Monday, 27 October 2014

Part 1: How to make your own Raspberry Pi Trail Camera 'PiTrailCam': Design Brief

Edit 16/11/14: Part 2 of this series is here

In a previous post, I've described my Trail Camera, which has been doing a sterling job of photographing the wildlife at the bottom of my garden.  We've been introduced to deer, badgers, foxes, mice and occasionally my neighbours dogs who periodically escape and have a romp through the woods.


I've taken inspiration from the AfraidOfSunlight.co.uk blog.  The author used a Raspberry Pi + camera + PIR combo to create a home-brew equivalent of a trail cam, with some great footage of birds.  Check out the Kingfisher and Sparrowhawk clips.

Why do this?
First of all, a commercial Trail Cameras are not cheap.  While mine is great, it has a lot of plus points but has a few limitations:

Commercial Trail cameras


Commercial Trail cameras: PLUS points
  • Simple interface - no tinkering required
  • Very long battery life (especially if stills setting used)
  • Durable - has lived outside for most of this year without problems.
  • Day vs. Night image capture issues taken care of with automatic IR cut-out filter (more later on that).

Commercial Trail Cams: Limitations 
  • Simple interface - no tinkering required (did you see what I did there !?)
  • Limited to only stills or video - not both at the same trigger point.
  • Its a closed device - i.e. cannot communicate with/trigger actions on other devices
  • EXPENSIVE

My plan is to build one around a Raspberry Pi, which is an open-source linux-based mini computer, available for approximately £30.  Along the way I'll go into detail for kit, configuration and any coding used, referred to from this point as "PiTrailCam"


What makes a Trail Camera ?

I've attempted to detail the various components that go into making a Trail Camera, and my thoughts about options for custom designs.

The glue that hangs it all together: Some sort of processing device.  I'm going to use a Raspberry Pi mini computer (RaspPi).  I've been tinkering with these for a while and there's loads of stuff out there that you can do.  My projects have been limited mainly to video streaming nest boxes and timelapse movie creation, however this project will expand to include relays, voltage conversion and MQTT messaging (more later).

1) Camera - Several options here.  Could use any/some of:


a) Raspberry Pi camera module
Small, compact wide community of users to troubleshoot.  Limited to one RaspPi Camera board per Raspberry Pi, however could use webcam in addition.  The PiNoir version has IR filter removed which opens up the option to do Night imaging + IR illumination
b) Webcam 
I'm currently using Microsoft Lifecam Cinema webcams in two bird boxes which stream video to my home network from which I can extract images/video, currently using iCode's iCatcher software (commercial).  Video and/or still images can be captured dirently from webcams and saved to the Pi's SD card.
c) Compact camera (with facility to control over USB).
The argument for this is the better optics and zoom of a compact camera.  The ShallowSky.com blog  combined the Raspberry Pi camera with a Cannon Powershot A520 to create a  'CritterCam'.  This used the  Raspberry Pi camera as a trigger (via image movement detection) with the better optics and zoom of a compact camera.  The downside is that 'as is' they wont work for night shots since the cameras infra-red (IR) filter will be intact.  While its is possible to hack your own, I'm not planning this.  This particular model can be picked up relatively cheaply on ebay.

Power source (battery vs. wired)
'In the wild' TrailCams are usually battery powered.  My commercial one takes 8 x AA batteries and also has a 12V DC in as an option too.  I'm going to use wired as this is only planned to be used near a mains power source.  In past projects I've used a power-over ethernet kit (PoE) from TP-link which means only need one cable is required to the device.

Illumination

For night time imaging, we'll need some sort of artificial illumination.  Options are visible light or infra-red light (IR).  IR has the advantage of being less likely to disturb the wildlife.  My commercial Trail Camera  uses a ring of IR LEDs set around the camera.   The downside my existing TrailCam is that the IR leds ring surrounds the camera, which means that at night all animals get the IR equivalent of red-eye.  My design will use IR illuminators away from the camera to avoid this.

