This week we are going to build a time lapse camera controller with an Arduino, but before we get into the weeks project, we have a couple of viewer emails we are going to review. Garage Door control must be the hot topic recently because all of the viewer emails this week are around garage door controls.
Downloads
Link to the solid state relay we used: http://www.omron.com/ecb/products/pdf/G3VM_352CF.pdf
Sample Code
/*############### Time-Lapse / Camera Controller #########################
This code will create a time lapse camera controller using an
Arduino. The controls are pretty basic, there are 4 buttons,
1 is the on/off, 2 will increase the time in 1 second intervals,
3 will decrease the time in 1 second intervals and 4 will take
a picture immediately.
There are also 3 leds, the first is on solid if the mode is on.
If it is on and within 1 second of the next picture it will flash.
The 2nd led is the focus LED and the 3rd is the shutter LED.
For this example, the timer is set to 10 seconds be default. You will
want to change that to be closer your real value.
Each camera manufacturer can have different specifications on how to
connect the camera for a remote shutter. Most use either a 1/8 or 1/16
TRS (mini stereo) plug.
The schematic is available in the show notes at http://tech-zen.tv or
http://letsmakeit.tv
You can also purchase the shield kit or parts bundle that we used in
the video at the http://tech-zen.tv store. The shield is available
as a kit.
From: Mike Myers (http://mikemyers.me) @netnutmike
Let's Make It Episode 33 (http://letsmakeit.tv or http://tech-zen.tv)
http://tech-zen.tv
For the sample code, show notes, contact information and many more
videos, visit the show page at http://tech-zen.tv/letsmakeit
Please subscribe to our YouTube channel or our netcasts at any of
your favorite netcast / podcast outlets.
We normally record Let's Make It live on Tuesday evenings around
7pm eastern. You can watch it live by going to tech-zen.tv and clicking
the live link at the top of the page.
We also have a community setup for our viewers and listeners. You can
join the community by going to community.tech-zen.tv.
We love input on what you would like to know or if you have an idea for
a new Let's Make it episode, you can contact us via email or phone at
the show information page.
################################################################################*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// The LED Pins
int led1 = 4;
int led2 = 7;
int led3 = 3;
// The Button Pins
int button1 = 8;
int button2 = 9;
int button3 = 10;
int button4 = 11;
// The other pins
int focusPin = 5;
int takePin = 6;
int photoSensor = 0; //This is analog 0
int timerInterval = 10; //This is the default interval, you may want to make it higher
int currentTimer = 2000; //This is the default current timer, it needs to be > 1000
bool alternator = true; //Default for the blinking light at <= 1000 ms
int blinker = 0; //Timer Used for the blinking
int mode = 0; //Default Mode is off
//The Modes
int modeStop = 0;
int modeRun = 1;
LiquidCrystal_I2C lcd(0x3F,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
//Setup the pins for the correct mode
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
//Note that we are using INPUT_PULLUP which means button pressed = !digitalRead.
//This saves us having to use pullup resistors in our design.
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
pinMode(button4, INPUT_PULLUP);
pinMode(focusPin, OUTPUT);
pinMode(takePin, OUTPUT);
lcd.init();
lcd.backlight(); // Light It Up
Serial.begin(9600); //Start serial for output
//This can be removed or commented out. It was put here for debugging the
//i2C display I was using. I kinda liked the blinky light so I left it in
startupSequence();
}
void loop()
{
//Read the photosensor
int gsr = analogRead(photoSensor);
//If in run mode, decrement the timer counter by 1
if (mode == modeRun)
--currentTimer;
//If the current timer is less than or equal to the 1 second then do the blinking light
if (currentTimer <= 1000)
{
//The blinker variable is used as a timer, this gets passed by about once a millisecond
//which is too fast for the human eye to see. The counter blinks the led about 10 times
//a second
++blinker;
if (blinker > 100)
{
alternator = !alternator; //Do the oposite of the current LED state
blinker = 0;
Serial.println("SMILE");
}
digitalWrite(led1, alternator);
} else {
if (mode == modeRun)
digitalWrite(led1, true); //Mode is run so turn on the LED
else
digitalWrite(led1, false); //Mode is not run so turn off the LED
}
//It is go time, set the new timer and take the photo, update the display
if (currentTimer <= 0)
{
currentTimer = timerInterval * 1000;
takePhoto();
showMode();
showTimer();
}
//Button one was pressed to toggle the mode to either on or off
if (!digitalRead(button1))
{
toggleMode();
delay(250); //bounce protection
currentTimer = timerInterval * 1000; //Reset the timer
}
//Button 2 was pressed, add one second to the interval timer
if (!digitalRead(button2))
{
increaseTime();
delay(250); //bounce protection
currentTimer = timerInterval * 1000; //Reset the timer
}
//Button 3 was pressed, subtract one second from the interval timer
if (!digitalRead(button3))
{
decreaseTime();
delay(250); //bounce protection
currentTimer = timerInterval * 1000; //Reset the timer
}
//Button 4 was pressed, hope you had time to smile before the picture was taken
if (!digitalRead(button4))
takePhoto();
delay(1); // Delay 1 MS. 1000 loops around should equal close to 1 second.
}
//====================================================
//
// Function: toggleMode
//
// Description:
// This function just toggles the mode to either on
// or off then updates the LCD
//
//====================================================
void toggleMode()
{
if (mode == 0)
mode = 1;
else
mode = 0;
showMode();
}
//====================================================
//
// Function: showMode
//
// Description:
// This function outputs to the LCD and the Serial
// port the current mode.
//
//====================================================
void showMode()
{
Serial.print("Mode Set To: ");
lcd.setCursor(0,0); // Clear out the current mode text
if (mode == 0)
{
Serial.println("Off");
lcd.print("Mode: Off ");
} else {
Serial.println("On");
lcd.print("Mode: On ");
}
}
//====================================================
//
// Function: increaseTime
//
// Description:
// This function increases the timer interval by
// one second then updates the LCD
//
//====================================================
void increaseTime()
{
++timerInterval;
showTimer();
}
//====================================================
//
// Function: decreaseTime
//
// Description:
// This function decreases the timer interval by
// one second then updates the LCD
//
//====================================================
void decreaseTime()
{
if (timerInterval > 1)
--timerInterval;
showTimer();
}
//====================================================
//
// Function: showTimer
//
// Description:
// This function outputs to the LCD and the Serial
// port the current timer interval.
//
//====================================================
void showTimer()
{
Serial.print("Timer set to: ");
Serial.print(timerInterval);
Serial.println("s");
lcd.setCursor(0,1); // Clear out the current mode text
lcd.print("Timer: ");
lcd.print(timerInterval);
lcd.print("s ");
}
//====================================================
//
// Function: takePhoto
//
// Description:
// This function performs the function of taking
// the picture. It first outputs to the serial
// port, turns on the focus led, then the focus
// pin to the camera, waits 1/10 of a second
// then turns on the 3rd led and take pin to take
// the picture then waits 1/2 second and then
// turns off the pins.
//
//====================================================
void takePhoto()
{
Serial.println("Cha-pow!");
digitalWrite(led2, true);
digitalWrite(focusPin, true);
delay(100);
digitalWrite(led3, true);
digitalWrite(takePin, true);
delay(500);
digitalWrite(takePin, false);
digitalWrite(led3, false);
digitalWrite(focusPin, false);
digitalWrite(led2, false);
}
//====================================================
//
// Function: startupSequence
//
// Description:
// This function was created just so I knew that
// the code had reached the end of the setup
// because I was having lockups with the i2C
// LCD display I was testing with.
//
//====================================================
void startupSequence()
{
int sDelay = 200;
Serial.println("Hello");
for(int l=0; l<5; ++l)
{
digitalWrite(led1, true);
digitalWrite(led2, false);
delay(sDelay);
digitalWrite(led2, true);
digitalWrite(led1, false);
delay(sDelay);
digitalWrite(led3, true);
digitalWrite(led2, false);
delay(sDelay);
digitalWrite(led2, true);
digitalWrite(led3, false);
delay(sDelay);
}
for(int l=0; l<5; ++l)
{
digitalWrite(led1, true);
digitalWrite(led2, true);
digitalWrite(led3, true);
delay(sDelay);
digitalWrite(led1, false);
digitalWrite(led2, false);
digitalWrite(led3, false);
delay(sDelay);
}
digitalWrite(led1, false);
digitalWrite(led2, false);
digitalWrite(led3, false);
}