Lessons from a life of startups, coding, countryside, and kids
I started with a low-tech footprint tunnel to get proof of our local hedgehogs but that was never going to be enough. I had a Raspberry Pi sitting in a drawer that wasn’t getting much love so, after a little googling a Raspberry Pi Camera Trap, aka a ‘PiTrap’, was born.
The idea is to put a Raspberry Pi in a waterproof enclosure, use the NoIR picam (which let’s in infra-red light) and use a cheap IR lamp to light the scene. Then we can use the
motion application to take photos / videos only when there’s movement in the scene
The Drybox was probably the most expensive part of this setup but you can probably hack together a cheaper alternative. It’s pretty neat though because I can put all the electronics safely in there and the picam sits neatly under the lid sheltered from any rain. Having said that, I don’t use it if I know we’re expecting heavy rain.
I just grabbed a cheap IR lamp from eBay for about €6. It doesn’t come with a power source though so you’ll need to find a suitable one. I used an old power supply from a battery charger that had the requisite 12V/1W and appropriate connector.
I found that the flat camera cable fitted perfectly through the Drybox slot and I just mounted the picam under the lid with some Blu-tack. If you have a longer cable you could mount the camera in a different position. Then you can position the box near some food or water. I’ve even started mounting it on a fence.
Next, we need to make the hardware do something. I’ll assume you have Raspian already installed (if not, do it now)
First, we need to install
motion but the default motion package isn’t compatible with the Raspberry Pi camera. Install the dependancies:
sudo apt-get install -y libjpeg62 libjpeg62-dev libavformat53 libavformat-dev libavcodec53 libavcodec-dev libavutil51 libavutil-dev libc6-dev zlib1g-dev libmysqlclient18 libmysqlclient-dev libpq5 libpq-dev
Then grab the patched motion app from here
wget https://www.dropbox.com/s/xdfcxm5hu71s97d/motion-mmal.tar.gz tar zxvf motion-mmal.tar.gz
You can run it like this by supplying a configuration file
./motion -n -c motion-mmalcam.conf
The configuration file that I use is here.
Here’s a couple of things that I changed:
threshold 10000. I made it less sensitive (previous it would capture flies and slugs moving in the distance!). You can try adjusting this number though
ffmpeg_output_movies on. I turned on video recording
ffmpeg_video_codec msmpeg4. I changed the video encoding by trial & error and this one seemed to work for me when playing back in VLC
Next we need to make motion auto-start when the pi is turned on.
If everything is working correctly, operation is as simple as plugging it in and walking away. Getting the images off is as simple as using rsync or scp. The IR camera gives a distinct ‘pinkish’ hue in daylight so it’s probably best just to convert them to Black & White.
And there it is again
Sometimes it can be difficult to figure out if the motion capture is really working because it can be very sensitive. I found it helpful to turn on
locate_motion_mode and set
locate_motion_style redbox so that a line will be drawn around the area of movement.