A birdbox camera based on a Raspberry Pi Zero.
We have a birdbox on the side of the house and thought that it would be interesting to be able to see which birds were using it, and possibly also see if chicks are raised there.
Here’s the kind of video that we get back (with the default settings).
For the camera system, I’ve used a Raspberry Pi Zero W with a Noir camera (their standard camera with the IR cut filter removed). Illumination is a couple of 940nm IR LEDs that are from Adafruit. To control them, I’ve designed a simple PCB that uses a FAN5333B LED driver circuit. This will control the current that the LEDs draw regardless of what temperature the box gets to and will allow their brightness to be controlled with a signal from the Raspberry Pi, including turning them off to prevent wasting (more) electricity.
In addition to the LED driver circuit, there is a DS18b20 temperature sensor on the Pi board to monitor the temperature in the enclosure. Just because. I soldered the sensor directly to the header connections on the Pi since space is limited, and soldered a 1206 surface-mount 10K resistor across the 3v3 and ~DQ lines to provide the pullup that it needs to work properly.
Getting the Raspberry Pi working
The instructions on the motioneye wiki don’t work for current pi as of 25 Oct 2020. I followed the instructions here: [Link to pimpingthepenguin.com] (https://www.pimpingthepenguin.com/2020/06/raspberry-pi-zero-setup-for-motion-eye).
which are based on the installation instructions on the motioneye wiki here [link to the motioneye GitHub page] (https://github.com/ccrisan/motioneye/wiki/Install-On-Raspbian).
In summary, you need to use:
apt install python-pip python-dev libssl-dev libcurl4-openssl-dev libjpeg-dev zlib1g-dev python-pil instead of
apt install python-pip python-dev libssl-dev libcurl4-openssl-dev libjpeg-dev libz-dev as given in the motioneye install instructions.
This gets the code to run, but it doesn’t connect to the camera properly. Also note that python2 is no longer supported on Raspbian, and python 3.7 is the default. This means that you need to issue
pip2 install motion so that it’s explicitly installed on python 2.x on your system.
Once you’ve followed all the instructions, you should be able to log in to the motioneye interface using your web browser and add a camera. I found that the camera did initially not work. The issue with the camera was that the
/dev/video10 device was chosen instead of video0, which is where the camera appeared on this pi. Edit
/etc/motion/camera-1.conf to change the camera location to the correct one. Restart the motioneye server and it should work.
I purchased a wooden bird box from a local DIY store branded as ‘Peckish’. For the Raspberry Pi, I designed a simple enclosure that fits under the roof of the birdbox and printed it out in black PLA. The enclosure has a clip detail for the LED driver board, and mounting screws for the Raspberry Pi.
The LEDs are mounted either side of the Pi, and are pushed into place. A simple clip provides some strain relief on the power cable, which passes through a small hole at the font of the base. The lid itself is held on with a pair of M3 screws and I tapped a thread into the mating part to hold the screws. The Pi is held on four M2.5 screws which are screwed into tapped holes in the lid piece.
The Pi fits into the base of the enclosure, which is held to the roof of the box with two screws. I sprayed the enclosure, and all of the electronics inside it with a conformal coating to try to keep moisture out.
Once the enclosure was assembled, I fitted it to the inside of the roof of the enclosure, and then protected everything with a small piece of roofing felt that we had left over from the last time the shed roof was repaired. This was heated using a hot air gun to get it to bend over the edges of the roof, and held in place with some small clout nails.
Power is supplied from a 5V, 15W supply that is mounted on the wall in the garage. I used a 1.5mm^2 core cable to minimise voltage drop from the internal cable resistance. At the top end, the cable is fed into the bird box, and is terminated in some heatshrink packed with silicone to keep everything dry. The final entry into the camera enclosure is done through smaller gauge wire that’s soldered to the large cable.
Controlling the LED
The LED illuminators are controlled with a GPIO pin on the raspberry pi. When it’s high, the LEDs are on, and when it’s low the LEDs are off. This means that they can be controlled remotely using software. I wrote some very very simple python code to turn the LED on for 25 seconds when motion is detected in the box. This means that the lights are off until something comes to have a look and then they’re turned on for the duration of the video recording (which itself is set to 30s).
#!/usr/bin/python import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) #Which GPIO addressing method to use. GPIO.setup(12, GPIO.OUT, initial=GPIO.HIGH) #Pin we're going to control GPIO.output(12, True) #On for 25s time.sleep(25) GPIO.output(12, False) #Then off again GPIO.cleanup()
To make sure that the LED for the camera and activity on the Raspberry Pi are switched off to prevent disturbing the birds, add the following to the end of /boot/config.txt (you’ll need to be an admin on the pi):
#Disabling LEDs on the system to make it dark disable_camera_led=1 dtparam=act_led_trigger=none dtparam=act_led_activelow=on
The motion interface allows lots of settings to be adjusted. Until we’ve got nesting birds in the box, I set it up to be motion-activated and to record a 30 second clip whenever something moves in the box. Motion is able to detect and take-care of changes in ambient lighting, so dawn doesn’t cause images to be collected. At the same time as recording is started, I call a web hook to ifttt.com which fires a notification on my phone using the maker channel, and also the python script that turns on the LEDs to better-illuminate the bird in the box.
This has been an interesting little project, and one that has used a variety of skills from CAD, electronics design, 3D printing, electronics assembly, programming and setting up a little Linux machine. I’m looking forward to seeing the baby birds.