Nikon D40 Intervalometer Project

So, I’ve been wondering how to get my camera (Nikon D40) to do time-lapse photography. I am going on a camping trip here in about 2 weeks and would love to be able to take some time-lapse shots of the night-time sky whilst we sit around the campfire.

A problem arises. The Nikon D40 does not have an intervalometer (nor does it support auto-bracketing, but that’s another post). This means no time-lapse photography with this camera.

Or does it?

A couple of generalized web searches brought me to some informative sites:
http://www.cibomahto.com/2008/10/october-thing-a-day-day-7-nikon-camera-intervalometer-part-1/
http://ilpleut.be/doku.php/code:nikonremote:start
http://www.bemasher.net/archives/114

I was in luck! I happen to have an Arduino board lying around doing nothing. Happy times!

I set off to the only place in town with electronic components, Radio Shack (I know). IR LED in hand, I proceeded to assemble my very simple circuits. I built a second circuit to blink a second LED for 2 seconds before the IR LED sequence is fired off for the camera. I chose to use the code from the bemasher link.

The Arduino microcontroller board that I have has a 220 ohm resister built into digital pin 13 that I was not aware of. My IR LED was understandably dim as a consequence of my adding a second 220 ohm resister to the circuit. The camera wasn’t taking pictures when it should have been. With that problem solved, I edited the code to include a timer that I can set easily to whatever number of seconds I need. I set it to 10 seconds and tested the camera out again.

Success!

I built a small enclosure for everything, soldered a few wires together, and tested again to make sure I had put it all back together correctly. It works from about 10-12 feet away, but I shouldn’t need it for anything that far away. The idea is to just place the IR LED directly on the IR receiver and let it take a picture every 60 seconds for hours at a time. Simple.

Code I am using:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
Author:         BeMasher
Description:    Code sample in C for firing the IR sequence that mimics the
ML-L1 or ML-L3 IR remote control for most Nikon SLR's.

Based off of:   http://make.refractal.org/?p=3
http://www.cibomahto.com/2008/10/october-thing-a-day-day-7-nikon-camera-intervalometer-part-1/
http://ilpleut.be/doku.php/code:nikonremote:start
http://www.bigmike.it/ircontrol/

Notes:          This differs slightly from the other 3 versions I found in that this doesn't use the built in
delay functions that the Arduino comes with. I discovered that they weren't accurate enough for
the values I was trying to give them. The delayMicrosecond() function is only accurate between about
4uS and 16383uS which isn't a very workable range for the values we need to delay in for this project.
The ASM code that Matt wrote works well but is limited to only pin 12 and I haven't got a good enough
grasp of the architecture to modify the code to work on any pin. So this is what I've come up with to
produce the same result.
*/


#define IND_LED 10       //Pin the Indicator LED is on
#define IR_LED 13        //Pin the IR LED is on
#define DELAY 13         //Half of the clock cycle of a 38.4Khz signal
#define DELAY_OFFSET 4   //The amount of time the micros() function takes to return a value
#define SEQ_LEN 4        //The number of long's in the sequence

unsigned long seq_on[] = {2000, 390, 410, 400};        //Period in uS the LED should oscillate
unsigned long seq_off[] = {27830, 1580, 3580, 0};      //Period in uS that should be delayed between pulses
int interval=0;
int time=0;

void setup() {
Serial.begin(19200);        //Initialize Serial at 19200 baud
pinMode(IR_LED, OUTPUT);    //Set the IR_LED pin to output
pinMode(IND_LED, OUTPUT);   //Set the IR_LED pin to output
}

void customDelay(unsigned long time) {
unsigned long end_time = micros() + time;    //Calculate when the function should return to it's caller
while(micros() < end_time);                  //Do nothing 'till we get to the end time
}

void oscillationWrite(int pin, int time) {
unsigned long end_time = micros() + time;    //Calculate when function should return to it's caller
while(micros() < end_time) {                 //Until we get to the end time oscillate the LED at 38.4Khz
digitalWrite(pin, HIGH);
customDelay(DELAY);
digitalWrite(pin, LOW);
customDelay(DELAY - DELAY_OFFSET);        //Assume micros() takes about 4uS to return a value
}
}

void triggerCamera() {
for(int i = 0; i < SEQ_LEN; i++) {            //For each long in the sequence
oscillationWrite(IR_LED, seq_on[i]);      //Oscillate for the current long's value in uS
customDelay(seq_off[i]);                  //Delay for the current long's value in uS
}
customDelay(63200);                            //Wait about 63mS before repeating the sequence
for(int i = 0; i < SEQ_LEN; i++) {
oscillationWrite(IR_LED, seq_on[i]);
customDelay(seq_off[i]);
}
}

