loading

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);
}
}
 
<p>Great! I've been looking for this for days. Now i finally found it and I hope I'm able to build this myselfe. I have zero coding skills and I want to use it with the T2i. Do I have to change the code somehow?</p>
<p>Here is one controlled with your smart phone's built in WiFi, with laser, light, motion, sound high speed trigger</p><p><a href="https://www.kickstarter.com/projects/969220052/camsformer-high-speed-triggeringwireless-camera-co" rel="nofollow">https://www.kickstarter.com/projects/969220052/cam...</a></p>
<p>Hi, nice work!</p><p>I made something similar using Arduino, I added IR and wire trigger onboard sound and light sensor: </p><p><a href="http://www.instructables.com/id/APCC-Advanced-Photo-Camera-Control/" rel="nofollow">http://www.instructables.com/id/APCC-Advanced-Photo-Camera-Control/</a></p>
Well Done! Thanks for the hard work. I'm going to make this my weekend project. I'm working on a linear motion device for my T2i and this will be a great way to trigger the video. I'll reply again and maybe post video.
I would love to see it, sounds like a cool project. If you want an even more simple video trigger, check out my other Instructable, it's way more simple, cheap and quick to build. (However, if you are looking to integrate the trigger into a larger Arduino driven motion control system, this is the better one). <br><br>http://www.instructables.com/id/Long-Range-Canon-DSLR-Video-Trigger-V2-greatly-s/
Hey, very clever dude!! I have an arduino, but it's the only thing im not great with when writing code. Is there any way I could have at least some sample of the code written for this? I would like to trigger shooting on my atv in a combo with my GoPro. The 7d is just way nicer video, and I can use the slightly less crisp GoPro video as a first person view simulator.<br><br><br>Basically, I just hope you can help me out. I have everything and then some to get this moving, I just get all flustered with lines and commands. thanks for any info, great writeup man.
I am not a programmer at all either. It just takes some careful reading thru and understanding it piece by piece. Make sure you have a basic understanding of how the program structure for the Arduino works, that will help a lot. There is a lot of great info on the Arduino site. All the code that makes my project work is posted in Step 4 of the Instructable. I tried to comment the code decently so you can tell what is going on. <br><br>Good luck! Sounds like an interesting project.
Ah jeez, I am a brand new user, I didn't even see the step links. I just readit the first one and though THAT was an awesome post. QUADRUPLE kudos to you! haha. I have The Arduino kit that comes with most of the standard parts, and Microcenter is right near me, they have a decent selection of the Arduino advanced components. If not I can just order parts from an onlin electronic component distributer. Thanks for the reply, and I will make a similar write up when I get it done. Thanks again!
can I use this to make a trigger to make photo's of water drups?
No, this is a video only hack. If you need to record video of waterdrops from 100ft away, this is your ticket. If you are just looking to capture photos of water drops, there are a number of Instructables about that on here. (like this one: <a href="http://www.instructables.com/id/Laser-Triggered-High-Speed-Photography/">http://www.instructables.com/id/Laser-Triggered-High-Speed-Photography/</a>)

About This Instructable

28,642 views

22 favorites

License:

More by herx: Long-Range Canon DSLR Video Trigger (V2, greatly simplified) Remote Canon DSLR Video Trigger
Add instructable to: