Water Level Monitor - Arduino / ESP8266 / ESP32 / Sigfox

22/12/2021

Today I would like to present the level meter project, which consists of a web application and sensor nodes, which are formed by a microcontroller and transmission technology that allows the transmission of measured data from ultrasonic distance sensors. The web application allows to record data from the sensor node, which sends information about the water level in the well / tank at regular intervals (5 min). 


The data is visualized to the user in the web interface in the dashboard, or historically in time in graphs, tables. Ultrasonic water level measurement is used. The principle of measuring ultrasonic sensors is to send a Trigger signal with a length of 10 μs (microseconds), which bounces off the water level and returns to the receiver - Echo. The Time-of-Flight method is used to recalculate the time between sending and receiving the signal to obtain the distance of water from the sensor. 


After sending the data to the web interface, a correction is performed, when the real level is calculated from the bottom of the well, which is entered into the database. The correction is made on the basis of the known depth of the well and the accepted differential water level from the ultrasonic sensor. The web interface in the dashboard also visualizes the current well volume in liters based on the known well diameter. Both values ​​are also visualized with a tendency from the previous measurement t.k. rises, falls, stabilized by XY cm / by XY liters.

Ultrasonic sensors ARE suitable for:

  • Digging wells
  • Septics and cesspools
  • Streams and lakes
  • Plastic rainwater tanks
  • Silos (bulk filling measurement)
  • Containers (waste monitoring, collection container filling)
  • Boilers (monitoring of wood, pellets, coal, wood chips)
  • Manholes and cellars (groundwater monitoring)


Ultrasonic sensors ARE NOT suitable for:

  • Drilled wells (due to detection characteristics - wide beam)
  • Pipes and tubes (due to detection characteristics - wide beam)
  • In wells with a tributary (the turbulent level dampens the ultrasound, measurement is impossible)
  • To places with a sudden change in temperature (temperature affects the time of sound propagation, so even the stationary level appears to fluctuate)
  • For vacuum tanks (measurement is impossible)


Project uses an ultrasonic distance sensor HC-SR04 - (detection angle 15 °), or a water test sensor JSN-SR04T (detection angle is up to 60 °). It is also possible to use similar sensors with the same measurement method and Trigger, Echo pins: US-02X, IOE-SR0X, HC-SR0X, HY-SRF0X, DYP-ME007. Detection angle represents the width of the beam. It is possible to measure the level up to 400 resp. 450 cm (based on data from the catalog sheet of individual sensors).


It is possible to use an Arduino ATmega microcontroller (Uno / Mega) with a Wiznet W5100 or W5500 Ethernet module or its newer version USR-ES1 to operate the project. WiFi platforms from Espressif Systems - ESP8266 (NodeMCU, Wemos D1 Mini, Generic Board) or ESP32 (Devkit, or a separate module such as ESP32-WROOM-32) can be used for air data transmission. 

The wiring diagram for all platforms is available directly in the web application together with the source codes in the Wiring language (.ino app), resp. An experimental implementation in the ESP-IDF framework with a real-time operating system - FreeRTOS with the Queue blocking mechanism is also available for ESP32.

The ESP8266 and ESP32 microcontroller platforms (Wiring implementations) can also be operated in ULP (Ultra-Low Power) mode, which dramatically reduces their consumption to the level of tens of microamperes. Suitable for battery operation for several years (it is necessary to use a transistor to switch the power supply for the sensor, requires modification of the source code).


The second operating mode is StandBy, where the platform runs in standard mode and can be extended with the implementation of Over The Air (OTA), which offers firmware updates via LAN directly from the ArduinoIDE interface, espota.py is used for the upload process. Arduino with Ethernet only supports HTTP connectivity and does not support OTA update or Low-power mode! HTTP and HTTPS encrypted connections to the web server can be used for the ESP8266 and ESP32 platforms

If fixed internet is not available at the given place, it is also possible to use data transmission via IoT LPWAN network Sigfox, which covers most EU countries, America, Australia or Asia and is thus a suitable alternative for areas without internet coverage. The SIGFOX WISOL 868 MHz / 915 MHz UART modem (designation SFM10R1) is compatible, which communicates with the microcontroller via AT commands through the UART interface.


The modem is suitable for IoT applications with low current consumption. Message limit 12B (used 4B for water level UINT_32), custom callback from Sigfox backend executes HTTP / HTTPS POST request to write data to web interface. Because the Sigfox network has a limited number of messages per day (140), measurement and data transmission is performed every 11 minutes. In the case of a license for 140 messages, it is possible to use other - system data for transmission, for example GPS coordinates from the Sigfox ATLAS system (it is necessary to edit the file for writing to the database, + change of table fields).

