Showing posts with label arduino. Show all posts
Showing posts with label arduino. Show all posts

Saturday, January 4, 2014

Arduino Time-Lapse Dolly Project Part 2

Arduino Time-Lapse Dolly Project Part 2

Buttons make it go!


For those who have not had much experience with the Arduino, basically what happens is once the board if plugged into a power source the program starts to run - so in this case the relay will start clicking away until you unplug it or upload another program.  So its kind of nice to update the program so that the relay, and therefore the camera will only fire once a button is pressed.

Now I add a button that will trigger the relay and therefore the camera.  The basic button wiring can be found on the Arduino site but I have one here as well:


So I ran a wire from the Arduino +5v pin to the bread board.  Hooked one side to the switch, on the other side of the switch is connected to a digital pin on the Arduino (Pin X), plus a 10K Ohm resistor connected in parallel to ground.

Here is my set up:

Button is the little back square on the white bread board.  The purple wires connect to the relay.  The red, yellow and black wires on the left side go to the camera.  

One thing to consider is that buttons aren't perfect and may "bounce" - meaning they don't make smooth contact and may chatter a bit.  I added a simple debounce code - very simple, maybe even laughably so - but I am a simple guy and I didn't understand the debounce code available online.

Here is my code:

const int buttonpin = 53;  //number of the pin the button is connected too
const int camerapin = 52; //number of the pin the relay to trigger the camera is connected too

int buttonstate = 0;

void setup() {

 pinMode(camerapin, OUTPUT);  //sets pin 52 to output mode
 pinMode(buttonpin, INPUT);  //sets pin 52 to input mode
}

void loop(){
  buttonstate = digitalRead(buttonpin);

  if (buttonstate == HIGH){
    digitalWrite(camerapin, HIGH);  // since I am not sure how much time the relay needs to be on for the camera to register it will keep the relay "on" for .1 seconds. 
    delay(100);
    digitalWrite(camerapin, LOW);
    delay(500); //to help prevent the button from triggering the relay multiple times by accident, this delay prevents the button from being pushed again for .5s
  }
  else{
    digitalWrite(camerapin, LOW);  //in hindsight, I probably don't need an "ELSE" statement
  }
}


Next: Stepper it up!

Saturday, November 23, 2013

Arduino Time-Lapse Dolly Project Part 1

Let me preface this article by saying I am NOT an expert in electronics, or programming or the Arduino... I am pretty confident that I can hack something together, and perhaps my readers can help me along the way if I get stuck.

First I will briefly describe what I have in mind.  I have been taking a lot of Milky Way time-lapse movies recently and to add a little pizzazz to them I would like to have the camera move on a track.  So I can either I can stay up all night and move the camera manually - which sounds like work.  Or I could automate it with some programmable computer thingy.  Option two sounds way better.  The thought is I would have the Arduino trigger the camera for the appropriate amount of time.  When the shutter closes, move the camera on the track a short distance.  Then trigger the camera again and repeat until the sun comes up.  For those who are not aware of what is required to shoot Milky Way time lapse, it takes 300 individual pictures to make 10 seconds of video at 30 frames per second.  For each photo, the shutter is open for 30 seconds.  I prefer to try and shoot all night, which may be 8 hours worth of shooting and equals about 800 shots.  This is why I would like to automate it!  I would rather sleep all night than baby sit the camera. See my first video below:



Now, I am not very electronic savvy - most of my background is in car electronics so I am all about the relays and switches.  To me a transistor is something Harry Potter probably used.  I heard of something called a stepper motor which I think I need to move the camera dolly. After some research I know Arduinos have these shield things to control motors.

Step 1, buy and Arduino.  Check!  Actually I got the Mega because the shield I bought said it worked for the Mega but didn't explicitly say it worked for the Uno so I thought I would just get the Mega for now.

Step 2, buy a stepper motor shield. Check!  I got the SainSmart one off of Amazon.  Hopefully it does everything I need because I don't really know much about stepper motors and such.



The Arduino site suggests installing the "Blink" program.  Well when I plugged it in for the first time the LED was already blinking so that really doesn't help.  So what I did instead was take the standard blink program and change the blink interval.  Uploaded that and it worked great.

Here is the code I used:

int led = 13;

// the setup routine runs once when you press reset:
void setup() {              
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);  
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(250);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(300);
digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(250);
 digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000); // wait for a second
}


I bought a cheap shutter release cable and opened it up to see how it triggered the camera and figure out how to wire it into the Arduino.  I cut the wires to the board (see photo below) and tried connecting different ones together to figure out what combination fired the camera.  What worked was connecting all three together.  If I connected the red and white together nothing happened, but if I connected the white and black it was like a half shutter press, and connecting the red and black did nothing.

See the cut wires in the black connector on the main board. 

With my simplified electronics background the firth thing I thought of was a relay.  Tie the red and white wires together, and use the Arduino to actuate a relay to connect the red and white wires to the black wire. So I wired one up like this:


Hooked up on a bread board it looks like this:


Now one special note - the Arduino can only support 40mA through each pin so you have to pick relay that doesn't draw more than that.  The first relay I got drew 90mA and though it worked, I think it will fry the Arduino over time. How do you figure it out?  Take the voltage, divide it by the resistance.   If its less than .04 then you are OK.  Since the Arduino puts out 5 volts, you take 5 and divide it by the resistance of the coil in the relay (expressed in Ohms).  You need a relay that can be triggered by 5v and has a coil resitance of 125 ohms or more.

As for the code I took the Blink code and changed the pin to 10 and wired the relay up as shown above.  Plugged the Arduino into the computer and listened for the click.  Then I plugged the wires from the shutter release to the camera and did the same thing this time the camere should fire at a regular interval.

Sure enough, it did!  Great success!

Stay tuned for more updates!