The Raspberry Pi Batinator

11K7612


Intro: The Raspberry Pi Batinator

The Batinator is a portable Raspberry Pi that uses a PinoIR (No Infrared Filter) camera module to record video in the dark at 90 frames per second, 640x480 resolution. It features a 48 LED infrared illuminator on top and the power is provided by a re-purposed 12v rechargeable drill battery. I've recently become fascinated by the bats that visit our garden of an evening and built this to try and catch the little beauties on film.

Turns out the Batinator is also handy for recording lightning flashes, I should perhaps have called it the Storminator: Youtube video at: https://youtu.be/zEASwGeTgw8

In case you can't view the embedded video it's on YouTube at: https://www.youtube.com/watch?v=Ota2V3bVvAw with more at https://www.youtube.com/watch?v=Bd2L6NeaoOg

The (very straightforward) Python code is on GitHub at https://github.com/MisterEmm/Batinator

STEP 1: Bat Detection

We only moved into this house last August so it was really exciting when I first noticed the bats in the garden a few weeks ago. They're mainly visible at dusk, when they come out of their roost in the woods to feast on moths and other insects. There are seemingly rich pickings in our garden and you usually don't have to watch very long to see them, often flying in circles hoovering up whatever they can find.

Inspired to find out more I bought a bat detector kit from the local maplin, which was a fun bit of soldering and works really well. I then wondered if it might be possible to film them to get a closer look and hopefully even identify what species of bats were visiting! I had a spare Raspberry Pi 2 and was given a Pi NoIR (noir = no infrared filter) camera module for my birthday last year so thought I'd make use of it and see what happened.

STEP 2: The Code

I started by setting up the camera on the Pi, following instructions and a camera example from the MagPi Magazine, then turned to the internet to find other examples I could adapt for recording the video.

I found the perfect code on the Average Man Vs Raspberry Pi website, which was well documented and really easy to follow. I made a few changes to suit my needs, specifically to split the recorded video into 5 minute chunks - each 5 minutes takes 15 minutes to watch back because of the framerate!

The code I used is all available on GitHub - it's very straightforward!

STEP 3: First Light

I initially hoped to use a handful of infrared LEDs mounted on the Pi to illuminate the bats, so started hunting around in the workshop to see what I could find. I came across a broken security camera and soon had it apart, snipping the LEDs from the circuit board to leave as much "leg" as possible. I then soldered these to a perma-proto board, connected them to the Pi and gave it a test.

Looking through my phone's camera they were certainly working, so that evening I deployed the Pi in the garden, plugged into a power outlet in the shed and nestled in a convenient plant pot. After the 40 minutes was up I excitedly copied the footage over to my laptop for viewing and - nothing, not a sausage!

It was obvious that the illumination of the four salvaged LEDs wasn't nearly powerful enough, as the bats were probably at least a metre away from the Pi. Off I went to google in search of solutions!

STEP 4: More Power

I found a great article on raspberrypi-spy comparing the various options for IR illumination and decided to get an IR Illuminator - essentially a small spotlight stuffed with IR LEDs. The one I bought on ebay has 48 LEDs and is powered by 12 volts DC - it was literally the cheapest UK-stocked one on there at about £5 and arrived a couple of days later.

This was much more like it! I plugged it in alongside the Pi in the darkened workshop and ran a couple of test videos, shortening the recording time in the Batinator.py script but leaving it set to capture at 90fps.

Watching the test videos back was a case of good news/bad news - the illumination was fantastic, really good for several metres. The downside is that the video was constantly flickering, to the point of being unwatchable. I had a feeling I knew what the cause of this would be, the power supply of the new illuminator. My theory was that the flickering was reflecting the 50hz oscillations of the mains power, so I set up a test script to record 10 seconds of video at 90, 85, 80, 70, 60, 50 and 40 frames per second. Comparing the videos sure enough they all had the flickering effect apart from the 50fps one. This was a bit disappointing as I'd really wanted to push the frame rate to its limit.

