Adding PIR to TTL camera tutorial

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
n8thegr8
 
Posts: 1
Joined: Wed Feb 05, 2014 11:08 pm

Adding PIR to TTL camera tutorial

Post by n8thegr8 »

Hi, working with my son making a motion capture camera.
We have got the TTL camera working.

Now we are trying to integrate it with a PIR sensor.

The code is below: I would think that we would turn the cam motion detect to off
and then adding the PIR sensor.

Any suggestions?

Thanks

Code: Select all

  //  Motion detection system can alert you when the camera 'sees' motion!
  cam.setMotionDetect(true);           // turn it on
  //cam.setMotionDetect(false);        // turn it off   (default)

  // You can also verify whether motion detection is active!
  Serial.print("Motion detection is ");
  if (cam.getMotionDetect()) 
    Serial.println("ON");
  else 
    Serial.println("OFF");
}




void loop() {
 if (cam.motionDetected()) {
   Serial.println("Motion!");   
   cam.setMotionDetect(false);
   
  if (! cam.takePicture()) 
    Serial.println("Failed to snap!");
  else 
    Serial.println("Picture taken!");
  
  char filename[13];
  strcpy(filename, "IMAGE00.JPG");
  for (int i = 0; i < 100; i++) {
    filename[5] = '0' + i/10;
    filename[6] = '0' + i%10;
    // create if does not exist, do not open existing, write, sync after write
    if (! SD.exists(filename)) {
      break;
    }
  }
  
  File imgFile = SD.open(filename, FILE_WRITE);
  
  uint16_t jpglen = cam.frameLength();
  Serial.print(jpglen, DEC);
  Serial.println(" byte image");
 
  Serial.print("Writing image to "); Serial.print(filename);
  
  while (jpglen > 0) {
    // read 32 bytes at a time;
    uint8_t *buffer;
    uint8_t bytesToRead = min(32, jpglen); // change 32 to 64 for a speedup but may not work with all setups!
    buffer = cam.readPicture(bytesToRead);
    imgFile.write(buffer, bytesToRead);

    //Serial.print("Read ");  Serial.print(bytesToRead, DEC); Serial.println(" bytes");

    jpglen -= bytesToRead;
  }
  imgFile.close();
  Serial.println("...Done!");
  cam.resumeVideo();
  cam.setMotionDetect(true);
 }
Last edited by adafruit_support_bill on Mon Mar 03, 2014 6:45 am, edited 1 time in total.
Reason: Please use the 'code' button when submitting code - click 'code' and paste your code between the tags.

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Adding PIR to TTL camera tutorial

Post by adafruit_support_bill »

Yes, you can remove all the motion detect code from that sketch. Adding a PIR is pretty simple. The output is a digital signal so it can be connected directly to an Arduino pin. This page has some example code: http://learn.adafruit.com/pir-passive-i ... sing-a-pir

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”