The Timelapse Beehive

I’ve wanted to keep bees for 20 years, and I’m finally getting round to doing it. There’s a lot of nonsense going around about how it’s a new middle-class fad, but I recently dug this book out. It’s called the Golden Throng and it was printed in the 1940s.

It was given to me by my great uncle Ronald, who was a beekeeer, in 1995 and in the front I found an inscription which clearly indicates that I wanted to do it. In it he quoted

‘the advice given to me, by the old beekeeper who started me off, by giving me one of his hives, in his old Cheshire manner of speech :-

‘Remember that bees does nothing invariably”

There’s my proof. It may be a fad, but I’ve been building up to it. So I’m getting started with bee-keeping.

What

When you encounter a bee in the wild, you can hear how it sounds. It’s probably flying, or buzzing to warn you that it has a sting and could totally take you. But it’s one bee on its own.

The beehive is an extraordinary macro-organism. It’s a huge co-operative mass of animals all doing their own thing, but to the same end. But they’re not just co-operating.

They’re taking group decisions as a whole, like whether another queen should be produced, or whether to swarm, or if the hive is too hot or too cold and needs air conditioning.

I thought the sound of a beehive might be a good insight into some of the processes going on.

You can hear individual bees that you meet, you can hear the inside of a hive when you open it to inspect it, but behind closed doors, when no-one’s looking or listening, how do they sound?

Bees are some of the most studied animals in the world, although I’m not sure if that would be true if you divided that per capita. Recording bees isn’t something new. I know someone who knew someone who was recording beehives in the 1950s. I found a couple of projects online, but they seemed a bit over-complicated, and academic, and not really suitable.

So I decided to make my own.

What exactly did I decide to make?

I could have stuck a microphone in a hive and pressed record. No doubt I would have got : you’re ahead of me here : a recording of some buzzing. That would be an interesting one-off, but it wouldn’t really tell me much except that bees don’t stop buzzing once they go indoors.

What would be interesting to do would be to compare how they sound during the day to how they sound during the night. Or how they sound in the summer compared to the winter.

So I decided that I wanted something to take small recordings on a timer, then splice them together to form a time-lapse.

To do this I needed to make something. Some kind of device…

Why?

A bee-keeper needs to know his bees. They’re not just a box at the bottom of the garden. For this reason a beekeeper has a veil and smoker and undertakes the ritual of the opening of the hive for inspection.

That’s me, behind the camera taking the photo.

Of course there are some Americans who don’t hold with all this protective stuff and would rather do it wearing as little as possible.

The purpose of opening the hive is to know exactly what’s going on. A bee-keeper should know, at all times, if the queen is laying eggs, if they’re healthy, how many there are, if the bees have enough food and elbow room, if they’re suffering from disease, and so on. Adding an extra bit of information is surely a good thing.

As you open the hive, the sound the bees make constantly changes. They might be angry, confused, or just fed up that you’re taking so long and they’re getting cold. The constant change in the volume and pitch of the collective hum is, like most things about bees, completely magical.

A timelapse over the course of a day might show a daily cycle of something. Perhaps they get cold at night and need to shiver to keep warm. Perhaps they get to warm in the day and need to fan to keep cool.

A timelapse over a year might show that they don’t do much over winter. Or it might show that they’re very busy keeping warm. It’s a very bad idea to open a hive and look inside when it’s cold, but if a microphone’s installed, I can listen to them any time.

A timelapse over the course of a month might show that they take bank-holidays off.

Where do you put a microphone in a beehive?

There is something magical about bees. One of the magical things is the ‘bee space’. It’s a measurement of approximately 7mm, the width of a bee. Bees like everything to be tidy and connected. They want to be able to crawl between things, work on the comb back-to-back, and for all holes they can’t crawl through to be sealed up. If a gap is smaller than the bee space, they will fill it up with propolis, which is a sticky substance made from resin. If a gap is larger than the bee space, they will fill it with wax comb. Of course, it’s more complicated than that.

All modern hives are made with the bee-gap in mind. They are very carefully engineered so they can be taken apart and the frames removed, but the bees won’t try to glue anything up. So there isn’t actually much space to put extra objects.

A hive is made of a number of boxes. In each box hang about 10 frames, which the bees make comb on. The brood box is at the bottom, where the queen lays eggs and the workers raise them. On top of this are supers, which are smaller, and that’s where the beekeeper would really rather the bees put the honey. To keep the queen from laying eggs in the supers, a queen excluder is placed between the brood box and the supers. It’s a grid of wires that workers can get through but the queen can’t.

The queen excluder provides a useful space to connect things to, and is right in the centre of the hive. This is all very experimental, but I think the queen excluder is going to be the best place.

How do you put a microphone in a beehive?

You can get absolutely tiny electret microphones these days. I started by butchering a mobile phone earphone and microphone set. I immediately regretted it, as the mic is smaller than a match head.

I eventually managed to solder it onto some kynar wire, and later copper winding wire.

How do you record?