I went back to the camera specifications article for inspiration and found that if the frame rate is lowered to 49fps then the capture resolution can be increased from 640x480 to 1296×730 - a compromise!

STEP 5: More Testing

Out went the camera the next night, back into its planter on the side of the shed and pointing across the garden.

As soon as I retreated back indoors I could see a bat circling around, so I was hopeful that this time I'd capture something good. 45 minutes later I started watching the footage back and although I'd caught a bug or two close to the camera the moving bat hadn't been illuminated at all.

I could see it on the film in silhouette as it wheeled around over the wall in perfect circles but it was obviously still too far away from the IR light.

The next night I decided to up my game, so instead of placing the camera near its power source in the shed I ran an extension lead out to the birdfeeder, which is almost in the middle of the garden and much closer to where I usually see the bats. I also deployed a secret weapon - the smelly sock! I'd seen on Springwatch a few weeks earlier that Martin Hughes-Games had attracted moths by hanging up socks soaked in a mixture of beer, wine and brown sugar - "Sugaring" it's called. I figured if I could attract moths near the camera then this would in turn attract the bats. Not very fair on the moths but there you go, I wouldn't be tempting them every night with my boozy hosiery. I had no success on the following nights (too cold and wet) but kept a stock of beer handy (for the moths of course) just in case.

STEP 6: Bat-tery Power

The difficulty in "deploying the batinator" of an evening was that it involved running an extension lead from the shed, plugging in the Pi and illuminator and then trying to align them towards where the bats might be - this would take 10-15 minutes and was a hassle to put away late at night. I decided that I wanted to go battery powered, so that starting the capture would be a simple as popping it out and pressing the "go" button.

I first thought of using a 12v battery for the illuminator and a separate 5v power bank for the Pi, but this felt like a clumsy solution, so I decided to go with a single 12v battery to power both. I was already exploring 12v power sources for another project, so decided to built a portable 12v/5v supply that was modular enough to be used for both purposes.

I began with an old 12v cordless drill (a very cheap one!) - I hacksawed through the handle just below the trigger, leaving a flat surface to fix a project box securely on top with cable ties. the 12v cable was clearly visible inside the chopped handle so I just added a connection block to simplify things.

Inside the project box I wired a DC plug that would connect to the illuminator's 12v input, and in parallel connected a standard 12v car power socket, drilling holes for them to poke through at the rear. This would allow me to plug in a USB adaptor to convert the 12v supply from the drill battery to a 5v 2.1a and 1a usb output. I then added in a master power switch to the box and before plugging in the precious Pi tested the USB output using an Adafruit USB Charger Doctor, it all looked good!

STEP 7: Behold the Batinator!

With the power all sorted I just needed to fit the Pi and illuminator to the base to make it nice and portable.

The illuminator came with a handy swivelling bracket so this was easy to bolt to the lid of the Pi case, and I lightly glued the camera module on top so that they would always be properly aligned. I did need to use a longer camera ribbon cable to make sure it wasn't over-stretched.

I knew I'd want to use the 12v/5v base with other projects so I needed to make the Pi case removeable - Lego turned out to be a convenient and perfect semi-permanent solution! I hot-glued a flat Lego base to the top of the power box, and another one to the base of the Pi case, fitting the two firmly together.

With all the bits clipped on the finished product really reminded me of the "-inators" created by hapless evil scientist Heinz Doofenshmirtz in the Phineas & Ferb cartoon, and so the Batinator was named! Learning from the fate of the other -inators I decided to omit a prominent "Self Destruct" button.

An unplanned benefit of using the 12v battery was that the 50hz flickering from the mains electricity was eliminated, so I could once again capture video at the full 90 frames per second. Now it was just a case of waiting for the weather to improve!

STEP 8: Finish & Footage

