The idea for this  current version is to condense down the functions from the previous versions in to a single board that fits on top of the raspberry pi zero W.

I also wanted to reduce the cost and complexity of the previous versions to increase the reliability and make it easier to use.




The main board sits between the various components and the pi, and is populated with jst connectors to make fitting it all together easier.

I’ve been running a version of this board that I built with the excellent  protozero board : and thought I’d have a go at putting together a circuit diagram on fritzing.

A few clicks later I had the first version of the board ordered from – this was a bit of a mess, mainly as I managed to use an odd relay template but after a bit of tinkering I had this version printed.


Circuit diagram (click to enlarge):



The heart of the board is a L293D IC. I chose this as it can reverse the polarity of a signal which is necessary to control the IR filter over the camera lens. Further information here:


The L293D has 2 channels and I have used the second channel to control the relay. This is handy as it allows the GPIO pins to control a 5v relay with minimum effort or additional components (just a diode to prevent feedback) and provides an element of protection to the pi.

5v relays are easy to get hold of and cheap, and the minimal components mean that I can include the relay on the main board and not have to rely on per built boards.


The light is a 5v, 10W Infrared IR 840-850nm SMD LED unit.  It draws about 2A current so I’ve connected it to the USB battery supply via the relay to enable it to be switched.

Previously I’ve used a ring of LED’s but this brighter and doesn’t require a 12v supply so the whole assembly is smaller.

It gets very hot, so it may get an upgrade with a heat sink in the future.

Infra Red filter

This filter is designed for use with security cameras and consists of a small plastic element that is pulled in front of the camera lens to prevent infra red light getting through.

When it is deployed it gives a more natural colouration however when it is removed it picks the light reflected by the infra red lamp giving better vision in the dark.

It works by sending a 5v signal for a fraction of a second to the actuator – one way it moves in front of the lens and the other retracts it.

The polarity of the signal is handled by the L293D chip with the following outcomes:

Filter off
Chip pin Pi pin Signal
1A 16 LOW
1B 13 HIGH
Filter on
Chip pin Pi pin Signal
1A 16 HIGH
1B 13 LOW
Filter stop
Chip pin Pi pin Signal
1E 7 LOW


The buttons are simple and cheap ones from mod-my-pi but they’re decent quality and a normally open (push to make) type. They are current limited with a 220? resistor and the pin is pulled down to negative on the board so it is simple to put any button or even an LDR or similar with a jst soldered to it.

There’s no protection on these and I managed to fry my old test pi by plugging in the 5v supply to the light on the first board (stupid mistake, but it had a broken camera connector anyway).

PIR sensor

I’ve used an inexpensive HC-SR501 PIR (passive infra red) detector  datasheet

5v is supplied to the module and when it detects movement, it sends a 3v signal through the yellow wire which is detected by the pi on pin 15

There are adjustments on the sensor for trigger time, sensitivity etc which can be altered however it is set up in a configuration that seems to work.



Once again this does all of the heavy work to include the actual motion detection and video conversion. I’ve used the in built ability to add on a button to the main web interface that links to my own webpage which alters button size etc so  it’s a bit easier for kids with touchscreen devices to use.

  1. Status
  2. Current date & time
  3. Main screen
  4. Buttons



A program called “detect” is running which is started via cron at boot. This program is a loop that performs the following actions:

  • Waits for a trigger from the PIR then turns on the light;
  • Reads the pikrellcam pipe to see if the light or filter buttons have been pressed on the web page
  • Reads the 2 x buttons and performs the shutdown / restart wifi commands

Link to code:  HERE



I’ve not been able to give it a proper test with animals yet -I don’t have any secure outside space to use it anymore and when I’ve put it out in other gardens nothing has been about at night (as its a bit cold). It works well in low light with early risers and curious children so performs as well as the previous version in terms of triggering.


  • fritzing is really easy to use and handy for drawing up the circuit diagram.
  • It’s simple to turn the diagram in to a pcb, but you need to be careful with component choice to make sure they are easy / cheap to get.
  • Aisler are quick and  cheap  – 3 identical boards cost approx £20 which is less than buying the prototype boards. It’s also fun to get Emails from Felix keeping you updated on progress.


  • The lamp gets REALLY hot! Not so bad when it is on sporadically outside but running for long periods wil require a heat sink.
  • The top line of emitters failed on my first lamp during testing. This could be down to getting hot, defective lamp or mishandling (it was messed about with a lot).
  • the lamp is an 840-850nm version which works well with the pi camera. I’ve since bought 3 x smaller (3W) ones at 740nm, 850nm & 940nm to test out which is best.


