Annabel and I got our prototype working for the bird box, and I ordered a cheap passive infra red (PIR) sensor for a couple of quid. I spent a bit of time wiring it up to the Pi’s GPIO pins and used the Raspberry Pi Spy’s excellent guide to work out how to trigger and respond to events. The first thing I played with was a small Python script that gave a little feedback on screen to what was happening but more importantly lit up a red LED when the PIR sensor detected motion. Its a great example of physical computing and a really good way to play with some programming. I was very pleased with myself when I made the LED light up when people walked into the room!
I bought an extra long cable for the Pi camera and tested it out. Annabel and I cut some wires the same lengths as the camera cable to wire up the sensor and LED, soldered some female breadboard type connectors to the ends and hooked them up. We covered the wires in a length of heat shrink tubing and shrank it down.
I modified an existing mount for a PIR sensor from Thingiverse on Tinkercad so we could mount the sensor onto the inside ceiling of the bird box. I also modified and existing CAD plan for a mount for the Pi’s camera, and added some sloping supports so that the camera would be pointing directly downwards from the sloping ceiling (I needed a bit of old school trigonometry here). I 3D printed these parts, checked their fit and we mounted the camera and the sensor to the ceiling. We played with the focus a little on the Pi camera and just taped and screwed the infrared LED to the bird box ceiling and checked that it roughly illuminated the right region.
We wired up the parts and the Pi and checked again that it all worked ok, screwed down the roof of the bird box and sealed the edge with the cables passing in and out with some silicone bathroom sealant to help keep the electronics dry and the box weatherproof.
Annabel chose a big L mount plate from B&Q and we screwed that to the brick wall with suitable masonry screws and rawlplugs and then placed the bird box and screwed that to the plate too. I’d said that I thought the plate would be a bit of overkill because of its size but once in position I think she chose the perfect size.
I 3D printed a case for the Pi, fitted the Pi and the wires into it and passed the cables through a nearby window into the utility room, sticking the Pi up on the wall inside. It’s connected to the network by WiFi, and I had problems with it losing connection because of a power saving mode. I found out how to switch that off and now it works very reliably and I can access the Pi by SSH.
The Python program detects movement inside the bird box from the PIR sensor, which triggers raspistill to take a photo and name it by date and time, and then post it to Twitter. It seemed obvious to get a bird box to tweet, and initially it was tweeting to my @samuelwebster account. We had some immediate interest from the local blue tits on New Year’s Day and the camera kept taking photos of a blank box until we got this:
Something entered the TweetyPi bird box on 2015-01-01 09:35:45.395517 pic.twitter.com/UKKu0QWax0
— Sam Webster (@samuelwebster) January 1, 2015
The bird box was then very quiet until late March, when we noticed the entrance hole had been pecked away at. Sure enough after fixing the wifi drop outs we saw a very busy bird box and I had to set up a Twitter account for the bird box itself @tweetypibirdbox to avoid flooding my Twitter followers’ accounts.
The resident blue tit did something in the TweetyPi bird box on 2015-04-14 12:54:15.854721 pic.twitter.com/RPc20YoCVT
— tweetypi (@tweetypibirdbox) April 14, 2015
Since then we’ve been watching a female blue tit build her nest, and occasional visits from at least one other blue tit and a large bumble bee. Sometimes she roosts in the box, sometimes she sleeps elsewhere. The triggered Twitter method has proved to be really good – we can see when she enters and leaves the box, we can watch the nest grow and have a collection of all the photos so far (almost 1000 today), and we can see when interesting or unusual things happen. We would probably miss many of these if we used a live vide feed right now, but we may switch to that later. It’s also a great way to share photos of what’s going on, and it’s an easy way for interested people (and us) to check in on the box and see what’s been happening.
The resident blue tit did something in the TweetyPi bird box on 2015-04-08 03:00:10.869961 pic.twitter.com/dI1Xua6oUJ
— tweetypi (@tweetypibirdbox) April 8, 2015
This project has already been a great success, whether or not she lays eggs in the box. Everything is working robustly now (fingers crossed) and we get an intimate view of part of the life of a small bird. The kids love it, it was a fun project to work on, and we all learnt something. I think we’re going to learn a lot more before this is finished.
The resident blue tit did something in the TweetyPi bird box on 2015-04-14 13:24:01.227468 pic.twitter.com/L2QPzEFQxP
— tweetypi (@tweetypibirdbox) April 14, 2015