Minimally invasive beekeeping with a Raspberry Pi

Extend Your Feelers

© Lead Image © writerfantast,

© Lead Image © writerfantast,

Author(s): , Author(s):

Beekeepers can get to know their colonies better without continuously disturbing the industrious insects. Using a Raspberry Pi and various sensors, two hobby beekeepers monitor the temperature and humidity of their hives, with plans to monitor their weight.

The winters in Germany's Sauerland region are long, but above all, changeable. Sometimes it snows in October, and sometimes you experience a spring-like 15°C (59°F) over Christmas. The beekeepers in the area are prepared for this and prepare their bees for the winter in the early autumn after the last honey harvest by feeding several liters of sugar solution into the hives, depending on the size of the bee colony. When the outside temperatures drop, the response is prompt: Lock up, install mouse gratings in front of the entrance, and meet again in April.

Because beekeepers do not normally open the hives during the winter months, they cannot know if the population is thriving. Inspired by the Hiveeyes Project [1] and the Open Hive Monitoring System [2], we planned our own monitoring solution for our colonies. As hobby beekeepers, we first want to observe the temperature (see the "Test Setup" box) but, later, also connect our own hive scale.

Test Setup

A Raspberry Pi 2 Model B (RPi2B) with Raspbian Stretch (based on Debian 9) was used, to which we connected a temperature and humidity sensor (DHT11). We also experimented with a DS18B20 temperature sensor and an active speaker connected to the RPi2B via a 40-pin GPIO extension board and a breadboard.

Connecting the DHT11 Sensor

The DHT11 digital temperature and humidity sensor is available for a few dollars. It supplies the temperature in degrees Celsius and the relative humidity as a percentage. In the first trial, we connected the sensor directly to the RPi2B. The Python_DHT sensor library [3] helps with the readout. After installing the packages build-essential and python3-dev, we checked out the sensor library from the GitHub repository and installed it on the computer:

$ git clone
$ cd Python_DHT
$ sudo python3 install

To use the library in your own Python scripts, you use import. For example, Listing 1 reads sensor data and outputs it to the console. A test run on the console shows that the sensor and RPi2B are working together:

Listing 1

01 import Python_DHT
03 sensor = Python_DHT.DHT11
04 pin = 4
05 humidity, temperature = Python_DHT.read_retry(sensor, pin)
06 print("dht temperature="+str(temperature)+",humidity="+str(humidity))
$ python3
dht temperature=17.0,humidity=49.0

After saving the script to /usr/local/bin, the database and the collector were the next steps.

Setting Up the Database

The InfluxData package source [4] contributes both the InfluxDB database [5] and the Telegraf collector [6], which are added to /etc/apt/sources.list.d/influxdb.list; then, we added the repository's GnuPG key:

$ curl -sL | sudo apt-key add -

After updating the package list (apt update) and importing the influxdb and telegraf packages, we configured the database to start automatically at boot time, initialized the server, and started the command-line client:

$ sudo systemctl enable influxdb
$ sudo systemctl start influxdb
$ sudo influx
Connected to http://localhost:8086 version 1.5.1
InfluxDB shell version: 1.5.1

When the client started, we created a new admin account and a new database named telegraf:

> exit

In the InfluxDB configuration file /etc/influxdb/influxdb.conf, you need to enable the web server under [http]:

  enabled = true
  bind-address = ":8086"

After restarting the service by typing

systemctl restart influxdb

the Telegraf configuration continues.

Well Acquired

The telegraf account must be a member of the gpio group for the collector to read values from the GPIO pin:

usermod -a -G gpio telegraf

The /etc/telegraf/telegraf.conf file contains the database information in the OUTPUT PLUGINS section:

  timeout = "5s"
  username = "admin"
  password = "****"

The INPUT PLUGINS area also has a space for your Python script, which will run once a minute:

    commands = ["python3 /usr/local/bin/"]
    interval ="60s"
    data_format = "influx"

If you want to check whether the communication between Telegraf and InfluxDB is working, you can launch the influx client. Listing 2 shows how we query the telegraf database on the test system.

Listing 2

Querying the Database

$ influx
Connected to http://localhost:8086 version 1.5.1
InfluxDB shell version: 1.5.1
> show databases
name: databases
> use telegraf
Using database telegraf
> show series
> select * from dht;
name: dht
time                host        humidity temperature
1522242851000000000 raspberrypi 54       19
1522242911000000000 raspberrypi 54       19
1522242971000000000 raspberrypi 53       19
1522243031000000000 raspberrypi 53       19


Grafana [7] visualizes the acquired data. The software supports numerous data sources, including InfluxDB databases. Because the official Raspbian repositories contain a relatively old Grafana version, we used a current package from GitHub [8].

The Grafana service also needs to be configured to launch automatically after boot with systemctl enable; the

systemctl start grafana-server

command calls the service, which users can reach from web interface port 3000 (username and password are admin). First, we used Add data source to add the telegraf database; then, we set up the dashboard to visualize the metrics (Figure 1).

Figure 1: The sensor measures temperatures between 8°C and 9°C (ca. 46°F and 48°F) at the upper edge of the lower hive frame shortly after 10am, when the RPi2B was hung in the hive.

We moved the RPi2B, at first provisionally protected with plastic bags and tape, into the beehive, which is located next to the house wall and can therefore use the existing wireless network (Figure 2).

Figure 2: The RPi2B is still in a temporary housing. A waterproof housing and a solar module for wireless power are on the shopping list.

To make room for the RPi2B and sensor, we took one slat out of the top floor of the two-frame hive. The DHT11 currently measures the temperature at the upper edge of the lower frame. At an outside temperature of 1°C (ca. 34°F), the average Easter weekend temperature was 8°C.

Close to the Bees

The temperatures are higher where the queen lives and where the bees breed (about 35°C, or 95°F). Other beekeepers have three or four sensors in the hives and measure the temperature at the entrance hole, under the lid, and in the lowest frame. You can check out the sensor results of the Hiveeyes project online [9].

With the information from a SunFounder tutorial [10], we experimented with a DS18B20 temperature sensor and a speaker module. To communicate through the GPIO extension board, we installed the Wiring Pi library [11], which provides the gpio tool (Figure 3).

Figure 3: The GPIO layouts.

The idea was to create a measuring device that emits an audible signal when a certain temperature is exceeded. Such a device could be interesting for transporting colonies of bees. If longer distances are planned, a transport grid on top of the hive ensures a sufficient air supply. For shorter distances, however, many beekeepers simply secure the hive with a strap.

When it gets too warm, the bees start flapping their wings to cool down, and when the hive is closed, everything heats up even more – the insects can produce such high temperatures that the combs and honey melt and the bees perish. A signal tone warns the beekeeper during transport and prevents the colonies from buzzing themselves to death while cooling the beehive.

Do Not Miscalculate!

A hive scale is planned for the summer to monitor the weight of the beehives. The beekeepers association in Nettetal, Germany, implemented such a project with an Arduino [12]; the data is presented by the Hiveeyes project. A scale is not only interesting in the summer to observe honey production, it can also be used in winter to better assess whether sufficient food is available. If it remains very cold for a long time, the bees will need more food – you can then see in time whether or not nutrition is becoming scarce.