Feedback!

Time-Lapse Camera

Views: 15039 Difficulty: 4 Status: Complete
Screen_shot_2012-12-21_at_7.24.53_pm

This PCB controls a camera and an SD card so you can make automatic time lapse videos.

Mapping a cheap CMOS camera to an arduino and an SD card you can make your own time lapse videos automatically. This tutorial uses the TTL Serial JPEG Camera with NTSC Video from adafruit. Basically, we take a picture, wait a certain amount of time and then take another picture. Putting them all together as frames in a video makes a nice time-lapse movie. It takes about ten seconds to save each image on the SD card so the time lapses have to be at least ten seconds long, they can be longer too, as long as you want within the memory bounds of the Arduino and the SD card. Like cameras? Check out our panoramic camera tutorial, uses the same plexi glass case and a similar circuit board to take panoramic pictures.

Camera and Case

Screen_shot_2013-02-05_at_2.54.59_pm
The laser cut plexi glass enclosure. Cut on a lunar lazor monday at NYC resistor using their awesome laser cutter.

Example Video

Here is an example of the type of time lapse videos you can make using this camera. The above were made watching the sunset with 5 second intervals.

Arduino Code

Here is the code for the arduino. It uses a bunch of libraries namely the SD library to save the images, the SPI library to talk to the SD card, The VC0706 library from adafruit for the camera, and the SoftwareSerial library to talk to the camera. The crucial function is called time_lapse and it takes two arguments: the number of pictures to take and the amount of time to wait between each picture (on top of the five seconds or so it takes to save the images). So a call like:
  time_lapse(99, 5000);
will take 99 pictures waiting about ten seconds (5 seconds of delay + 5 seconds of saving) between each shot. The function definition looks like this:
void time_lapse(int num_pics, unsigned int wait){
  // Create an image with the name IMAGExx.JPG
  char filename[13];
  strcpy(filename, "lapse00.jpg");
  for (int i = 0; i < num_pics; i++) {
    filename[5] = '0' + i/10;
    filename[6] = '0' + i%10;
    take_picture(filename);
    delay(wait);
  }
}
Please note: if you want more than a hundred images this function needs to be tweaked so that the images are saved as lapseXXX.jpg rather than lapseXX.jpg.
/* LucidTronix Time Lapse Camera.
 * For instructions details and schematic, See:
 * http://www.lucidtronix.com/tutorials/14
 * Connect the camera RX to pin 10
 * and camera TX to pin 11
 */

#include <SoftwareSerial.h>
#include <VC0706.h>
#include <SD.h>
#include <SPI.h>


SoftwareSerial cameraconnection = SoftwareSerial(10, 11);
// pass the serial connection to the camera object
VC0706 cam = VC0706(&cameraconnection);
#define SD_CS 4    // Set the chip select line to whatever you use (4 doesnt conflict with the library)
int pin_pan = 6;
int pan = 0;

unsigned int cur_wait = 2000;
void setup() {
  delay(1400);
  while (!cam.begin()) {
    delay(10000);
  }
  pinMode(SD_CS, OUTPUT);
  digitalWrite(SD_CS, HIGH);
  while (!SD.begin(SD_CS)) {
    delay(10000);
  }
  cam.setImageSize(VC0706_320x240);     // medium
  time_lapse(99, 5000);
}
void loop(){

}

void take_picture(char * filename){
  if ( cam.takePicture()){ 
    // Create an image with the name filename
    // Open the file for writing  
    // delete it if it exists 
    SD.remove(filename) ;
    delay(200);   
    File imgFile = SD.open(filename, FILE_WRITE);
    // Get the size of the image (frame) taken  
    uint16_t jpglen = cam.frameLength();
    // Read all the data up to # bytes!
    while (jpglen >= 1) {
      // read 64 bytes at a time;
      uint8_t *buffer;
      uint8_t bytesToRead = min(32, jpglen);   // change 32 to 64 for a speedup but may not work with all setups!
      buffer = cam.readPicture(bytesToRead);
      imgFile.write(buffer, bytesToRead);
      jpglen -= bytesToRead;
    }
    imgFile.close();   
    cam.reset();
  }
}
void time_lapse(int num_pics, unsigned int wait){
  // Create an image with the name IMAGExx.JPG
  char filename[13];
  strcpy(filename, "lapse00.jpg");
  for (int i = 0; i < num_pics; i++) {
    filename[5] = '0' + i/10;
    filename[6] = '0' + i%10;
    take_picture(filename);
    delay(wait);
  }
}

Parts

Title Description # Cost Link Picture
TTL Serial JPEG Camera with NTSC Video Camera from adafruit 1 $39.95 Link Vc0706_lrg
Servo Motor Continuous rotation servo motor. 1 $13.95 Link 09347-1
PCB for SD Card and Camera PCB supports camera and SD card atmge32u4 and USB. 1 $7.0 Link Screen_shot_2013-02-15_at_5.34.31_pm
ATMEGA32U4-MU Integrated Circuits MCU AVR 32K FLASH 16MHZ 44-QFN Value: 2.7 V ~ 5.5 V 16MHz 1 $6.04 Link Screen_shot_2012-12-28_at_7.31.41_pm
microSD Card Connector Secure Digital - microSD™ Push In, Push Out Value: microSD 1 $3.44 Link 0473340001
USB connector USB Mini type B Value: female 1 $0.68 Link Usb-m26ftr
Crystal CRYSTAL 16.00000 MHZ 20PF SMD Value: 16MHz 1 $0.53 Link Ecs-270-20-3x-en-tr
Switch SWITCH SLIDE DPDT 6VDC 0.3A SMT Value: DPDT 1 $0.44 Link Mfg_js202011scqn
Button 6mm Through Hole Tactile Switch Through Hole SPST-NO 0.05A 12V Value: 0.05A @ 12VDC 3 $0.1 Link Screen_shot_2012-12-28_at_7.41.40_pm
Permalink: http://lucidtronix.com/tutorials/14
Servo motor, JPEG camera, and Arduino Leonardo combine to make a panoramic camera....
Arduino-powered spherical camera with 2 Servo Motors and an SD Card....
Mixing pixels from two face images together....
Our take on the classic bouncing ball, paddle game....
Handheld gaming machine, based on the Arduino Leonardo, equipped with joystick, SD card and more....
Print bitmaps, cellular automata, drawings and text.....
Use the Joy Gamer to make a dynamic picture frame....
A wearable real-time clock with vibrant color display....