My hive is near home, but not that near. I needed something that could operate off the grid, without mains power.

The obvious solution is a Raspberry Pi. A bit of fishing around shows that a Pi uses between 0.2 amps and 1 amp. Which is only a few days from a massive car battery, which then has to be recharged. Plus it doesn’t have a sound card built-in, or wireless networking, so extras need buying.

So that’s a No to the Raspberry Pi.

My criteria were:

must have a microphone input

must be small

must run off a small battery

must be able to charge from a solar panel

must have some kind of wireless networking

The answer was an Android device.

I had a Nexus 7 with a slightly dodgy screen lying around, so I used that.

So my setup looks like this:

Microphone, solar panel, tablet. Simple. Every week or so I plan to take the device back home, upload over wireless.

There is a thoroughly discredited paper saying that mobile phone signals can affect bee navigation. Discredited perhaps, but while it would have been great to use a mobile phone and have automatic uploads over the air, I didn’t want to risk it. So I’m using bog standard wireless, and taking the tablet home to upload the sounds at periodic intervals.

I started my experiment! I placed the microphone in the hive …

… and waited.

Writing an Android app

I needed an app that could:

take a high quality sound recording every n minutes

store it

upload it to a web service

I’ve never written an Android app, and haven’t written a line of Java for five years. But I can honestly say that the Android API and SDK is absolutely brilliant.

The debugger is excellent. And Java’s not as bad as I remember.

It took me about weekend to learn the relevant bits of the Android SDK and get the basic app working, another one to iron out the bugs, and a weekend to cobble together the server side.

Problems

Timing

Writing code for Android is an exercise in humility. Most programmers’ attitude is ‘I write the code, the computer runs it, and I’ll do my best to make it CPU and memory efficient’.

With Android you declare your intent to the runtime. ‘I intend this code to run. Would you mind?‘. Android will probably run it, but there are no guarantees, and the battery life comes first. If during execution the battry suddenly runs out, all bets are off.

There was a precise alarm service available in an earlier API but it’s been deprecated now. That means that you can specify when a thing will happen, to the millisecond, but Android will decide when to do it.

I’ve not actually correlated exactly what the reallity of the sound recordings were, but it means that recordings are ‘about n minutes’, not ‘every n minutes precisely’.

Recording Audio

There’s a great class called MediaRecorder. You tell it to start recording, give it a callback method and it does its thing. Easy.

Unfortunately its thing sounds awful. It only records compressed autio at very low quality, doesn’t have raw or even mp3 formats and is basically useless. I don’t know why they bothered.

There’s a class called AudioRecorder. You supply a buffer and say ‘go’ and it fills the buffer with 16-bit integers and calls your callback when it’s full. Writing this stream of integers to a file results in most of a WAV file, but not the headers.

I had to find documentation on the WAV file format and write the appropriate headers myself, including the bitrate, size of file, etc.

And of course it wasn’t right first time. There’s a great program called SoX which, amongst other things, fixed my headers. I then had to diff the fixed and broken files to find out which bytes were wrong.

Good old fashioned fun.

Recording bees

You may think that recording audio is the same as recording bees. You’d be wrong. Even with AudioRecord, the automatic volume adjustment and other automatic processing things meant that after 2 seconds of recording the sound of the buzzing was filtered out. The recording system very helpfully identifies an annoying buzz and gets rid of it.

I found a way round this (use the VOICE_RECOGNITION source) but it wasn’t obvious.

Server side

There’s no point doing everything in the Android app. After all, it’s only there to harvest recordings. I used Clojure to write the server, becuase that’s what I everything with these days. It’s not massively complicated, just storing recordings and splicing them.

How do you produce a timelapse?

There’s a great program called SoX. It’s a general purpose sound file tool, and it’s great for trimming, splicing and producing spectrograms.

I want to take regular recordings, but play back timelapses on different timescales. Also, because of the approximate alarm situation, I didn’t have exactly timed samples.

So I stored the recordings with the time they actually happened and then choose the nearest neighbour.

For example, if I have 24 hours recording every 5 minutes and I want to create a timelapse taken from every 18 minutes:

So what happens when you put a microphone in a beehive?

1 : nibbling bees

I read somewhere that bees will eat paper voraciously. Here’s how my probe came out after about 4 hours. Compared to a new microphone on the left.

I’ll need to do a bit more R&D.

2 : Sodding birds

I love birds, but that’s not what I was here to do. In almost every ten-second recording, taken every 15 minutes, there’s birdsong. I think I’ll try and get the microphone further into the middle of the hive.

What does it sound like?

These are very early days. Here’s a short time-lapse taken over four hours. Here’s a spectrogram, which represents the frequencies present in the sound. Look near the very bottom (under 1khz) for the bees. You can see the chattering of the birds at about 30 seconds, about 2 kHz.

Early days.

I’m just getting started with my bees and my time-lapse beehive. This is early days, where ‘days’ means literally ‘days’. I hope to have more recordings in the coming weeks.