To run the project, it is necessary to have a web server with Apache / Nginx support (for .php scripts) on the public IP address or in the LAN network, where the platform sends data from the ultrasonic sensor. ATTENTION, in case of Sigfox operation the server must be accessible from the Internet, otherwise it is not possible to write data! The web server runs an application that visualizes the user's latest data in a dynamic report with a microcontroller connectivity indicator.


The web interface also contains a record of records - maximum, minimum value of the water level in 24 hours, 7 days, 30 days. This data is visualized in the alarm clock representation. Highs and lows indicate continuous well yield. The web application also has various configurable data that are needed to correctly determine the water level - the depth of the well to the bottom (it serves as a calibration value for measurements). The ultrasonic sensor returns the water level from the top of the well, not from the bottom.

Therefore, the measurement is subtracted from this calibration value to determine the actual water level from the bottom. The second variable parameter is the well diameter. Setting the well diameter is important for converting the level to a liter by fighting the well. The settings subpage also contains an estimate of the maximum depth of the well at a given diameter for the most accurate measurements without reflections - it takes into account the detection characteristics of the sensor.

This estimation of the maximum well depth is performed by trigonometry and allows the user to better select the sensor for his requirements with respect to the dimensions of his well. Data is sent to the web interface via HTTP / HTTPS protocol with POST payload. The microcontroller is authenticated via a parameter in the POST request. Actions in the web interface (deleting the record, configuring settings, displaying the source code for the microcontroller) are behind the login via HTTP Auth Basic - name and password (it is recommended to use the web interface under HTTPS).

The project is also suitable for laymen, there is a .pdf document with instructions for the implementation of the web interface, which explains step by step the setup project on the web hosting / local web server, how to set MySQL database login details etc. Source code for microcontrollers is generated at web interface automatically.

The project can be tested in advance for free with your hardware on the test web interface: https://arduino.clanweb.eu/studna_s_prekladom/?lang=en. The last recalculated measured data from the web interface can be transferred to MQTT Broker (with another microcontroller that acts as a JSON client - program implementations are available). This data is distributed in JSON format on the .php subpage. It can be integrated into your own automation (Domoticz, Hassio, Loxone, etc.) and visualize data from the level meter in other visualizations, e.g. Grafana.


On request, you can try a full-featured web application (except HTTP Auth on the settings and source code subpages) in advance with your hardware. I supply exclusively a software solution. I do not offer hardware or its installation!

Other types of water level sensors that can be integrated (you need to create your own firmware):

  • Laser (LiDAR)
  • Hydrostatic
  • Electrostatic (capacitive / inductive)
  • Pressure (differential / with compensating atmospheric pressure sensor)
  • Optical
  • Mechanical (float)
  • Magnetic (Hall)
  • Microwave (radar)
  • Note: If the water level calculation from the bottom is performed on the microcontroller side, it is necessary to set the well depth to 0 cm on the web interface.

The web interface is available in Slovak, German, Russian and English. Slovak is the default language.

More information about the project, Sigfox network coverage at your region with the possibility of testing the project with your hardware is available at: https://martinius96.github.io/hladinomer-studna-scripty/en/

Download libraries that are required in source codes:

Library archive (.zip) extract to C:/Users/[User]/Documents/Arduino/libraries
Library name Library function Download
NewPing

Library for AVR microcontrollers (ATmega) Arduino Uno / Nano / Mega. It allows to perform measurements with ultrasonic distance sensors US-02X, IOE-SR0X, HC-SR0X, HY-SRF0X, JSN-SR0XT, DYP-ME007.

Download
NewPingESP8266

Library for ESP8266 and ESP32 microcontrollers. It allows to perform measurements with ultrasonic distance sensors US-02X, IOE-SR0X, HC-SR0X, HY-SRF0X, JSN-SR0XT, DYP-ME007.

Download
Ethernet2

Library for AVR microcontrollers (ATmega) Arduino Uno / Nano / Mega. It enables communication with the Ethernet module Wiznet W5200 to W5500 via the SPI interface.

Download
Ethernet3

Library for AVR microcontrollers (ATmega) Arduino Uno / Nano / Mega. It enables communication with Ethernet module Wiznet W5500 V2 - USR-ES1 via SPI interface.

Download
UIPEthernet

Library for AVR microcontrollers (ATmega) Arduino Uno / Nano / Mega. It enables communication with the Ethernet module ENC28J60 from Microchip via the SPI interface.

Download


© 2021 Martin Chlebovec - Arduino Blog - . All rights reserved
Powered by Webnode Cookies
Create your website for free! This website was made with Webnode. Create your own for free today! Get started