English (en) | Change Language
By: Andrew Lotze
Published: 2022-07-01

Here Andrew Lotze shares his experience with microcontrollers in conjunction with BeerSheba Project work in Senegal. His thoughts are in reference to the EDN 155 [http://edn.link/2myd6p] article on agricultural applications for microcontrollers.

I've been following a similar trajectory to Tim for the last two years with regards to the use of microcontrollers for data gathering and farm automation. I started with simple programmable timers, and pre-packaged Wi-Fi relays, and eventually discovered a well-developed alternate firmware that takes much of the work out of programming the microcontrollers, and easily integrates into Wi-Fi networks.

The firmware is called Tasmota [https://tasmota.github.io/docs/], and is an Arduino-based software for ESP8266/ESP8285 and ESP32 microcontrollers. ESP8266 is a 160mhz Wi-Fi capable microcontroller that has 10 digital and 1 analog inputs/outputs, that can control relays, lights, motors, MOSFETs, read voltage, communicate on serial buses like I2C and SPI, and more. It costs around $2 for a development board. The Tasmota community is very active and drivers exist for all kinds of sensors (temperature, humidity), time-of-flight, air quality, pressure, light, ultra violet, carbon dioxide, and pH). Those sensors are available for very low cost ($1-$5).

ESP32 is more powerful (240mhz), and costs around $4, but has more digital and analog inputs/outputs. ESP8266 and ESP32 both use significantly more energy than a simpler Arduino board, mostly due to Wi-Fi, so trying to run these using batteries is challenging. The firmware works best when it can connect to Wi-Fi (and send/receive data to/from various servers), but low-power options exist, so modules can run for weeks at a time on a 18650 lithium cell, and indefinitely in conjunction with a small solar panel. In general, though, they are suited for environments where 24/7 power is available.

I have:

  • ESP8266 modules controlling bore-hole pumps (they can even read and pass-through serial data from motor controllers), with attached manual switches, so pumps can be turned on and off in-person or remotely (Figure 14A).
  • Modules controlling solar battery charging (Figure 14B) and reading individual lithium cells (although dedicated BMS [Battery Management System] balancing boards are easier)
  • Modules reading temperature, humidity, and rainfall; that data is logged to an SD card.
  • Modules for monitoring and logging energy usage of some freezers using a ESP8266 module plus an AC power meter board ($6) (Figure 14C).
EDN156 Figure 14

Figure 14. Modules controlling pumps (A) solar battery charging (B), and energy usage (C). Source: Andrew Lotze

Centralized data collection from all the modules is helpful, and I am using a $15 Raspberry Pi Zero 2 W to run the services that the ESP8266 needs for that. The Zero 2 W can easily handle:

  • Node-Red (automation flow-chart software)
  • Syslog (error and debugging logging)
  • InfluxDB (time-series database for sensor logging)
  • Grafana (graphing of time-series data)
  • MQTT (low-overhead messaging protocol for communicating with Wi-Fi things)
  • GPS (for accurate time-keeping in the absence of internet)
  • NTP (distributing accurate time to everything else on the network).

Grafana and InfluxDB let me collect the sensor data from the ESP8266 modules and visualize it (Figure graph 15A ) easily. I can also monitor switch state (Figure graph 15B) to see at a glance which things are on or off. 

EDN156 Figure 15

Figure 15. Examples of graphs showing sensor data (A) and switch states (B). Source: Andrew Lotze

Cite as:

Lotze, A. 2022. Microcontroller use. ECHO Development Notes no. 156.