I’ve used an easyacc 10400mAh power supply – link which works fantastically in normal operation, giving a good 10 to 12 hours of power for both the pizero and lamp.
It’s got 2 connections – 1A & 2.1A with the lamp requiring all of the 2amp supply to function correctly.
The only issue with the power supply is its size. It’s pretty small for its output however it is now the largest component in the whole setup, so it dictates the overall box required.

Internal access

There is nothing more irritating than the insides of the camera flapping about and disconnecting so I’ve screwed everything down in this version. All worked beautifully until I needed to get to the sd card and had to unscrew and disconnect the board so I’ve bought an SD card extender which should do the trick.

The battery is now easily accessible via a flap in the bottom of the birdbox and the connections, while fiddly to put in, are nice and stable.


Old version

The is the original version with the ring of IR LED’s and the main control board with separate ones for the relay and the filter control. Not shown are the 9v battery to power the light (supposed to be 12v but needed the space!),2 buttons  and the main powerpack.

New version

The is the new version with the pi zero attached to the back and all of the elements connected. The usb plug goes to the 2.1A output from the battery with the pi powered by the 1A output (lead not shown). It is a considerable saving in space & complexity over the old version with fewer areas to break.


This picture shows the evolution of the camera board:

  1. simple version for pi V1 to break out the gpio pins. Very bulky and needed the wires kept falling off of the pins.
  2. this version is again for the pi V1 but introduced a couple of buttons on the board
  3. the final pi V1 board with pins that allowed the various elements (relays, buttons etc) to be positioned in more convenient places.
  4. Explorer phat version that I just couldn’t get to work well enough. It was excellent for the filter switching but the relay control needed a bit more oomph (or a better programmer!)
  5. The populated and working previous version.
  6. prototype of the new board constructed on an excellent protozero board. Loads of messy wires and my crummy soldering underneath so plenty of points of failure.
  7. PCB version 1 – i managed to mess up the relay type and didn’t want to use expensive ones so moved on to the current version.
  8. Current version, populated and unpopulated.
  9. Current version fully connected.


Group shot of the cameras, from left to right:

  • Handheld version – as described on previous posts.
  • The current trailam. The lamp is in the top and camera below., the pir is now fitted under the camera (not shown in this pic) and the buttons are inside.
    Stupidly I ended up putting the smallest version of the trailcam in the biggest box I had! In reality it could easily fit in the smallest box with space to spare.
  • normal colour trailcam. This is just pikrellcam and an old camera and pi model A used in daylight.
  • old version – this has got the big light around the camera and the PIR in the little window. The button is cunningly positioned behind the door.


Custom index page

The Anicam is controlled with a custom php page that uses the feed from pikrelcam.



require_once(dirname(__FILE__) . '/config.php');
include_once(dirname(__FILE__) . '/config-user.php');
include_once(dirname(__FILE__) . '/config-defaults.php');

function time_lapse_period()
$tl_status = "../../.pikrellcam/timelapse.status";
$f = fopen($tl_status, 'r');
$tl_period = 1;
if ($f)
$input = fgets($f);
$input = fgets($f);
sscanf($input, "%d", $tl_period);
return $tl_period;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo TITLE_STRING; ?></title>

<script src="js-css/jquery.min.js"></script>
<link rel="stylesheet" href="js-css/pikrellcam.css" />
<script src="js-css/pikrellcam.js"></script>
<script src="js-css/expandable-panels.js"></script>
<link rel="stylesheet" href="js-css/expandable-panels.css" />

if (isset($_GET["hide_audio"]))
$show_audio_controls = "no";
if (isset($_GET["show_audio"]))
$show_audio_controls = "yes";

echo "<body background=\"$background_image\" onload=\"mjpeg_start();\">";
echo "<div class=\"text-center\">";
echo "<div class='text-shadow-large'>";
echo "</div></div>";
echo "<div class=\"text-center\" style=\"color: $default_text_color; font-size: 1.4em;\">";
echo "<img id=\"mjpeg_image\"
alt=\"No preview jpeg. Is pikrellcam running? Click: System->Start\"
style=\"border:4px groove silver;\"

