Arduino – motion triggered camera

So having worked out that I can make a remote for my Nikon D80 to do some timelapse photography. I started thinking of things I can do to trigger the...

So having worked out that I can make a remote for my Nikon D80 to do some timelapse photography. I started thinking of things I can do to trigger the remote, below video shows it working but you’ll need sound to hear the shutter going.

First of all check out my tutorial for making the remote as this builds on that tutorial – also saves me having to recap and explain that. Arduino Nikon intervalometer infrared remote for timelapse photography.

Ok so now you know how I’m going to trigger the camera to take pictures. So now we need the sensor, for this I’m going to use a PIR (Pyroelectric InfraRed sensor) IC that works like a switch turning on when motion is detected, the one I’m using is basically a couple of IR emitters and sensors under a Fresnel lens – word of warning make sure you get the power supply right as they tend to smoke otherwise!. It works by measuring any difference to the background temperature and infrared radiation. I’ve also added an LED to signal when the PIR is on or off.

The biggest challenge for this was making sure the camera didn’t keep triggering for the length of time the PIR was active – sometimes it would be active for 5 or seconds after initial movement, so I wanted to capture say 2 photos for each time it was triggered.

For lazyness I’ve left my camera in auto setting so that it *should* autofocus along with everything else – e.g. exposure times and apertures.

Arduino Motion Tracker Parts

220 Ohm resistor (Red, Red, Brown, Gold)
10K Ohm resistor (Brown, Black, Orange, Gold)
PIR sensor
Infrared emitting diode
LED
Arduino Deumilanove w/ ATMEGA328
Breadboard / Prototyping board
Jumper/ Connector wires
Optional 9V power supply (here) or use the USB power for the Arduino
You will also need a soldering iron and solder if you use the same PIR as myself.

The Arduino Motion Detector Circuit

You may not be able to see but I’ve used the power supply from the Arduino to power the breadboard. The PIR gets its supply from this and there’s a 10k Ohm resistor between its output pin and pin 4 on the Arduino. The LED has a 220 Ohm resistor between that and the digital pin 9. The IR LED I’ve left in pin 13 and grounded – for a better system I would solder on a couple of wires to allow more flexibility with transmitting the signal. Also for the PIR, the one I have I had to solder a few jumper wires into the back of it just so you know.

arduino-camera-motion-trigger

Arduino Motion Sketch / Code

Based off of my remote tutorial I’ve just added in a few extra things really. An output for the LED, an input for the PIR and a chunk of code to limit the taking of photos.

/*

LUCKYLARRY.CO.UK - IR Remote control for Nikon using Arduino with motion trigger

Uses a PIR sensor to trigger the camera remote/ IR led if a change in background
temperature is detected.

*/

int currentState = 0;                                   // set a variable to store a count.
int pinPIR = 4;                                         // digital pin 4 for PIR
int pinLED = 9;                                         // digital pin 9 for LED
int pinIRLED = 13;                                      // assign the Infrared emitter/ diode to pin 13

void setup() {
  pinMode(pinIRLED, OUTPUT);                            // set the pin as an output
  pinMode(pinLED, OUTPUT);                              // set the LED pin as ouput
  pinMode(pinPIR, INPUT);                               // set the PIR pin as an input
}

// sets the pulse of the IR signal.
void pulseON(int pulseTime) {
  unsigned long endPulse = micros() + pulseTime;        // create the microseconds to pulse for
  while( micros() < endPulse) {
    digitalWrite(pinIRLED, HIGH);                       // turn IR on
    delayMicroseconds(13);                              // half the clock cycle for 38Khz (26.32×10-6s) - e.g. the 'on' part of our wave
    digitalWrite(pinIRLED, LOW);                        // turn IR off
    delayMicroseconds(13);                              // delay for the other half of the cycle to generate wave/ oscillation
  }

}

void pulseOFF(unsigned long startDelay) {
  unsigned long endDelay = micros() + startDelay;       // create the microseconds to delay for
  while(micros() < endDelay);
}

void takePicture() {
  for (int i=0; i < 2; i++) {
    pulseON(2000);                                      // pulse for 2000 uS (Microseconds)
    pulseOFF(27850);                                    // turn pulse off for 27850 us
    pulseON(390);                                       // and so on
    pulseOFF(1580);
    pulseON(410);
    pulseOFF(3580);
    pulseON(400);
    pulseOFF(63200);
  }                                                     // loop the signal twice.
}

void loop() {

  if ((digitalRead(pinPIR) == LOW) && (currentState <= 2)) { // count to limit the taking of photos
    takePicture();                                      // take the picture
    digitalWrite(pinLED, HIGH);                         // turn LED on
  } else {
    digitalWrite(pinLED, LOW);
    currentState = 0;                                   //reset the count when the PIR is off.
  }

  currentState++;
  delay(2000);                                          // delay for 2 seconds - 2 seconds between taking photos if the PIR is active for more than 2 seconds.
}

I think adding in another PIR would help me make some kind of turret system. Also you could use the ultrasonic range finder jobby, the SRF-05, to detect the distance and if less than say 3 metres take the photo etc.. I'm also going to try and setup a trip-wire system to trigger the camera :)

This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.

Technorati Tags: , , , , , , , , ,

  1. Arduino – IR remote/ intervalometer for Nikon D80 DSLR (that means timelapse photography yarrr!)
  2. Arduino – (Very) Basic motion tracking with 2 PIR sensors
  3. Arduino – Redefining the TV Remote
  4. Arduino – Using a Sharp IR Sensor for Distance Calculation
  5. Arduino + Processing: Make a Radar Screen to Visualise Sensor Data from SRF-05 – Part 2: Visualising the Data
  6. Arduino + Processing – Make a Radar Screen to Visualise Sensor Data from SRF-05 – Part 1: Setting up the Circuit and Outputting Values
  7. Arduino – Basic Persistance of Vision
  8. Obstacle avoidance Arduino robot – build your own larryBot
  9. Arduino & Processing – Getting values from SRF05 ultrasound sensor & serial port
  10. Arduino – Sonic range finder with SRF05