Introduction: Time-Lapse Box

This tutorial will show how to build a Raspberry Pi setup to shoot timelapses!

The setup is made of a box containing a light source and a camera (PiCamera) controlled by a Raspberry Pi to take pictures and upload them to Google Drive.

I apply my light-box to time-lapse the growth of bacterial colonies on the surface of Petri-dishes. However, this set-up can be easily adapted to timelapse or visually monitor anything you want!

I will walk you through all the steps I followed to get my system working:

Step 1: You will prepare your Google account so that your Raspberry Pi can autonomously send pictures to Google Drive

Step 2: You will set-up your Raspberry Pi to control the light source and the camera and so that it can access your GoogleDrive

Step 3: You will build the box and mount the Picamera

Step 4: You will wire the Raspberry Pi's GPIO and the light source through a relay

Step5: Start shooting!

Note that the order of the sections of this tutorial does not matter. You can follow them in any order you want!



1) 1 Raspberry Pi (Here Version Pi 3 Model B+) + 1 Picamera (Here Module V2) + 1SD card ( between 8 and 32Gb)

2) 2 5V Power supplies, keyboard, mouse, screen and WIFI for working with your Raspberry Pi

3) A 5V relay and a bunch of electric wires.

3) A light source (Here I use a light pad Gaomon GB4 to light-up the Petri-dishes from below!)

4) A big box (or wooden boards to build it)

7) Common tools (plyers, screw driver, tape, soldering iron, drills) + 3 partially-threaded screws (2.2 to 2.5mm diameter)

Step 1: Set Up Your Google Account.

Introduction to this step

We save the pictures taken by the Raspberry Pi on Google Drive. On top of avoiding filling your Pi's memory, this will allow you to check on your time lapse from anywhere around the world!

Google has released a Python package called PyDrive which allows you to upload and download files with... Python!

Google provides plenty of documentation to understand how to handle PyDrive. I also found Annis's tutorial very helpful. However, if you are a biologist like me, all this programming jargon (API, scopes, flow, token...) might be a bit overwhelming. So here is the story as I understand it:

You create a project on your Google account and enable the programmer option for this project. Google will give you a name and a passcode that your python script uses to connect to your Google account. When connecting for the first time, Python uses an authorisation "flow" where it tells Google what service it wants to access (The list of services Python wants to access is called the "scope"). When Google receives a flow request from python, it will ask your authorisation. Once you manually accept, Python gets credentials and a token to connect with Google without your authorisation in the future.

1) Go to Google Cloud Plateform and click on Select a Project on the blue ribbon. Click on New Project on the top right of the pop-up window. Name your project and click Create. This will bring you back to the welcome page. Again, click on Select a Project on the blue ribbon. Now click on the new project that you just created.

2) Click on the Burger menu at the top left of your screen. On the left column of the screen select API & Services >> Dashboard. Then,just under the blue ribbon select + ENABLE APIS and SERVICES. Next, search for Drive in the search bar and select Google Drive. Then click on the Enable button.

3)Go back to the Burger menu>> API & Services and this time select Credentials. On the next page go on the OAuth Consent Screen and give your application a name and Save. Now click on the blue 'Create Credentials' buttonselecting the OAuth Client ID option. Now tick the Other option and Create.

4) Now you'll be able to download a file called client_secret.json. This file stores your credentials and token. It will be used by your python script on your Raspberry Pi to interact with your Google account. For now save it on a flashdrive as 'credentials.json' , you will transfer it to your Raspberry Pi once set-up.

Step 2: Setting the Raspberry Pi

Introduction to this step:

Here, you will install the packages and python script for your Raspberry Pi to operate. The python script is the brain which governs our time-lapse device. It has three main functions:

1) It deals with the Google Drive. As explained in section 1, if you want to know more about this part look up here, here and here). 2) It actuatesthe GPIOsto turn on the light source. 3) It actuates the PiCamera to take pictures.

If you want to understand how the script works, I have heavily commented each step and have included the links to the online tutorials I have used to write it.

Alright let's begin:

1) Prepare your SD card

Format your SD card to format FAT. Download NOOBS from the Raspberry Pi website. Copy and paste all the files from your freshly downloaded folder straight onto your SD card. If stuck, detailed instructions can be found here.

2) Boot your Raspberry Pi

Just insert your SD card in your Pi turn, it on, and follow the booting instructions.

3)Make sure your Raspberry Pi is set on correct time:

>>in the command window enter the following command:

sudo date -s "Mon Aug 30 15:27:30 UTC 2019"

4) Make sure you are using python 3

>>in the command window enter the following command:

python —version

>> if the python version is not 3 edit the .bashrc file by entering the following command:

sudo nano ~/.bashrc

Scroll down at the end of the document and add the following line to the end of file:

alias python=‘usr/bin/python3.5’

save and reboot

5) Install the packages needed:

>>in the command window enter the following commands:

pip install pydrive

sudo apt-get install libatlas-base-dev

pip install google-auth-oauthlib

python -m pip install -U matplotlib

python -m pip install -U httplib2

sudo apt-get install python-gi-cairo

