Arduino Time Lapse Camera

Here's the code for making a time lapse shutter release for a Nikon DSLR. I have always wanted a high-definition time lapse camera, but this is the next best thing. Basically it just triggers the shutter release a number of times per second. I got the time values from here.

Change the #defines for your needs. Enjoy.

/* Time Lapse code by Morgan Jones. Feel free to use, modify, and redistribute to your will. */

/* Begin user defines */

/*
 The scale of your time lapse. 0 for frames/sec, 1 for frames/minute, 2 for frames/hour,
 3 for frames/day, or 4 for frames/week.
*/
#define SCALE 0

// The frame rate of your time lapse (see above).
#define RATE 2

// Your IR LED pin.
#define LED_PIN 12

// The built-in LED on your Arduino.
#define LED_ARDUINO 13

// Your camera model. 0 for D40, D40x, D60, D80 or D90. 1 for D80, D70, D70s, D50, or N65.
// For the D80, choose 0 (it's just newer).
#define MODEL 0

/* End user defines */

/* Begin preprocessor defines */

#if SCALE == 0
#define WAIT_MILLIS 1000
#elif SCALE == 1
#define WAIT_MILLIS 60000
#elif SCALE == 2
#define WAIT_MILLIS 3600000
#elif SCALE == 3
#define WAIT_MILLIS 86400000
#elif SCALE == 4
#define WAIT_MILLIS 604800000
#endif

/* End preprocessor defines */

/* Begin program variables */

#if MODEL == 0
static unsigned int code[] = { 2250, 27600, 650, 1375, 575, 3350, 650 };
#elif MODEL == 1
static unsigned int code[] = { 2000, 27800, 500, 1500, 500, 3500, 500 };
#endif

#define CODE_SIZE sizeof( code ) / sizeof( unsigned int )

// The LED's state
static boolean state;

// Start of the second
unsigned long then;

/* End program variables */

/* Begin program code */

void setup()
{
  // Start output on the LED pin and internal LED
  pinMode( LED_PIN, OUTPUT );
  pinMode( LED_ARDUINO, OUTPUT );
}

void loop()
{ 
  // Start this second
  then = millis();
  
  // Send the code 2 times
  for( int a = 0; a < 2; a++ )
  {
    // Set the initial state to HIGH
    state = HIGH;
    // Send the entire code
    for( int b = 0; b < CODE_SIZE; b++ )
    {
      // Turn the LED on or off
      digitalWrite( LED_PIN, state );
      // Wait a little bit
      delayMicroseconds( code[b] );
      // Invert the state. IR codes are a square wave, so we need an on-off cycle.
      state = !state;
    }
    
    // Turn the LED off for 63 milliseconds
    digitalWrite( LED_PIN, LOW );
    delay( 63 );
  }
  
  // Turn on the Arduino LED while we wait
  digitalWrite( LED_ARDUINO, HIGH );
  // Do nothing until we can finish this second/minute/hour/day/week
  delay( ( WAIT_MILLIS / RATE ) - ( millis() - then ) );
  // Turn off the Arduino LED. We're done waiting.
  digitalWrite( LED_ARDUINO, LOW );
}

/* End program code */

I haven't tested it out, but it should work provided you have an IR LED and a resistor (so you don't blow your LED; I just blew one tonight; don't do it) and your Arduino is in close proximity to your camera.

Update: Someone has already made this. Oh well.

Hi Morgan,

you did not Google enough. There are lots of timelapse and lots of IR control code samples out. You can even find dedicated hardware plans and schematics for super cool timelapse solutions.

Cheers, Udo

Well, I stand corrected.