Instructables

Remote Canon DSLR Video Trigger

Step 4: Arduino Code

Here is the Arduino code to make the whole thing run.  

Credit for the IR remote control code goes to Martin Koch  http://controlyourcamera.blogspot.com/  with his thanks  to http://www.doc-diy.net/photo/rc-1_hacked/index.php for figuring out the IR code.

The code is well commented, but the general idea is this:

- The SWITCH pin is set to open input state of HIGH, this is the pin the RF trigger is attached to.  
- The state of the Power LED is set to HIGH, and the loop watches for a change from not running to running. If this occurs, the LED blinks (while video is being shot), and vice-versa, once recording stops, the LED returns to solid.
- The Arduino looks for the SWITCH pin to be pulled LOW, indicating the trigger has been pressed.
- Once this occurs, it fires the Start/stop video sequence to the IR LED.
- The video state of running is set or unset.
- The Piezo buzzer beeps (once for start, twice for stop)

Simple as that.

The LED blink code was written from a sample of code I found that allows the LED to blink without using the delay(); function so that no button presses are missed during a delay in the loop.   A small delay is written into the piezo buzzer function because this fires immediately after the recording stops or starts, and doesn't run continuously.

I don't have an AVR programmer, so I used my Arduino to write the code to the atmega328 chip I had simply by pulling the stock chip off my Arduino, inserting the chip I was using for this project, writing the code to it, and swapping it out again.  
 
Here is the code (also attached in a .TXT file, rename to .pde) :

/*
Based on Arduino sketch for simulating a Canon RC-1 IR remote control to start and stop video recording on a Canon 5D Mark II or 7D
 2010, Martin Koch
 http://controlyourcamera.blogspot.com/
 Huge thanks go to http://www.doc-diy.net/photo/rc-1_hacked/index.php for figuring out the IR code.

 Modified by JustinHerx for accepting input from a remote (wired/wireless) and turning the
 output into an IR command to activate/deactivate video recording on a Canon 5D MII, 7D, 60D, etc.
 Parts required:
 - Arduino
 - Power LED (or switch with power LED, I am using an illuminated pushbutton switch from RadioShack # 275-0009)
 - Piezo buzzer (RadioShack #273-059)
 - 2.5mm jack to attach camera trigger
 - IR LED to trigger camera
 - Resistor for LED
 */

const int irLED = 11;
const int SWITCH = 7;
const int buzzPin = 8;
const int powerLED = 4;
boolean running = false;
int ledState = HIGH; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
long interval = 200; // interval at which to blink (milliseconds)

unsigned int pulseDuration = 10; //microseconds
//The required 15 microseconds pulseDuration didn't work since digitalWrite consumes some additional time
//thats adds to pulseDuration value. 10 to 12 microseconds worked for me.

unsigned int photo = 7330; //A 7330 microseconds delay between bursts shoots a photo.
unsigned int video = 5360; //A 5360 microseconds delay between bursts starts/stops video recording.

void setup() {
//Serial.begin(9600); // uncomment for debugging
pinMode(irLED, OUTPUT);
pinMode(SWITCH, INPUT);
pinMode(buzzPin, OUTPUT);
pinMode(powerLED, OUTPUT);
digitalWrite(SWITCH, HIGH); //turn on internal 20 k pullup resistor so the open input state is HIGH.
digitalWrite(buzzPin, LOW);
digitalWrite(powerLED, HIGH);

}

void loop() { //run again and again

if (running == true) // This part of the loop is to test if the camera has been triggered to record
// and blinks the power LED while recording.
{

//Serial.print("running"); //uncomment for debugging
//Serial.println();

unsigned long currentMillis = millis();

if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;

// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
{
ledState = HIGH;
}
else
{
ledState = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(powerLED, ledState);
}
}

if (digitalRead(SWITCH) == LOW) { //read switch input
shoot(video); //start or stop video recording
if (running == false) //detect the state of recording and invert it
{
running = true;
}
else
{
running = !running;
digitalWrite(powerLED, HIGH);
}
piezoBeep(); //beep the buzzer to indicate that recording has started or stopped
delay(500);
}
}

void shoot(unsigned int delayBetweenBursts) { //sends the IR signal

//send first 16 bursts
for(int i=0; i<16; i++) {
digitalWrite(irLED, HIGH);
delayMicroseconds(pulseDuration);
digitalWrite(irLED, LOW);
delayMicroseconds(pulseDuration);
}

delayMicroseconds(delayBetweenBursts);

//send second 16 bursts
for(int i=0; i<16; i++) {
digitalWrite(irLED, HIGH);
delayMicroseconds(pulseDuration);
digitalWrite(irLED, LOW);
delayMicroseconds(pulseDuration);
}
return;
}

void piezoBeep(){ //beeps the piezo buzzer, once for start of recording, twice for end of recording
if (running == true)
{
digitalWrite(buzzPin, HIGH);
delay(250);
digitalWrite(buzzPin, LOW);
}
else
{
digitalWrite(buzzPin, HIGH);
delay(250);
digitalWrite(buzzPin, LOW);
delay(100);
digitalWrite(buzzPin, HIGH);
delay(250);
digitalWrite(buzzPin, LOW);
}
}
 
 
Remove these adsRemove these ads by Signing Up
recwap6 months ago

Hi, nice work!

I made something similar using Arduino, I added IR and wire trigger onboard sound and light sensor:

http://www.instructables.com/id/APCC-Advanced-Photo-Camera-Control/

Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!