Sunday, 20 April 2014

Side-View, Raspberry-Pi powered bird counting bird box

As I mentioned in an earlierpost, I've been looking to setup a small bird nesting box with camera feed that can be viewed from any internet-enabled device (PC, tablet, phone).  While there are plenty of solutions out there to directly connect an analogue camera to a TV, there are no affordable compact off the shelf 'stream-across-the-web' (or home network options).  

My 'Mark I' box is based on the side view 'Odd-Box' design, variants of which are available commercially from various UK retailers.  This design is interesting as it gives a 'side-on' perspective, rather than the usual 'top-down' view from the traditional nest box with camera at the top.  I've added an entrance counter which should allow me to monitor coming & goings from the box.   

My side-view, Raspberry-Pi powered bird counting nest box

As described in an earlier post, I've taken advantage of the Raspberry Pi's flexibility to connect to a variety of devices, and have hooked it up to a webcam to stream live footage of an owl nesting box, which  is currently intermittently occupied by squirrels.
Bird Activity Counter
I've also incorporated two entrance hole infra-red beams that when used together should be able to detect entry and exit from the box.  This is based on the bird box project in Andrew Robinson and Mike Cook's Raspberry Pi projects book:

The final chapter ' Chapter 17 - The Techno-Bird Box, a Wildlife Monitor' describes a method of utilising the PiFace interface board with the Raspberry Pi to record entry and exits to the box.  This YouTube video shows the sort of thing that is possible.
Update May  4 2014:  Python scripts for this aspect of the project are described in this post
Box Construction
The wiring, IR illuminators and detectors are housed in the multi-layer plywood section on the LHS of this picture.

All wiring is goes via a terminal block to the PiFace interface board + Raspberry Pi.  The box is powered via power over ethernet (PoE) using a TP-LinkTL-POE200 PoE kit.  The camera is a Microsoft Lifecam cinema.   The box is linked into my home network, and can be viewed from any connected device as a motion jpeg stream.

Video streaming
The LifeCam is capable of 1280x720 video, but unfortunately the viewing angle is too wide, and there's a gain in frame rate if I drop it to 800x600.  At this resolution I can also zoom in, which isn't possible at the higher resolution using the LifeCam.  I'm using mjpeg_streamer to stream the video across my network, and can get a framerate approaching 20fps, but limit it to approx 12fps as this is still perfectly adequate.

View from each end of the box (not web-cam view)
I haven't gone for artificial light in the box, and have instead cut a window into the box lid and put a sheet of transparent acrylic over the lid.  This seems to give plenty of natural light, and we'll see if the skylight puts them off or not. 

For a future 'Mark II' box, I'm planning to use the Raspberry Pi camera board as its a good resolution, cheap and much more compact.

Motion detection
The Raspberry Pi is essentially a small computer running Raspbian, a version of Linux.  This is an open-source operating system that benefits from a wide community of open-source software (read = free).  I'm currently taking advantage of the Lifecam's facility to stream mjpeg natively, which puts very little load on the Pi.  Optionally, you can run a program called 'motion' which analyses a video stream for movement configured to record any detected activity.  I haven't used this, as a while ago I setup a PC running iCode's iCatcher Console software which does the same thing.  This is windows based, commercial software, which operates on a per-camera licensing basis, so there is a per-camera cost involved. I have maxed-out my available iCatcher per-camera licences at the moment, so may look at using motion for the next nest box / feeder / whatever build.  Using this software, I can capture any activity and export to a video file, for example this week has seen plenty of squirrel mating in my Owl nest box.

If you exclude the motion detection (which can be setup for free on the Pi), the cost for this build would be approx £100, which when you compare to how much the cost of a TV-only analogue kit would cost is very favourable.  The 'downside' is that you have to build & program this yourself, but there are plenty of guides out there to help with that.

Since we're not dealing with a battery or solar powered box, this had to be put up near a network point and power.  The advantage of a PoE setup is that I can run an ethernet cable a long distance from the house and send power and a data signal through it.  The TP-Link kit I've used allows a step down to either 12, 9 or 5V at the destination, so I've assumed that it must send a higher voltage down the wire.  My assumption is that since the step down occurs at the destination, there's no need to fiddle about with voltage drops if you planned to send 5V from the power source. 
To keep it simple, I'm mounting this one on the side of the house, and running ethernet cable through the wall.  My other similarly setup owl-come-squirrel box is set up exactly the same way, and is a good 150ft from the house.