echo "<div class=\"text-center top-margin\">";


<input type="image" src="images/bigstop.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
onclick="fifo_command('record off')"
<input type="image" src="images/bigpause.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
<input type="image" src="images/bigrecord.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
onclick="fifo_command('record on')"
<input type="image" src="images/bigtakestill.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
<input type="image" src="images/bigmotion.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
onclick="fifo_command('motion_enable toggle')"
<input type="image" src="images/mainmenu.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
<input type="image" src="images/lampon.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
<input type="image" src="images/lampoff.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
<input type="image" src="images/filteron.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
<input type="image" src="images/filteroff.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
<input type="image" src="images/videos.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
<input type="image" src="images/stills.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"

<div id="container" class="top-margin">

if (file_exists("custom.php"))
include 'custom.php';


This page basically hijacks the pikrellcam pipe and sends its own information through it to the python program.

import RPi.GPIO as GPIO
import time
import os
import sys
# Set pins to BOARD

# Setup pins for relay
Motor2A = 36
Motor2B = 32
Motor2E = 37
# Setup pins for filter
Motor1A = 16
Motor1B = 13
Motor1E = 7
#PIR setup
#set up PIR pin
PIR_PIN = 15
#set PIR pin as input

#set up BUTTON A pin

#set up BUTTON B pin

#below is the function MOTION which is called by the main program at the bottom
				print "motion detected"
				# double check
#				time.sleep(2)
				while GPIO.input(PIR_PIN)==1:
					print "confirmed"
#					time.sleep(1)
					# switch relay on
					print "light on"
					# wait 20 seconds - can change this
					print "waiting"
					# check the PIR again, if its on wait for another 20 seconds
					while GPIO.input(PIR_PIN)==1:
						print "still waiting"
					#turn off the relay
					print "motion stopped"
					print "Light off" 
				print "button A detected"
				while GPIO.input(BUTTON_PINA)==1:
					print "confirmed"
					os.system('sudo poweroff')

				print "button B detected"
#				os.system("sudo ifup --force wlan0")

# message is prined at startup & gives the PIR sensor 2 seconds to settle down before the program starts.
print "PIR Module test press Ctrl+C to exit"
#turn off the relay
print "Light off"

print "Sending signal"

print "Filter off"

print "ready"

# this runs all the time, checking to see if the PIR or buttons are triggered
	GPIO.add_event_detect(PIR_PIN, GPIO.RISING, callback=MOTION, bouncetime=300)
	GPIO.add_event_detect(BUTTON_PINA, GPIO.RISING, callback=BUTTONA, bouncetime=300)
	GPIO.add_event_detect(BUTTON_PINB, GPIO.RISING, callback=BUTTONB, bouncetime=300)
	while 1:
# stop program if ctrl+C is pressed
except KeyboardInterrupt:
				print "quit"

Handheld Raspberry Pi Infra Red camera


Following the construction of my trailcam, I’ve created a new version that is also hand held.  The intention is to use it as a normal trailcam as before (leaving it in position and triggering the video / light via sensor), as well as using the IR lamp & camera to view wildlife in the dark via the screen.

Prototype , built in the modmypi packaging!

The main construction comprises of a 12v IR lamp from a security camera along with a pi noir camera and adafruit screen all controlled by a raspberry pi (model 2B). I’ve added a couple of buttons to control the light, video record etc for use in handheld mode with the pi controlling the functions in automatic / trailcam mode.

Front of camera

Raspberry pi

I’ve used a model B raspberry pi 2 for this project. Originally I’d hoped to use a zero with a pimoroni explorer pHAT however I had trouble getting the screen to work with the zero and the explorer so reverted back to my test system – the pi2. My main concern was battery life but it doesn’t seem to be too much of an issue.


Rear of camera

The screen is an adafruit 3.5″ pitft plus bought from pimoroni. This has a restive touch screen incorporated which can be used to operate some of the functions – I use a spare pointer from a Nintendo DS which is fairly accurate.


