Infrared Bird Nest Box Camera Configuration and Installation
I had been observing house sparrows since a few years. I observed their activities outside the nest but I had always been curious about their activities inside the nest
- How do they build the nest
- How many eggs do they lay in a clutch and how frequently
- How long does it take to hatch the eggs
- How do they keep the nest clean
- How do hatchlings spend their time in the nest
- And many more...
I had been thinking about installing a camera in the nest box since a year or more
In the process of searching for the right camera, I came across some options
It took me sometime and thought process to decide which camera to install
I decided to go with Raspberry Pi Zero 2 W H for the nest box camera. It is a perfect fit for my nestbox, easy to setup compared to the ESP32-CAM and easy to upgrade or extend if we need more capabilities in the future
What do we need for this nest box camera setup?
- Raspberry Pi Zero 2 W H (H indicates pre-soldered GPIO header)
- Raspberry PI Infrared IR Night Vision Camera Module
- Raspberry Pi Zero V1.3 Camera Cable (15cm)
- Raspberry Pi Zero protective case
- Raspberry Pi Pi3/Pi3B+ Micro USB 12.75W Power Supply
- Micro SD Card Reader
- SanDisk Ultra A1 Class 10 32GB Memory Card
- HDMI Female to Mini HDMI Male Adapter
- Micro USB OTG to USB 2.0 Adapter
- Infrared Light 3W for Raspberry Pi Camera
- Two 5mm 890nm IR LED
- Two 220ohm resistor
- Female to Female jumper cables
Setting Up The Pi
I have explained in detail how to setup Raspberry Pi Zero 2 W in this post
Customising the Pi
I believe you have setup your Pi and is now ready to configure the camera
We shall create another user to run and manage our bird nest box camera
We shall create a new user birdwatcher. Execute the below commands in the command terminal on your Pi
sudo adduser birdwatcher
sudo usermod -aG video birdwatcher
sudo usermod -aG render birdwatcher
sudo usermod -aG audio birdwatcher
sudo usermod -aG sudo birdwatcher
birdwatcher has now been added to the groups video, audio, render and sudo
Enabling RDP is a onetime process which you already completed when setting up the Pi. You will be able to RDP with this user and every other user you create here after
The next step is to prepare the Pi for installing the camera module
Installing the Camera Module
Setting up the camera module is straight foward
Pi Zero V1.3 Camera Cable has a broad end (1mm) and a narrow end (0.5mm)
Narrow end is connected to the CSI port on the Pi and broad end is connected to the camera module
Once connected and the Pi is powered on, the camera remains powered irrespective of whether it is recording or not
This camera can see IR light when illuminated with an IR source like an IR LED or bulb. It can also see in the day light. It does not have an auto cut IR filter that can block IR light during the day. So, during the day it can see light in the visible spectrum and IR spectrum. In the dark, if we bring an IR source near this camera, we will be able to see the surrounding objects, this is how it gets night vision
This camera module has two contact points each on either side of the lens. These contact points are positive and negative terminals with a potential difference of 3.3 Volts
As we discussed earlier, this camera module needs IR light to be able to see in the dark. There are three different ways to provide IR light, we shall discuss about these three configurations now
- IR Light Using 3W Infrared Light Source
- IR Light Using IR LEDs Powered by GPIO Pins
- IR Light Using IR LEDs Powered by Camera Module
In all the three configurations, the way camera module is connected to the Pi remains the same
Execute
birdwatcher@pizero:~ $ rpicam-hello --list-cameras
Available cameras
-----------------
0 : ov5647 [2592x1944 10-bit GBRG] (/base/soc/i2c0mux/i2c@1/ov5647@36)
Modes: 'SGBRG10_CSI2P' : 640x480 [58.92 fps - (16, 0)/2560x1920 crop]
1296x972 [46.34 fps - (0, 0)/2592x1944 crop]
1920x1080 [32.81 fps - (348, 434)/1928x1080 crop]
2592x1944 [15.63 fps - (0, 0)/2592x1944 crop]
If you are not able to see the camera, it indicates you have not connected the cable properly
The leads (golden) on the cable should always be facing the board as shown above, be it on the Pi or the Camera
IR Light Using 3W Infrared Light Source
In this configuration the source of IR light is the two 3W modules attached on either side of the camera module
These 3W LED modules are powered on as long as the Pi is powered. So they emit IR light as long as the Pi is running
One good thing about these modules is, they have a photosensitive resistor which cuts down the power to these modules in day light. So these modules do not emit IR light when they are in the open receiving day light
But when the modules are inside the nestbox which is relatively dark, these modules remain turned on always
These are 3W each drawing a power of 600 mA (max), so they produce some amount of heat. You can attach heat sinks on the back of the modules to dissipate heat
When illuminated with a single module, this is how the interior of the nest box looks like
The wavelength of IR light emmited by these modules is about 850nm, that is the reason we see a faint red light on the modules and also pictures appear faint red
You can either go with one module or two modules depending on your need. But keep in mind the amount of heat these modules generate and the power they draw
I installed only one module but later on decided not to go with these modules as it might not be suitable in all the seasons due to the heat they generate
This is how I mounted the Camera Module with IR LED Modules on top of the nest box
IR Light Using IR LEDs Powered by GPIO Pins
In this configuration the source of IR light is the two IR LEDs
These IR LEDs are powered by the GPIO pins
Before we go in to the details of the connection, let us understand about the GPIO pins
For this topic we will limit our discussion to the pins that provide power to the LEDs
Pins 2 and 4 provide 5v at 1.5A. Pins 1 and 17 provide 3.3v at 500mA
We cannot connect the IR LEDs directly to any of the above the GPIO pins. Doing so would result in burnout as the current from the 3v3 and 5v pins is too high. Maximum continuous forward current rating for IR LEDs is 100mA. For this project let us target the current output range at 20mA–50mA
To bring down the current output to the desired operating range we need a resistor
If we add a 220 ohm resistor at 5v pin, that would limit the current to 23mA
If we add a 150 ohm resistor at 3.3v pin, that would limit the current to 22mA
Select the right resistor depending on the voltage
Connect the long leg of the LED to the anode and short leg to the ground. Connecting the other way would not damage the LED as the voltage is low. The LED doesn't light up as it prevents the flow of current in the opposite direction
Should you connect the resistor on the long leg or the short leg of the LED?
It can be connected on any leg. Now you might have a question, the electrons are flowing from the 5v or 3.3v pin to the ground pin and connecting the resistor on the ground side or the short leg of the LED would not stop the rush of electrons flowing in to the LED causing the burnout
But the resistor does not behave that way, it shapes/restricts the flow of electrons from the origin to the end. So, the number of electrons entering the LED would remain the same irrespective of which leg of the LED we connect the resistor
I could not think of a better analogy than this
In the above picture, the bridge is similar to the resistor. The road leading to the bridge is the source of traffic, imagine the road to be one way. The observer in the checkpost on the other end of the bridge is similar to the LED
At the origin, the road leading to the bridge might be a six lane road with a lot of vehicles, but as the road approaches the narrow bridge it also becomes narrow allowing vehicles only in two lanes. Similarly the road leaving the bridge is also narrow with just two lanes. It might expand in to six lanes after some distance but near the bridge it is two lanes
The observer in the checkpost would see the same amount of traffic irrespective of the position of the checkpost, be it on the road leading to the bridge or leaving the bridge
One advantage of using GPIO pins to power the LEDs is that you can turn them on and off by writing a simple python script
# Run this script when you turn on the camera
from gpiozero import LED
from time import sleep
# GPIO 2 (BCM numbering)
led = LED(2)
led.on()
# Run this script when you turn off the camera
from gpiozero import LED
from time import sleep
# GPIO 2 (BCM numbering)
led = LED(2)
led.off()
IR Light Using IR LEDs Powered by Camera Module
In this configuration the source of IR light is the two IR LEDs
These IR LEDs are powered by the Camera Module and are always on if the Pi is powered on
We know the voltage at the contact points on the camera module is 3.3v
If we add a 150 ohm resistor, that would limit the current to 22mA
But I connected a 220 ohm resistor limiting the current to 15mA
When illuminated with two LEDs, this is how the interior of the nest box looks like
We can see the pictures in blue. It is not because the LEDs are encased in blue epoxy. It is because the sensor in this camera has mapped blue light for IR spectrum. Some sensors map grey
What you see inside are clay birds
The clarity is good enough with the illumination provided by the LEDs at 15mA current
I decided to go with this configuration as I don't have to deal with jumper cables. The reason for avoiding jumper cables is that they would clutter the box with a lot of wiring and I didn't have a way to properly conceal them inside
I also have a very limited time window to complete all this setup as the nest box is now empty and birds are not visiting the nest as it is winter. In a few more days they would start visiting
Operating the Camera and Streaming
Below are some
Command Description
--------------------------------
rpicam-hello Opens a live preview window for a specified duration
rpicam-still Captures high-resolution still images
rpicam-vid Records video to a specified output file
rpicam-raw Captures raw Bayer frames directly from the sensor
rpicam-jpeg Captures high-resolution JPEGs
Example
-------
rpicam-hello -t 5000 for a 5-second preview
rpicam-still -o test.jpg saves an image to test.jpg
rpicam-vid -t 10000 -o test.mp4 for 10 second video
rpicam-raw -o test.raw
rpicam-jpeg -o test.jpg
rpicam-vid --qt-preview -t 10000 -o test.mp4 for 10 second video with preview
Youtube Streaming
-----------------
rpicam-vid -n -t 0 --inline --width 1280 --height 720 --framerate 30
--bitrate 250k --codec libav --libav-format flv -o - | \
ffmpeg -f flv -i - -f s16le -i /dev/zero -c:v copy -c:a aac -ab 128k -g 60
-f flv rtmp://a.rtmp.youtube.com/live2/<your stream key>
This concludes the setup of Infrared Camera for Bird Nest Box
This camera setup can also be used for monitoring the activity of wildlife