This snake is my bees’ best friend

pascal boudalier
7 min readMay 11, 2021

--

It will tell you if your hives are making honey

It all started several years ago with an old dream: to have my own hives and make my own honey.

I took training (it’s a trade), and had 3 hives for a couple of years. My record is 50kg of honey with one hive. Unfortunately, last spring, with COVID, I could not take good care of them and I lost two.

This year, I decided to reboot this project, with a small plus: a connected bee hives.

I know there are several projects out there, even commercial offerings but it is not a reason not to build my own. Commercial products are very expensive, and I wanted to tackle the difficult aspect of weight measurement which is not always included in DIY projects.

How Beehives behave

As the bee colony grows in population and bees brings in pollen and nectar to *store* it as food reserve, the hive’s weight increases. Conversely, if the nutriment intake slows down and the hive starts to *consume* its reserve, the weight will stall or decrease.

If the weather is good and the weight does not increase after a while, it may be the sign of a problem. Maybe the queen is dead, maybe there are too many parasites in the hive, maybe a small animal broke inside, maybe the Asian hornet is present and attacking bees ..

And no matter what the weather is, if the weight starts to decrease, it means the bees are eating the honey reserve and it is time to feed them with a mixture of sugar and water ..

All in all, the weight is a very good indicator of the hive’s health and of the amount of honey available. So let’s build a connected bee scale.

My DIY solution

My DIY solution is based on an ESP32 microcontroller, MicroPython and a couple of sensors.

It is obviously solar powered, as hives are typically not grid connected.

It is obviously connected, as hives are typically not in an area that you want to wander about (even if bees are not aggressive as long as you don’t aggress them)

It is interesting to record the weather conditions and try to correlate them to the hives’ heath. Therefore I included luminosity, temperature and barometric pressure measurement.

— —

For examples of other projects based on ESP microcontrollers and MicroPython, I suggest you to read : Enlighten your garden with MicroPython , The New York Times on Epaper, every morning , How much solar hot water do I have ?, A Python Will Keep Your Fridge Cool

— —

The system consists in :

  • Lolin D32 ESP 32 microcontroller
  • HX711 load cell sensor (more on that later)
  • TSL 2561 Lux (luminosity) sensor, BME280 (temperature and barometric pressure) sensor, and MAX 1703 (LiPo State Of Charge SOC) sensor
  • A small solar panel, battery charger and LiPo battery
Hardware Design

The ESP32 has built-in Wi-Fi and communicates with a smartphone application using the Blynk framework. (see also This computer will run forever to get more details on the Blynk framework). Essentially, Blynk allows to design a user interface application on Android or iOS, without any code, just by assembling widgets.

The whole system is powered by a small solar panel which charges a LiPo battery. A charge sensor is used to measure the battery state of charge ( SOC, ranging from 0 to 100%).

All sensors’ values (weight, lux, temperature, pressure, SOC) are sent periodically to my smartphone.

The smartphone application

Several techniques are used to minimize energy consumption, which is critical for battery operated devices:

  • ESP32 deep sleep mode. The ESP32 starts, reads all sensors, sends those values thru Wi-Fi to my smartphone, and then goes to deep sleep for the next 15 minutes, after which the cycle restarts. While in deep sleep, the ESP32 almost does not draw any power from the battery.
  • The sensors themselves are powered by the ESP32. So while the ESP32 deep sleeps, those sensors are powered off as well.

Weight measurement

Load cells are used to measure forces (and ergo weights). A load cell is a piece of metal on which a strain gauge is glued. A strain gauge is simply a piece of foil whose resistance value (in ohm) will vary when it is compressed or extended. When a force is applied to the cell, the metal flexes a bit, the strain gauge flexes as well and its resistance varies (a tiny ,tiny bit). This change can be measured.

A strain gauge
A single load cell. The piece in the middle receives the weight and flexes a bit.

A Wheatstone bridge is used to measure the small variation in resistance. Typically, such a bridge connects 4 load cells (by the way, a 4-cell Wheatstone bridge is exactly what you have in your bathroom scale)

A 4-cell Wheatstone bridge — Get your wiring right !
4 load cells in a Wheatstone bridge configuration. 4 wires connect to the HX711 which amplifies the signal and delivers the value to the ESP32 microcontroller. Each cell is rated for 50kg.
Debugging on the living room table. The piece hanging is the Lux sensor
Ready for real live testing. An Ikea kitchen box is used as waterproofed enclosure
Endurance testing. The table is also used for breakfast. The stuff on the right is This computer will run forever

So what

From my experience, the weight is not 100% accurate. I guess it has to do with the quality of my cabling (rat nest). But plus or minus 100 grams is not an issue (an hive is ten’s of kilograms). Unlike for a bathroom scale (specially if one is trying to loose weight), I am more interested in the trend than in the absolute value, so this setting is more than adequate for the purpose.

Note that with 4 cells my scale can measure up to 200kg (4x50kg). For other applications, it exists more precise cells which can measure with gram precision.

At the end of summer, when time comes to harvest honey, I’ll publish an update to this post, with my honey season history. Stay tuned !!!!

In the meantime, I wish you a sky of honey

— — Do not cross this line if you are not interested in details — —

Beside energy consumption, special consideration is needed for systems that are designed to stay out there, untouched for days or months:

  • Robustness: a watchdog is implemented as a separate MicroPython thread (yes, you get multi threading on a 3$ microcontroller), which forces deep sleep after 60 seconds, no matter what. This covers possible loops, bugs ..etc.. Without a watchdog, the program would just stop, and sit idle, consuming power. A push notification is sent to my smartphone when the watchdog pops.
  • Remote update: A button in the smartphone application is used to tell the ESP32 to not go to deep sleep, but instead to initiate MicroPython’s web REPL (Read Evaluate Process Loop). This allows interacting with the system, in particular updating the MicroPython application remotely via Wi-Fi, with no need of an USB connection between a desktop and the ESP32.
  • Operation statistics: the application records the status of sensor readings (ok or failed), the number of failures since the last hard reset, and the number of times the watchdog popped. Those statistics are stored in a specific RAM area of the ESP32, known as RTC (real time clock) memory. This memory is maintained during deep sleep while the rest of the RAM is wiped out. Those statistics are sent periodically to my smartphone application. Note that there are no reasons for a sensor reading to fail. If it does, this is most likely a cable getting loose.
  • Visual clues: two leds are used to provide visual clues on what is happening. Is sensor reading OK ? can I connect to WiFi ? to the Blynk server ? etc. As my enclosure is made of glass, I can figure out what is happening by looking at the box connected to the hives.
  • Sensor data cleansing: The MicroPython application sorts out abnormal sensor readings that can create operational problems. For example, if two consecutive weight measurements are more than 1kg apart, this is considered suspect and ignored . Another example is to ignore some lux sensor errors ( e.g. at noon, a sensor, pointing to the sky, may get saturated and generate an error ) . Note that another workaround is to smartly orientate the lux sensor …
  • Persistent logging: (version 2.0). Run time errors are logged in a tiny file system. A button is added to the GUI, to send those log to the terminal. So it is possible to view remotely what happen in previous deep sleep cycles.

So , was crossing the line worthwhile ?

--

--

pascal boudalier
pascal boudalier

Written by pascal boudalier

Tinkering with Raspberry PI, ESP32, RiscV, Solar, LifePo4, IoT, Zigbee, energy harvesting, Python, MicroPython, Keras, Tensorflow, tflite, TPU. Ex Intel and HP

Responses (1)