/*
void loop() {
if(Serial.available()) {        //Wait 'till something is connected
if(Serial.read() != 0) {    //If anything but 0 is sent take a photo
triggerCamera();        //Take a photo
}
delay(100);                 //Delay an arbitrary amount of time, serial isn't instantaneous
}
}
*/


void loop() {
if(interval == 10) {
digitalWrite(IND_LED, HIGH);
delay(245);
digitalWrite(IND_LED, LOW);
delay(250);
digitalWrite(IND_LED, HIGH);
delay(250);
digitalWrite(IND_LED, LOW);
delay(250);
digitalWrite(IND_LED, HIGH);
delay(245);
digitalWrite(IND_LED, LOW);
delay(250);
digitalWrite(IND_LED, HIGH);
delay(250);
digitalWrite(IND_LED, LOW);
delay(250);
triggerCamera();
interval = 2;
}
delay(995);
interval += 1;

//Serial.print("Time: ");   //This is to get timing as close as possible
// time = (millis()/100);
//prints time since program started
// Serial.println(time);

}

This is probably boring to almost all of you, but I just thought I would share. :)

14 thoughts on “Nikon D40 Intervalometer Project

  1. BeMasher says:

    Glad to see others are finding my code useful!

    If you’re going to be posting a lot more code on your site you should take a look at a wordpress plugin called CodeColorer.

    http://wordpress.org/extend/plugins/codecolorer/

  2. Kris says:

    Hi,

    Curious to hear if you go this working. Any samples you can share?

  3. Whatafreak says:

    This seems to be the most popular post on my blog, so here is a quick update:
    I was able to get the intervalometer to work, but I am a total newb when it comes to cameras. I still don’t know how to get it to take long exposures and honestly, I haven’t taken a good look in a long while to figure out how. I didn’t think about trying to use it for daylight time-lapse shots until earlier today. If I can find some interesting subject matter I will give it a go and post up the results here.

    If your goal is to get a Nikon D40 to take pictures at regular intervals indefinitely, this method definitely works!

  4. Roy Tan says:

    hey, nice!! I also have a nikon d40 and soooo sad that it doesn’t have and couldn’t handle intervalometers on the market. Could you make one for me? I’m not a tech guy so I don’t know jacksh** about electronics.

    Roy

  5. teatoe says:

    did you buy an IR LED transmitter? do you set some frequency or anything? or just by turning on the IR LED on the camera would take a picture if it was set to remote mode?

    Thanks

  6. Whatafreak says:

    @ Roy
    In all seriousness, yes. I could make you one. The HUGE drawback of me making you one and you knowing nothing about it means that your shiny new intervalometer would be able to take photos only at the interval I had set in the code prior to shipping it out to you. My suggestion is to tackle this project yourself so that you can adjust the timings as you please and as individual projects dictate. Arduino boards can be purchased fully assembled so all you would have to do is assemble the IR LED circuit (very simple!) and transfer the code to the chip.

    @ teatoe
    Yes, for this project I picked up an IR LED transmitter from a local Radio Shack. The camera has to be in remote mode or it won’t respond to the LED at all. There is no frequency to set. In the code I posted above there is a specific sequence that is “flashed” from the LED and that the camera is looking for in order to trigger a photo capture.

  7. Josh says:

    Thanks for posting the code. I just got it up and running have found that taking a shot every 10 seconds doesn’t get the effect I am after. Could you please tell me which values need to be changed to have the shutter fire in different intervals? Thanks in advance :)

  8. Whatafreak says:

    @ Josh
    Sure! The relevant code is contained inside the “void loop()” function at the bottom of the code (line 75). In order to lengthen/shorten the time between shots, at the very next line (#76) you only need to change the value next to “interval ==”. It says “10″ in my code so it takes a photo every 10 seconds. It currently only works with whole numbers, but there shouldn’t be a problem even if you enter in a “10.1″ for some reason. It might take pictures every 11 seconds instead, though. Also, that value is in seconds.

    The code under the interval check (lines 77-92) is ugly but I wanted a way to make sure the sequence was working when I was testing it out without my camera nearby. So, I put together another very simple LED circuit and had it flash for 2 seconds before it fired the IR LED signal. If you guys want to remove that junk let me know and I can post the needed changes to the code for you to use.

  9. Josh says:

    Thanks heaps whatafreak! I was able to get the interval down to 3seconds but any lower and the function runs only once and then stops. I’ve tried changing the delay and the interval=+1 to other values with no success. Would it be possible to get intervals of one and two seconds or is that a limitation of using the Ardunio? I’m very new to the Arduino, I just bought it a few hours before posting my first comment and already really enjoying it. I found a high speed photography trigger I want to try using the Arduino and an SLR, have you tried this one?

    I posted a video on youtube of my first test. The sun was setting so I didn’t have long to film. I posted the relevant information in the description and gave you and beMasher a shout out :)

  10. Whatafreak says:

    Thanks, your video looks great! I edited your comment to embed the Youtube videos, hope you don’t mind…

    The way that I have written the code as posted above was for flashing a second LED to let me know a trigger was coming. This was when I was testing things without my camera nearby so I needed another way to verify success or failure.

    If you wanted to take the interval all the way down to a single second, here is how I would re-write the “void loop” function (i.e.- replace lines 75-104 above with the following):

    1
    2
    3
    4
    void loop() {
    delay(1000);
    triggerCamera();
    }

    Keep in mind that I have not yet tested these code changes.

    The delay function is measured in milliseconds, so 1000ms = 1s. You could continue to shorten the time all the way down to the minimum needed to run the “triggerCamera” function. I took a quick glance through the code again and if I am reading it correctly, the minimum amount of time between triggers is about 100ms.

    Edit:
    I haven’t tried any high speed photography, but that video was pretty informative and I am interested in trying this in the future. IMO the guy did a little showing off there at the end what with the automatic switching off and on of the lights, lol.

  11. teatoe says:

    hey,

    i’m planning to attempt this very soon. i’m a programmer but don’t know anything about circuits. i’m planing to pick up an Arudino broad, bread broad, some wires, 1 IR LED and 2 LEDS. is that all i need for the project?

    i’ve looked everyone online and your blog shows the best example of how to do this. greatly appreciated!

    thanks,

  12. teatoe says:

    hey,

    i got it work! thanks for the page once again. pretty cool!

    thanks

  13. Whatafreak says:

    @ teatoe

    Sorry for the late reply. In the most simple implementation, all you should need is the IR LED. I personally wanted a second LED to flash for my own validation of the circuit working, but it isn’t necessary for the setup to work.

    Once I got everything finalized, I soldered together a tiny PCB for the LED circuits and placed it into a small enclosure. I workable length of wire ends with the IR LED at its tip to trigger the camera. A breadboard just isn’t practical if you want to take the Arduino out and about without constantly having to “rebuild” the circuit if the wires fall out or get moved somehow.

    If everything goes to plan, I’d like to use it to make a time-lapse shot of my family setting up camp 2 weeks from now on our trip to the mountains for the weekend. I’ll post a video up here for anyone who cares to see the results.

    Additionally, I’m going to update this post shortly with pictures of my completed setup so you guys out there on teh tubez can get a better idea of how I implemented this particular design. Don’t get too excited, it’s not anything special, lol.

  14. John Maetta says:

    Nice project.

    Our big off-road riding season kicks off at Thanksgiving. We gather with family and friends as well as several thousand other off-road enthusiasts in the western Mojave.

    This has been a project on my list for some time. I have wanted to create a time-lapse movie of the entire weekend event. This requires the camera, a Nikon D40 DSLR, to snap photos every 6 minutes or so, over the course of 5+ days. It also means the camera needs to be hidden on a remote hilltop to encompass a large area.

    I have envisioned using my laptop and DIYPhotoBits, http://www.diyphotobits.com, but this requires the laptop to be connected to the camera and enough power to run both for 5+ days. Not to mention leaving my expensive Nikon and laptop unattended in the middle of the desert.

    Recently, I stumbled across an IR project that used an Arduino microcontroller to pulse an infrared LED to trigger a Nikon DSLR. This project simulates the Nikon ML-L3 Wireless remote control, but without human intervention.
    http://blog.tinyenormous.com/2009/09/30 … meter-code

    Not being familiar with the Arduino, but knowledgeable using PIC microcontrollers, I decided to adapt it to a PIC16F648A, with an enhancement.

    The Arduino project uses a potentiometer to set the time interval between shots. My PIC version uses 5 SPST (single pole/single throw) switches to set the time interval using a binary coded decimal scheme.
    Switches 1 through 4 allow the photographer to select any number between 1 and 15, while switch 5 selects either seconds or minutes. The minimal interval is 1 second and the maximum interval is 15 minutes.

    As an example, turning on switches 1 and 3 sets the interval to 5 seconds. The same switch settings and turning on switch 5, sets the interval to 5 minutes. This modification to the Arduino project simplifies and provides a faster, more accurate means of setting the interval.

    The entire project can be downloaded from:
    http://www.n6vmo.com/YitIRp/YitIRp.zip

    The .zip file includes the PIC software files, schematic, PCB, and list of materials.

    Here is a video I took at a shooting range cleanup event.
    http://www.youtube.com/watch?v=rp9HN3VWt_4

    N6VMO

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>