The buttons are connected to a board which is in turn connected to the pi gpio pins via the 26way ribbon cable at the back of the screen as well as from the pads on the screen.

The rear of the touchscreen

I’ve since moved the red wire in the pic above as it sat on, & made connection to the usb port on the pi B.

Board 1

There are quite a few gpio controlled functions so I’ve used 2 boards all linked together with with JST connectors. It is possible to shrink most of the connections down to a single, more compact board however I wanted it to be modular and by construction skills weren’t up to it.

Board 2


The lamp needs to be as bright as possible so I’ve had to use 12v. Rather than having 2 power sources as before (1 for the light and one for the pi) I’ve gone for a single source and used a step down power supply for the pi. I’ve used a batt borg power converter bought from modmypi and it is excellent, working flawlessly.

The power itself is supplied via 10 x 1.2v rechargeable batteries which last for quite some time. I’ve also fitted a socket for a power supply to be attached, for when I’m testing it and if it is deployed near a socket. A simple switch selects if it runs from batteries of power supply.


The light is a super cheap replacement board from a security camera. I’ve disabled the LDR using blutak so it could be used if necessary. There’s also a connection of the filter on the board – presumably it auto selects if the filter is required – I’ve not used this as I wanted the filter to be controlled by the pi.

light with filter inside

The light is controlled via a simple switch on the body of the camera as well as via a relay for use in trailcam mode. I bought a relay from an ebay seller as it was cheaper and easier than making my own. The supplier said that he’d imported some for himself but had a few spare to sell so  I don’t know if he’s got any left. Excellent seller, though and really quickly delivered and good item.

(I had experimented with making my own board but managed to kill a pizero in the process so went for the safer option)


The filter is pretty much the same as used previously and controlled by a motor controller chip on board 2.

I’ve described it in more detail on my previous post here: Trailcam 5 I.R. Filter.

Software & Code

I’ve once again opted for the excellent pikrellcam with its built in motion detection. This has worked very well on my previous trailcam and it works perfectly when used in manual record mode.

The pi boots up in kiosk mode and displays a modified version of the pikrellcam web page – I’ve altered it to change the size of the image and add the touch buttons at the side. If the main image is clicked it reverts back to the normal pikrellcam page giving access to the additional functionality and media storage.

The simplified web page

It is worth noting that the web page will be deleted if pikrelcam updates, so I’ve had to live without updates for the time being. If it should need updating I’ll copy back the modified page after the update.

EDIT: Billw has provided a solution for the issue here

Finally, a python script runs in the background which provides the functionality for the buttons, this is started in the same way as the kiosk mode and calls a separate piece of code to run the motion detection when the button is pressed – described here

I’ve put the code on a separate page here. I’m no programmer however it seems to work.

Start / stop python script from python


We took it out for a walk in the dark a week or so ago and the results were better than expected:

First test:

These were taken when it was in the cardboard box and held together with elastic bands. The light has been improved since then as well.

A montage of several situations:

It’s got a range of about 40m showing movement with 20m and less giving reasonable detail.

The danger of looking at a screen rather than concentrating on where you’re going:

I’ll post up some more videos when I’ve experimented a bit more – I’m desperate to see if I can video a hare in the nearby fields.

Main youtube:


There is some glare on the lens from the lamp. Currently I’ve got an old toilet roll holder inside the light, this needs to be made more permanent and increased in length.

It could do with a new box that’s a bit more suitable for leaving outside.

I’ve got some new buttons to replace the current ones. They’re waterproof so I can use them in conjunction with a new, more robust housing for prolonged trailcam usage.

Being left handed, I’ve built it to be easier to use with the left hand in terms of both button position and weight distribution. Right handed people seem to find this hugely difficult to use so perhaps I could modify it to be ambidextrous.

I’d like to further tweak the python coding as there are a couple of areas that I’m not too happy with. Ultimately it needs a good few workouts in both handheld and trailcam modes to see what needs work.


element manufacturer supplier link
Screen adafruit Pimoroni×320-3-5-tft-touchscreen-for-raspberry-pi-pi-2-and-model-a-b
Proto boards adafruit modmypi
IR filter ebay  electronics_lee
IR lamp ebay xrst_511
Lamp relay ebay puretekuk
Power convertor – batt borg modmypi
JST connectors modmypi
buttons maplin maplin