6) Enable PiCamera:

>>type in the Terminal: sudo raspi-config

>>Click on 5 Interfacing Option then on P1 Camera then enable the camera interface and reboot

7) Save the Python Script and the file credentials.json on your Raspberry Pi:

Download the python script provided in this is the script that will be executed to shoot the time lapse. I have put it together by copying some bits of codes found online (I provide the addresses of the web pages used in the script). credentials.json is the file which you got in the last step of Section 1 save it with in the folder Documents of your Raspberry Pi.

8)Establish the authentication flow with your Google Drive : contains all the instructions to establish the first authentication flow with your Google Account with the application that you created in Section 1. It transmits the credentials stored in credentials.json to Google and opens up your web browser so that you can manually log in to your Google Account and grant permission to your app to access your Google Drive. Once this is done, Google gives us a Token that saves in your Documents as a file called token.pickles which will be used to establish connections without your input in the future.

Execute, type in the Terminal:

>> cd Documents

and then:

>> python

Log on to your Google Account and allow your application to access to Google Drive.

After this step, check that your Raspberry Pi is taking pictures and saves them to your Drive.

9) Make sure that your Raspberry Pi executes on boot without any user input:

To allow your Raspberry Pi to run when booting, we tell it to open the terminal when it is booting and to run when the terminal opens:

To tell the Pi to open the terminal on boot we modify the file autostart. Type in the command window :

>>sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

Then type @lxterminal immediately above the '@xscreensaver' line. Save and close by typing ctrl+x then y then enter.

To run when the terminal opens we edit the .bashrc file. Type in the command window:

>> sudo nano /home/pi/.bashrc

Scroll down to the end of the file and type:

echo Running at boot

sudo python /home/pi/Documents/

Save and close by typing: ctrl+x then y then enter.

10) Move some packages around:

Now will run on boot. However, the packages it needs are now saved in a place it cannot access ( /home/pi/.local/lib/python3.5/site-packages). We therefore need to move those packages to the location it can access (/usr/lib/python3.5/dist-packages). To move those packages, type the following command in your Raspberry Pi terminal:

>>sudo cp -a /home/pi/.local/lib/python3.5/site-packages/. /usr/lib/python3.5/dist-packages/

You can check that those packages were moved by going to those location with file manager. You will need to right click and select Show Hidden to make .local appear in file manager.

This is the end of this section! The next sections are going to be a little more crafty: we will build the box and connect the Raspberry Pi to start shooting our timelapses!

Step 3: Build the Box

Introduction to this step:

The best time lapses are shot in a constant light environment where nothing moves apart from the thing you are filming. You can use any space where the lighting doesn't change too much such as a big card box, a cupboard, a storage room as long your setup won't be disturbed throughout the recording.

A laser cutter will allow you to build a neat box with perfect dimensions for your set-up . However, you don't need something so fancy to shoot great time-lapses. You can also use any space where the lighting doesn't change too much such as a big card box, a cupboard, a storage room...

1) Design your box.

I used a laser cutter (Trotec Speedy 360) to build a box (in 6mm MDF wood) that not only has the right dimensions but also has a f*cking great design.

Bear in mind that your box needs to be high enough so that the camera can capture your entire scene. Use the horizontal and verticalfields of view of the picamera to estimate how high your camera needs to be to capture what you are filming.

I used Make a Box with the following dimensions (Width:303mm, Length:453mm, Depth (=Height):350mm, Plank width:6mm) to get the blueprints. I added a few holes for the Picamera and the wires and also engraved some cool trippy drawings found on Freepik.

2) Assemble your box

3)Mount the Picamera

Having a steady camera which doesn't move throughout your shooting is very important to get a good looking time lapse. After trying tape, 3D-printed PiCamera cases and others, I came up with a nice trick to both set the orientation of the camera andkeep it firmly fixed on top of the box. I use 3 screws which are threaded only at their tips. The unthreaded part is the one going through the wood depth while the threaded tip goes in the picamera hole. When rotating the screw, the threaded tip will move the PiCamera corner closer or away from the surface of the box. This allows you to precisely and firmly set the angle of your camera to capture your scene.

Please note that this is the most crafty part of this Instructable as the holes emplacement and angle need to precisely match the ones on the Picamera. It is probably best that you first practice on a spare piece of wood before you start poking holes all over your beautiful box!

Step 4: Wiring the Light Source to the RaspberryPi

Introduction to this step:

This section takes care of wiring your light source, your 5V relay and the Raspberry Pi through its GPIO.

Important:I don't know much about working with electricity and high voltages (I am just a biologist after all). I cannot guarantee the safety of this tutorial and of the final set-up. Be particularly cautious to fire hazards and when working with high-voltage!

You can look hereto read more on how a 5V relay works and herefor a full tutorial on controlling the RaspberryPi's GPIO.

You might notice that I did not include any resistor in the circuit that powers the light pad. This is because is suspect that the LED string in it already has them.

Apart from that, it's all on the video!

Step 5: Shoot Time Lapses!

And you are done!

Have fun and share your art in the comments!