Introduction: The Raspberry Pi Batinator

About: I love the design and ambition of vintage technology, and the usability and potential of new - my passion is bringing the two together.

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:

In case you can't view the embedded video it's on YouTube at: with more at

The (very straightforward) Python code is on GitHub at

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 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...