Fareed Mohmed← Project library

Engineering · Raspberry Pi · Project 32 of 47 · Camera and vision · Beginner

Time-lapse camera

Take one photo every few seconds and string them into a film later. Slide the room light from dark to bright and the pictures show a sunrise.

▶ Open in the simulator

Raspberry Pi simulator drawing of the circuit for Time-lapse camera: the board, its power supply and the parts wired to the 40-pin header
Privacy and safety. A camera records people. Tell everyone who lives in or visits the place, keep the pictures private, and delete old ones. Switch the Pi off before you plug in or remove the camera ribbon cable.

Parts in this circuit

PartType
Pi CameraPi Camera Module 3
Shot lampLED

Wiring, pin by pin

Red = 5 V, orange = 3.3 V, black = GND, other colours = signals. “Pin” is the position on the 40-pin header; the GPIO number is what the code uses. Power the Pi from a 5.1 V supply and wire with the power off.

#ColourFrom (part and leg)To (header pin)
1ColouredShot lamp - anode +Pin 11 (GPIO17)
2BlackShot lamp - cathode -Pin 6 (GND)

Python code (gpiozero)

from picamera2 import Picamera2
from gpiozero import LED
from time import sleep

cam = Picamera2()
cam.configure(cam.create_still_configuration())
cam.start()
sleep(1)

lamp = LED(17)

for n in range(1, 7):
    lamp.on()                                  # the lamp shows that a photo is being taken
    cam.capture_file("frame%02d.jpg" % n)
    lamp.off()
    print("Frame", n, "of 6")
    sleep(3)                                   # wait 3 seconds

print("Done. On a real Pi you would join the frames into a video.")

How the code works

You will learn

  • Repeating an action with for and range
  • Making file names with numbers (frame01, frame02)
  • Waiting between pictures

Try this

  • While it runs, slowly drag the Room light slider up. Look at the six photos.
  • Move the ball a little after each photo.
  • Change the waiting time to 1 second and the count to 10.

On a real Pi

  • To make a film, use ffmpeg on the Pi: ffmpeg -framerate 10 -i frame%02d.jpg timelapse.mp4
  • For days of shooting, save the photos to a USB drive and use a good power supply. A power cut stops the film.
  • Keep the exposure fixed for time-lapse, or the brightness jumps from photo to photo.

Parts to buy

The links open a search on each store, so you see what is in stock today. Check the model, voltage and price before you order.

#ItemQtyBuy / compare
1Raspberry Pi 4 Model B
about 4000 to 9000 INR
1Robu.in Amazon.in ThinkRobotics
2Official 15 W USB-C power supply (5.1 V, 3 A)
Do not use an old phone charger
1Robu.in Amazon.in ThinkRobotics
3microSD card 32 GB, class 10 / A1 (with Raspberry Pi OS)
And a card reader to write it
1Robu.in Amazon.in ThinkRobotics
45 mm LED, green1Robu.in Amazon.in ThinkRobotics
5330 ohm resistor, 1/4 W
One per LED
1Robu.in Amazon.in ThinkRobotics
6Raspberry Pi Camera Module 3 (12 MP, autofocus)
Or a Camera Module 2 / HQ camera
1Robu.in Amazon.in ThinkRobotics
7CSI camera ribbon cable, 15-pin, 30 cm
Check the port size of your board
1Robu.in Amazon.in ThinkRobotics
8Camera mount or small tripod1Robu.in Amazon.in ThinkRobotics
9Dupont jumper wires, male-to-female, 20 cm (pack of 40)1Robu.in Amazon.in ThinkRobotics
10Breadboard 830 points
For resistors and shared GND / 5 V
1Robu.in Amazon.in ThinkRobotics
← 31. Count objects with the cameraAll projects33. Obstacle-avoiding robot car →

This is a learning tool. The simulator checks the program logic, not the electrical design. Never put more than 3.3 V on a GPIO pin.