This snake is my bees’ best friend

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.

My DIY solution

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

  • 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 smartphone application
  • 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 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.

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



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
pascal boudalier

pascal boudalier

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