This is a view from the lifecam camera with the box outside:

View from Bird box camera at 800x600 resolution

My main concern is that the electronics compartment gets a little warm, and I don't want to kill the Pi... hopefully being on North-East facing wall, it shouldn't get too hot.  The next version will incorporate some better ventilation.

I hope that I haven't left it too late putting this nest box up, but last season we have great tits nesting in May, so I'm ever hopeful!


  1. Great stuff!

    I've been considering box designs to give me side-on or angled views for BirdBox2015.

    The leaning-tower design has a number of advantages, compared to making just a very wide box:-
    -the nest will be built within the field of view of the camera, rather than just anywhere around the bottom of the box.
    -no need to fit a clear (glass/acrylic) window between camera section and nesting section.
    -less material (wood) required.

    My concern with "windows" to let in natural light are:-
    -Predators: I'd suggest you diffuse the light so predators cannot see what is going on inside. Bubble-wrap stuck to the inside face would be good, but will probably reduce the light too much.
    -Direct sun light: any window needs to be low enough to avoid direct sunlight when the sun is high in the sky (i.e. strong).

    At midday today, it's so dark & gloomy outside that I've had to turn my box lights on!

    Your POE choice looks great. The device delivers 5Volts up to 2Amps, so your Pi should give you rock solid operation. I was moving completely away from cabled boxes, but I'm now thinking I could use RaspberryPi + POE for my robin box, which is very close to our garage. The advantages include: it could be powered up all the time, and I should get full HD at 30fps streaming over the 100Mb/s wired connection (I'm currently limited to 640x480 @30fps until I can up the rate of my wifi from 54Mb/s).

    RaspberryPi temperature: my system monitors cpu temperature, and so far the max has been about 40'C (I'm also over-clocking the cpu @800MHz, so that increases the temp slightly). According to the clever people on the forum, the temp could reach 80'C+ without issue. So I don't think you need to worry about over heating, especially as the whole box will probably be in the shade for most of the day.

    Now, get that box screwed to the wall before its too late!

  2. All put up yesterday, just before a huge downpour, after which, we're still functioning - passed the rain test then! A quick check of temp gives 55 degrees in the day and 48 at night. I'm going to have a go with plotly to see if I can visualize temperatures using "vcgencmd measure_temp" in python. The box is only in direct sunlight first thing in the morning, so I'm not overly worried on that front.

    The window works well, The inside is viewable in natural light from 5:50am to 8pm (Mid April) - Caught a nice sunrise at 6:05. Since the box is at an angle, its not directly above the base of the nest 'site', however I might get some of that stuff that you can stick on bathroom windows to stop neighbours getting unwanted glimpses of you in the shower ;)

  3. Yes, rain and water ingress is a worry, but looks like you passed that test.

    The max temperature in my previous comment should have read 50'C (not 40) so yours is quite similar to mine. I suspect the difference may be due to cpu% utilisation. When I view mine its usually 25-30%, but it rises to 50% if I turn on the task manager, presumably because its another graphic for VNC to update.

    I've seen several Python code examples for the Pi which run very tight loops, driving the cpu to 100%. In my control program I only poll the box entrance sensor every 500ms. So the Pi gets an easy ride, although I probably miss the occasional turbo-charged great tit.

    Can't wait to see some video...even if only an arty sunrise!

  4. Yes, the in and out monitoring script as included in the book I linked to is much kinder to the Pi if I put in a time delay included in the loop as you suggest. CPU usage by Python dropped from 100% to approx 15%, which makes for a happier Pi, good suggestion :)

    The sunrise is really only just a red flash, no external camera I'm afraid. I did toy with the idea of running a webcam inside with an outside-facing RasPi camera, on the basis that I could get footage of the entry / approach / double as exterior security CCTV measure...., but endless tinkering = no mounted box.

  5. Thank you for your comment on my blog post about my Raspberry Pi powered Nest Box. I'm now making some tests with temperature and humidity sensors to be placed in my nest box next year.

    Interesting to read about your project. Your nest box looks great!

    Follow my project on this page: