Let's add a real time clock to our trail cam and then look at a casing to house it all.

This guide is now a couple of years old and although it is still valid, new software and hardware has been released that supersedes what follows. Read the new version of this guide

Where we've got to

You should now have a working trail cam that records video for a set duration and then saves the video to a USB stick. If you're not quite there yet, go back over the steps in part two of this how-to guide and if you're struggling, leave a comment and I'll see if I can help.

Keeping the time

Recording videos of wildlife is really useful if you want to know when an animal is in your garden or visiting a feeding station. If you know the time the animal is caught on camera, you are able to build up a picture of its routine and eventually predict when it might next be recorded. This relies on knowing when the footage is recorded. Raspberry Pis do not feature an on-board clock, meaning they set the date and time only when they connect to the internet. If you are using your trail cam in range of a WiFi connection point then this isn't a problem, each time you switch the Raspberry Pi on, it will update the time to the current, correct time. However, if you are planning on using the trail cam in a remote area where there is no WiFi connection, the Raspberry Pi has no way of knowing what the current time is. If you were to switch it on without an internet connection being present, the time defaults to January 1st, 2000 so our trailcam.py program would timestamp the video files and annotate the videos based on this default. Of course, you could make a note of when you switched on the Raspberry Pi and then calculate when the video was recorded relative to that time but there is a much easier option!

By adding a Real Time Clock (RTC) component to our Raspberry Pi, we can use it without an internet connection and know it will keep the correct time. RTCs come in different shapes and sizes but for our project, the smaller the better. Check out this mini module over at The Pi Hut. The RTC utilises something called the I2C (pronounced 'eye squared see') bus on the Raspberry Pi. Going into I2C in detail is beyond the scope of this guide however, in order to use the RTC you must enable the I2C interface as we did with the camera - do this BEFORE attaching the RTC:

sudo raspi-config

Select Advanced options and then Enable automatic loading of I2C kernel module

Next, power down the Pi

sudo halt

Make sure to disconnect the power cable before attaching anything to the Pi. You can follow the RTC set up instructions from The Pi Hut here.

Once set up, you should be able to type 


in your command line and the Raspberry Pi should return the current time and date. It's important not to unplug the RTC from the Pi or else it can lose step and report back the wrong time. If you do unplug it, follow the instructions again to get it in sync again.

So now we should have a fully functioning trail cam that when switched on:

  • Sets the current time using the RTC module
  • Mounts a USB drive to a designated mount point
  • Automatically runs out trailcam.py program
  • Detects motion from via the PIR sensor and records annotated videos, saving them to our USB stick.

Now is the time for some thorough testing to make sure the PIR is detecting movement, that the camera recording the video and the program is successfully writing the video to the USB stick. Once you are happy this is all going according to plan, it's time to move on to the casing.

Making a casing

This section of the guide is more subjective that the previous parts simply because there are lots of ways to go about making a housing for your trail cam. You might want to use a project box from and electronics shop and modify it to suit. I tend to use clip lock food container since they come in all shapes and sizes, they are mostly air and water tight but best of all, they are easily accessible (which is great when swapping out USB sticks).

Detailed here are the steps I've taken to make a casing for my latest revision of the trail cam using a Raspberry Pi Zero but the fundamental steps are the same for any Pi.

Taking a small clip lock food container, I drilled a couple of holes to allow the PIR sensor and the camera lens to see out of the case. Using some waterproof sealant, you can 'glue' the PIR sensor's cover in place. You might not want to do this for the camera so you can use it in other projects. I got round this by sealing a small piece of plastic across the hole and then taping the camera board against the plastic to hold it in place.

The heaviest piece of the project is the battery. If it moved about inside the case, it could damage other components or knock things loose so it is important to restrain it. It should be possible to tape the battery to the side of the case. In my case, I used some sticky velcro to attach it to the lid of the case. This way it is kept out the way of other peripherals but is securely fastened.

As for the Raspberry Pi, I simply blu-tac'd it to the base of the case making sure all the wiring and peripherals could fit in (if only just).

I finished off by covering the outside in black tape mainly to prevent the LEDs on the components shining out the case and potentially scaring the wildlife but also to help the camera blend in a bit more. Camouflage tape would also work, of course. 

I attached an old trail camera belt and clip to the camera through a look in the tape rather than making any more holes in the casing to save water ingress. You can use anything you like to make a way of fastening the camera but make sure it's secure! I've had badgers come up and nose the camera quite vigourously so make sure they can't detach it from it's location in the field - you might never see it again!

The Raspberry Pi camera module is pretty good. There is now a newer model available with better resolution but here's footage from my camera.

So that wraps up the guide on how to make your own trail camera. Of course there are lots of other ways to go about it so let me know in the comments how you get on and if you have any questions of modifications. I'd love to hear from you.