Typically the weather deteriorated as soon as the Batinator was ready, and it's only been on the last few warm evenings that I've been able to give it a proper test. You can see the early footage in the YouTube video - though there may be a moth or two included! Recording in the dark it's difficult to get an idea of scale, so sometimes it's hard to tell if something is small or just far away. A bat is pretty distinctive though!

I tried using various capture resolutions but the 90fps 640x480 is my favourite - anything faster and things become just a blur on the screen, albeit a 720p blur! The IR illuminator is effective up to about 2-3 metres, so to work with that and the VGA resolution the plan is to experiment placing the camera in different locations to get as close as possible to where the bats fly past. Or owls, UFOs, lightning, I'm not fussy. I hope to take it further afield in the coming weeks, maybe down the woods or on a bat walk at the local nature reserve.

Update 20/07/2016: Captured some brief lightning footage on the Batinator!

Update 24/07/2016: A few more bats and some moths!

The converted drill battery works really well, I try to have it fully charged before "putting the bat out" of an evening, but everything runs quite happily for over two hours. I've not let the battery run right down to zero while connected to the Pi as I imagine this isn't very good for it.

I've been using VLC to view back the captured .mp4 files and find this to be a solid option on both laptop and mobile. Editing the videos is straightforward in Windows Movie Maker, I'm now in the habit of watching back the files in VLC on fast forward, noting down the times of any on-screen "blips" to make the trimming easier later on.

The Batinator was great fun to build, and it's even more fun to use, I just love its simple reliability and quirky good looks. It's also the first portable Pi project I've attempted, which opens up loads of new possibilities I'll link more videos to this instructable as they (fingers crossed) get captured. Now excuse me while I watch the sky...

12 Comments

Neat project. May I suggest you try using an infrared heat lamp as your IR source? It will require being plugged in to a power outlet, but you can't match the intensity of the IR illumination you will get!
Thanks, I never thought of that! I am on a but of a quest to try different kinds of illumination! Happened to find this on the way home...

Some Led drivers work at frequencies lower than 1kHz and this produces flickering on high definition video. In fact, PWM frequency must be at least at 7kHz to be HD compatible.

That's good to know, thanks!

This is a neat project, but you should try with some normal lighting. You won't scare them away and you might be able to determine the species if you can get a real look at them. The reason most bats come out at night is pretty simple. It's when their food supply is most plentiful (for insectivorous bats anyway). At night, they also have less of a chance of becoming "dinner" to hawks, eagles and crows. A bat's eyes have roughly the same acuity as a person. At night, a bat is basically as "blind" as we are. So they don't use their eyes, they use echolocation. A standard light may actually attract bats because the light will attract insects. Around here (Illinois, US), it's not uncommon to see bats circling a street light, feasting on the moths and other bugs it attracts. I great you have an interest in bats. From what I've read, bats are kind of scarce in the UK being largely wiped out a long time ago. Experts have theorized that WNS (white nose syndrome) spread through much of the UK 100s of years ago almost completely killing them off. The only ones left have a natural resistance to WNS. And no matter where you are, bats are truly beneficial and need all the advocates they can get.

Really good and interesting thoughts, thank you! I meant to put out a torch the other night to attract the moths as you say - took me a while to dig one out with a 'normal' bulb (opinion seems split whether they like LEDs or not), I'll definitely give varied illumination a go, I read recently if there's a pool of light then they like to feed around the outside of it. With the IR light its almost like watching an underwater video, totally dark until something pops out, the local cat and a web-spinning spider close up have really made me jump recently. The bats are the stars though!

Interesting project. I've never thought of doing anything with the camera before but this looks like fun.

It was awesome fun to build and there are so many different camera examples online! Fingers crossed for an even better pi camera at some point in the future.
I'm just worried it's not eeeevillllll enough!
your video may seem blury at the higher frame rates but have you tried slowing that captured footage down? I'd bet you might get some interesting slow motion footage out of it
Thanks, I'll give it a go, it's one big experiment! Got a couple of bat clips last night, about to set it up quickly now as a thunderstorm is approaching! Would love to get a good shot of some lightning.