In order to use IR illuminators at night, you need a camera that has had its IR filter removed (This filter is called an IR bypass filter).  There are several mods out there to the IR filter from various webcams, but I'm not going to attempt this.
Luckily, there is a version of the Raspberry Pi camera without an IR filter, called the Pi-Noir which I'll be using alongside some IR LEDs.

IR bypass filter
The downside of using the Pi-Noir is that I'll need to add back in an IR bypass filter for daytime imaging.  While this isn't strictly necessary, there will be an odd colour cast to the daytime images without one.

Commercial Trail Camera: Night minus IR filter with IR LEDs on, Day time with IR filter in place 

This is taken care of nicely in the commercial kits, they probably use a CCTV IR cutout filter module that integrates with CCD board cameras.  I'm not yet clear how I'll do this but essentially I'll need to move an IR filter infront of the camera, or camera in front of an IR filter (my commercial trail cam does the latter for IR-illuminated night shots).  I came across this IR bypass filter on ebay, designed for CCTV CMOS camera boards that I may try.

File Storage
Options: 1) On the Pi's SD card; 2) On local storage media (eg USB stick); 3) On local network.
My commercial TrailCam has an SD card slot.  I have 2x 32Gb SD, I swop one in whe the other comes out.  Although I've yet to fill one, its a bit cumbersome when I want to review footage as I have to physically swap cards, and copy images/video to my PC.  Since PiTrailCam will be connected to my home network (remember I'm using PoE), I'll copy / save captured images/footage directly to my home network.  I also want to get away from having to physically remove storage media since a home-brew affair may be less open-uppable!

Facility to live view captured footage/images
Commercial Trailcams often have an LCD screen which allows you to review captured footage.  I plan to make my PiTrailCam accessible remotely over my network so won't need to do this.

Mechanism to detect movement

Passive Infared sensor (PIR)
A Trail camera is essentially useless without some means to detect movement.
This can be achieved either 1) Using software to compare sequential images for changes, or 2) Using physical sensors such as a passive infrared motion sensor (PIR) - the same thing that switches on your outside lights on when you put the bins out at night.


Water-tight enclosure
Various takes on this out there including cardboard, wood and plastic: from Tupperware to a more rugged case such as the Pelican 1040 case, as used in these commercial 'build your own' TrailCam kits).  I'll probably go for a wooden one as I'm more comfortable working with wood (see my previous side-view nest box project, which remains water-tight to this day!)

Trigger one trail cam from another
One cool thing that I would like to do is cause one PiTrailCam to trigger another.  This might be to capture the same event from different angles, or to utilise different cameras from the same viewpoint; or maybe to capture the progression of a subject from A to B to C.  The bonus of the low cost of these devices is that several PiTrailCams can be built for the cost of a commercial one.

I plan to use MQTT to do this.  This is machine-to-machine (M2M)/"Internet of Things" connectivity protocol, it sounds a bit complex but conceptually its quite simple.  One machine publishes a message to specific 'listening' machines, the message might be triggered by a PIR activation event on PiTrailCam1.  The listening machine (PiTrailCam2) can be configured to carry out a particular task (e.g. take a picture) when it receives the message from the first machine.


Over the next few weeks I'll post my progress.  In my next post I'll expand on the trigger and image capture side of things, the prototype of which is merrily clicking away in my office when I move about, taking pictures of the back of my head....

Edit 16/11/14: Part 2 of this series is here

5 comments:

  1. Can you use a lua-Linux module to complete this task?

    ReplyDelete
  2. did you ever get yours built?

    ReplyDelete
  3. Very interested in this project. Just stumbled upon it. How did your end result turn out?

    ReplyDelete
  4. Really cool idea. Any idea to power this if you did not have a power source? I saw some 4,000 and 10,000 ma USB battery packs, but not sure how long it would last before the battery would die.

    ReplyDelete
    Replies
    1. not sure - essentially the only power draw is in monitoring the PIR state. I had a RaspPi model A on timelapse which could do approx 3000 images on 8AA batteries which is essentially what my commercial trail cam will run on for months...
      I'm sure this could be made more efficient with the use of a modelA or Pi Zero. The 12v LED arrray must use a load of power, but haven't taken it 'off grid'.

      Delete