Skip to content

Instantly share code, notes, and snippets.

@shadowdoc
Created February 3, 2013 15:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shadowdoc/4702206 to your computer and use it in GitHub Desktop.
Save shadowdoc/4702206 to your computer and use it in GitHub Desktop.
A quick arduino sketch to control a Nikon DSLR via IR LED. Used for a party photobooth.
/*
Nikon IR Photobooth Kit
Marc Kohli
marckohli@gmail.com
11/11/2012
Changelog:
12/2/12 - Added Debounce code from http://arduino.cc/en/Tutorial/Debounce
Props to David A. Mellis and Limor Fried
Description:
Couples a simple push-button with the IR timer.
Delays 7.5 seconds after the button is pushed and then takes 5 pictures with
1s intervals between.
Adapted from the fabulous work of luckylarry and bigmike:
LUCKYLARRY.CO.UK - IR Remote control for Nikon using Arduino
Mimics the infrared signal to trigger the remote for any Nikon camera
which can use the ML-L1 and ML-L3 remotes. Can be used as an intervalometer
for time lapse photography.
The IR sequence I used is originally taken from: http://www.bigmike.it/ircontrol/
You should be able to use my pulse methods to alter to suit other cameras/ hardware.
micros() is an Arduino function that calls the time in Microseconds since your program
first ran. Arduino doesn't reliably work with microseconds so we work our timings by
taking the current reading and then adding our delay on to the end of it rather than rely
on the in built timer.
*/
// Camera Firing Interval Time
#define INTERVAL_TIME 1000
// Delay before taking pictures (in ms)
#define DELAY_TIME 7500
int pinIRLED = 12; // assign the Infrared emitter/ diode to pin 12
int pinBUTTON = 7; // assign the switch to watch to pin 9
int pinSTATUSLED = 9; // this is the pin that will flash an LED when the timer has been triggered.
byte val = 0; // variable for the button value
boolean buttonstate = false; // default the status LED to off
boolean debug = false;
// variables for debouncing
boolean lastButtonState = false;
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if output flickers
void setup() {
pinMode(pinIRLED, OUTPUT); // set the pin as an output
pinMode(pinSTATUSLED, OUTPUT);
pinMode(pinBUTTON, INPUT);
digitalWrite(pinSTATUSLED, buttonstate);
if (debug == true) {
Serial.begin(9600);
}
}
void loop() {
boolean reading = digitalRead(pinBUTTON);
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// This means we have a real state change.
// a.k.a. the switch has been in the same state longer than the
// debounceDelay value
val = reading;
}
if (val == LOW) {
if (debug == true) {
Serial.println(val);
}
for(byte i = 0; i < DELAY_TIME / 100; i++) { // This loop is the inital delay timer. One second per iteration
delay(100); // This is the front-end delay
buttonstate = ! buttonstate;
digitalWrite(pinSTATUSLED, buttonstate); // Flip the status LED
}
buttonstate = false;
digitalWrite(pinSTATUSLED, buttonstate);
takeFive();
}
}
void takeFive() {
for(byte i = 0; i < 5; i++) {
takePicture(); // take the picture
delay(INTERVAL_TIME); // delay in milliseconds which allows us to do timelapse photography - 1 second = 1000 milliseconds
if (debug == true) {
Serial.println("snap");
}
}
}
// 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(400); // and so on
pulseOFF(1580);
pulseON(400);
pulseOFF(3580);
pulseON(400);
pulseOFF(63200);
} // loop the signal twice.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment