Learn how to build a Raspberry Pi timelapse camera for at home or a compact rig for traveling. Timelapse photography is a fantastic way to capture the passage of time. It adds the dimension of time to videos that we do not see with our naked eyes and therefore these are immediately captivating.
The problem with timelapse photography is that it requires leaving a camera in one place for a long period of time. You then need to monitor it in order to ensure that it doesn’t run out of battery or get stolen!
What if I told you that for around $50 you could construct a fully remote timelapse rig using a raspberry pi, a camera module and (optionally) a battery pack. Hopefully that last addition will get your mind excited!
Things to buy:
Other things you’ll need:
- Network Cable
For this set up I will just use a Mac connected to my home network. I didn’t have an additional keyboard or a mouse.
The only problems that arose for me was when I didn’t input the code exactly correctly. So make sure to couble check everything. The total time for this build was around 3 hours but you can hopefully do it much faster by reading through this quick tutorial.
Remember this is just a guide to get you going . At the end you will have a worknig timelapese rig that you can install wherever you like. You will need to arrange some sort of case and get the location, permissions etc.
Note: copy the code below inside but not including the “quotes”. Or your code won’t work :).
Step by Step Guide:
1. Install raspbian on your micro sd card using your computer.
Visit http://downloads.raspberrypi.org/raspbian_latest to download the latest distrobution of raspbian.
Unzip the package by double clicking on it in your Downlaods folder.
Double click the file to un-zip it and insert the micro SD card into the mac using a dongle or adapter. Format it as a MS-DOS (FAT) disk using disk utility.
Launch Terminal on your mac and type “cd Downloads” this will navigate to your Downloads directory. You can type “pwd” to confirm this. See below for a list of handy terminal commands if you are not familiar with basic bash commands.
Now type “df -h”
Identify which of the disks is the one that is your SD card. It will be “dev/disk1s1” or “dev/disk2s1”
Now you want to unpack the distro.img onto the SD card. This will take some time and you will have no feedback until the process is done. You must wait for the cursor prompt to return (i.e. no progress bar). Just watch my travel vlogs here to pass the time 😉
Run the following commands making sure to substitute the question marks with the number of your drive. Note: Be bloody careful as a little mistake here will cause your mac to become useless!
“sudo diskutil unmount /dev/disk?s1”
“sudo dd bs=1m if=./2016-05-10-raspbian-jessie.img of=/dev/disk?s1”
“sudo diskutil eject /dev/rdisk?s1”
In this instance the disk is named disk2s2. Remember that this process will take a long time. You’ll need to wait 15-30 min …. or more.
2. SSH into your Pi to complete the set up
Put the SD card into the Pi connect it to the router with the ethernet cable and finally plug in the power. Give it a minute to power up.
Open another terminal box and type in “arp -a”. This will list off all of the devices connected to your router. You should be able to pick out the IP address of the Pi by looking at the various hostnames. It will be something like “192.168.1.??”. Replace the question marks with the last two digits of your IP address.
Type in “ssh [email protected]??” remembering to replace the question marks with the number you see above. If you have the wrong IP address it will not proceed. Try again with another IP until you see it asking for a password. Here you will enter “raspberry” as the default password.
Once you see that you’re connected to the Pi type in “sudo raspi-config”. Navigate to expand the file system, hit enter. Navigate to finish, hit enter. Select yes, hit enter. You will then be kicked out of your SSH session as the Pi is rebooting. Wait a couple of minutes to proceed.
SSH back into the Pi. Hint: you can do this pretty fast by pushing the up arrow in the terminal to show the last commands. When you see the SSH command just hit enter and it will re-run it. Run the following commands to ensure that your Pi is up to date:
“sudo apt-get update”
“sudo apt-get upgrade”
Note: This may take some time to complete the update so again just check out my youtube channel to pass the time 🙂
Once complete type “sudo shutdown -h now” and wait for the green light to stop flashing. This will end your ssh session.
3. Set up camera and make a little script
Unplug everything. Install the camera module into the raspberry pi. I am using the noIR version. Lift up the tabs, slide in the ribbon cable in with the metal parts facing away from the usb ports. Press the plastic tabs down to lock it in place. Plug in all the pi cables again.
SSH back into your Pi using the steps above. Enter the password “raspberry”.
Enter the “sudo raspi-config” command again. Navigate to the camera, hit enter. Enable the camera then navigate to finish to reboot the Pi. This will end your SSH session.
SSH back into the Pi. Take a second to familarise yourself with the directorys. This will help you navigate around. The following commands are essential to the bash command prompt. These will help you navigate through the file structures:
Type “pwd” to understand which directory you are in. Type “ls” to list all of the files and folders in the current directory. Now to check the camera type “raspistill -o photo.jpg”. To confirm that it worked, type “ls” again and review to see if there has been a file generated named photo.jpg.
Viewing this file inside an SSH session is kind of tricky but here is how to copy them to your local computer to view. The best is to copy the picture to your mac to view it.
Open up a new terminal on your mac. Do not SSH into the Pi. If you are currently connected via SSH type “Exit” to end the session. Type in “scp [email protected]??:/home/pi/photo.jpg /????/????/??????”. Replace the question marks with the folder path to a location on your mac. e.g. desktop is /Users/MyName/Desktop. MyName is whatever your computer name is. You will then be promped for the password and then the download will begin.
Hint: You can copy the path of any folder on a mac by holding down the option key, two finger clicking the file then selecting copy file path. Open the file to view your first Pi shot!
The next step is to make a small script that will take a picture with a time stamp and put it into a separate folder. Make sure you are back in the Terminal that is SSHed into the pi. Start my making another folder to store the photos. Type “mkdir photos”. To confirm type “ls” to see what comes up. Now navigate to that directory using the command “cd photos”.
Now we need to make a small script that when we run it it will take a photo each time it is run. The terminal has an inbuilt text editor that we can use to make this script. It is called nano. Create the script and open nano in one command with “sudo nano photo.sh”. Take the code below (without “quotes”) and paste it into the text editor window.
“raspistill -o /home/pi/photos/$DATE.jpg”
When finished push “control+x” on the keyboard and hit “y” and return to save.
To make sure that it works you’ll need to run the script. Type “sh photo.sh”. To check that it worked you can hit “ls” and see if there is a photo with the current date in the folder. If so pat yourself on the back. You have almost finished this!
4. Set up the automation to make the timelapses happen
We want to make it capture pictures every X seconds or X minutes or whatever you want. So lets make that happen. Linux (raspberry pi) has something built in called the cron tables that manage repeating tasks. It sounds difficult but it really isn’t.
Type in “sudo crontab -e” this will open up the cron tables. From here select “nano” the text editor that we used before. Once open use the arrow keys to scroll righ to the very bottom.
Paste in the following peice of code:
*/5 * * * * sh /home/pi/photos/photos.sh
This will take a photo every 5 minutes. If you would like it to run every minute then just change the 5 to a 1. Likewise 10 minutes or 30 min etc. The positioning of spaces and number of stars is vitally important here.
When finished push “control+x” on the keyboard and hit “y” and return to save.
To check that it is working we can use the “watch” command to monitor the folder and list any changes. Type “watch ls” to list all of the changes to the folder. Let it sit for however many minutes you typed in (my case is 5 min) and if another photo with a different time stamp pops up then viola you have done it! You can press “option c” to stop the watch command.
If you want to stop taking the photos just remember you can remove the line from the crontab by following the steps above and just deleting the line of code.
Download the photos onto your computer by using the tutorial above but replace it wuth the following commands “scp -rp [email protected]??:/home/pi/photos /????/????/??????”. Remembering to replace the question marks with the destination path.
Follow the tutorial above and make yourself a timelapse video. It is possible to compile the photos on the raspberry pi but it does take a loooong time. Look at different software options. I use “time lapse assembler” on the mac. But it is also possible using photoshop or a video editor such as Final Cut Pro X.
Get inventive with your timelapse and post it up on youtube. Add a link to the comments below for the world to see.
As always if you are having any troubles getting this set up, I am here to help. You can drop me a comment in the box below, or message me on any of the social channels. I am always happy to help!