Source codes for Arduino, ESP8266, ESP32, NewPing Library: Github project repository
Try Web interface of Water Level Monitor project for free with your hardware - ON-LINE: HTTP - Arduino + Ethernet / ESP8266 / ESP32
For source codes of web interface or questions, contact author in ENGLISH language at: martinius96@gmail.com

Water level monitor project

Arduino Ethernet Wiznet W5100 / W5500 ESP8266 ESP32 Ultrasonic HC-SR04 JSN-SR04T PHY Ethernet WiFi

Supported microcontrollers for Water Level monitor - AVR / ESP



Transmission technology modules - Ethernet



Compatible ultrasonic distance sensors



Water Level monitor - Arduino / ESP8266 / ESP32


Water level monitor project consists of a central web interface that serves to collect data from sensor nodes and visualize them to the user. Current data on the water level are represented in the dashboard together with the conversion to the volume of the well, historical data on the water level are also available to the user in tabular or graphical visualization with line graphs. Web interface is responsive, it can adapt to any screen and device resolution. Projects web interface uses a backend written in PHP that can process incoming data from the request using the HTTP POST method. Backend corrects the measured level to the actual one based on the known depth of the well, calculates the volume of water in the well from this parameter and the diameter of the well. Depth and diameter of the well are entered into the system by the user based on the proportions of his well. Data is sent to the web server by a microcontroller supported by technology (Ethernet / WiFi), which performs measurements every 300 seconds - i. 5 minutes. Water level measurement is performed using ultrasonic sensors - HC-SR04, or its waterproof variant JSN-SR04T. Other sensors with Trigger / Echo signals from the RCW, US-XXX, IOE-SR0X, SR0X, HC-SR0X, HY-SRF0X, DYP-MEXXX, Parallax PING)))™ series can also be used.

Water Level Monitor webapp dashboard in OS Android with automatic data update via jQuery

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. Time-of-Flight method is used to recalculate the time between sending and receiving the signal to determine the distance of the water level from the sensor, which is located at the top of the well. Conversion formula takes into account the speed of sound 343 m/s at a temperature of 20 °C. An important parameter for both ultrasonic sensors is the beam width, in other words the detection characteristic. HC-SR04 sensor has a 15° detection characteristic. The beam is relatively narrow and the sensor is also suitable for narrower wells and tanks, but it is not waterproof and has a high risk of corrosion (oxidation) due to the presence of moisture in the well. For this reason, it is advisable to place this ultrasonic sensor above the well. Waterproof sensor JSN-SR04T has a detection characteristic of 60°, which considerably limits it and prevents its use in narrow wells, as the beam widens with distance and requires a well with a diameter of several meters (6 meters diameter at a well depth of 4.5 meters) . Ultrasonic sensors are fully maintenance-free. The JSN-SR04T sensor has an electronic control board that must not be exposed to moisture and water. Standard communication shielded cable is 2.5 meters long, it is possible to connect counterparts of the same cable to extend the line. In the case of a square well, the diameter of the inscribed circle is entered into the average, which will form the reference value of the water cylinder for the calculation of the well volume. Error of the total well volume in this case will be at the level of ~12.5%. The maximum measurable level height (level) by the sensors is about 400 to 450 cm (known from the datasheet).

Other types of water level sensors that can be integrated (you need to create your own firmware):
  • Laser (LiDAR) - (Garmin LIDAR-Lite v3HP, TFMini ...)
  • Hydrostatic - (LMK307, LMP305, DPT200 ...)
  • Electrostatic (capacitive / inductive)
  • Pressure (differential / with compensating atmospheric pressure sensor)
  • Optical - (GP2Y0A02YK0F, YD-02F, FS-IR02 ...)
  • Mechanical (float / bobber)
  • Magnetic (Hall) - (VCL9, Sen-Hz41wa ...)
  • Microwave (radar) - (CS476, CS475A-L, SP69, WLR 8/15/30 ...)
  • Ultrasonic - another type of output (UART, RS-232, RS-485, current loop 4-20 mA, Modbus TCP / RTU, M-bus, PROFINET, CAN, SDI, DQ ...)
  • Note: If the water level from the bottom of well is recalculated on the microcontrollers side, parameter - Well depth in web interface must be set to 0 cm!

  • Video demonstration of the web interface - Water Level monitor:



    Ultrasonic sensors are suitable for:


  • Dug waterwells
  • Digged waterwells
  • Septics and cesspools
  • Streams and lakes
  • Plastic rainwater tanks
  • Silos (measuring bulk filling)
  • Containers (waste monitoring, fill level)
  • Boiler rooms (monitoring of wood, pellets, coal, wood chips materials)
  • Shafts and cellars (flooding - groundwater height monitoring)

  • Ultrasonic sensors are NOT suitable for:


  • Drilled waterwells (due to detection characteristics - wide beam)
  • Pipes and tubes (due to detection characteristics - wide beam)
  • To waterwells with a gradient tributary (rippled water surface attenuates ultrasound, measurement is impossible)
  • In places with a sudden change in temperature (temperature affects the time of sound propagation, so even the stationary level appears to fluctuate)
  • Vacuum tanks (measurement is not possible)

  • Plug n play firmware - Ultra Low Power / StandBy


    Compiled firmware available for immediate upload to the microcontroller (libraries are not required)!
    Firmware name Firmware function ESP8266 ESP32
    Ultra Low Power

    Firmware for ULP applications with low current consumption. The firmware is loaded via the bundled ESPTOOL tool automatically, which is run with a .bat script (in the script it is necessary to change the COM port of your ESP board). After uploading the firmware and assuming that ESP does not have the SSID and password from the previous project stored, WiFiManager will start, which is used to configure the existing WiFi network. ESP will start broadcasting an open WiFi network with SSID -> Hladinomer_AP in AP mode. After connecting the client (Windows / Android / iOS) the Captive portal will start on 192.168.4.1 (the client should be redirected automatically). WiFiManager allows you to select a WiFi network in range in the web interface, set a password. After successfully connecting ESP to the specified WiFi network and assigning IPv4 from the given range, Captive Portal will be turned off, ESP remains in STA-Station mode. Subsequently, the sensor node will start transmitting data to the web interface Water Level Monitor . The next time the sensor node is started, Captive Portal and WiFiManager will no longer start, as the WiFi network configuration is permanently preserved. After datas are sent to server, ESP microcontroller will switch to Deep Sleep mode. It will turn off main processor Xtensa. ESP8266 is awakened via WAKE timer (jumper between GPIO16 and RST required - check Wiring diagram), ESP32 is awakened via RTC Timer.

    ESP8266 .bin firmware ESP32 .bin firmware
    StandBy

    Firmware for StandBy mode of the microcontroller, which sends at regular intervals (5 min) measurements of the water level to the web server and at the same time maintains connectivity with the AP in the LAN network. The firmware is loaded via the bundled ESPTOOL tool automatically, which is run with a .bat script (in the script it is necessary to change the COM port of your ESP board). After uploading the firmware and assuming that ESP does not have the SSID and password from the previous project stored, WiFiManager will start, which is used to configure the existing WiFi network. ESP will start broadcasting an open WiFi network with SSID in AP mode --> Hladinomer_AP. After connecting the client (Windows / Android / iOS) the Captive portal will start on 192.168.4.1 (the client should be redirected automatically). WiFiManager allows you to select a WiFi network in range in the web interface, set a password. After successfully connecting ESP to the specified WiFi network and assigning IPv4 from the given range, Captive Portal will be turned off, ESP remains in STA-Station mode. Subsequently, the sensor node starts transmitting data to the web interface Water Level Monitor. The next time the sensor node is started, Captive Portal and WiFiManager will no longer start, as the WiFi network configuration is permanently stored.

    ESP8266 .bin firmware ESP32 .bin firmware

    WiFi network configuration via WiFiManager - Plug n play firmware


    WiFi network Hladinomer_AP, Captive Portal and WiFiManager web interface on Android

    Principle of water level measurement and data transmission - Block diagram


    Level meter for cesspool, septic tank, well, measuring principle - ultrasonic distance sensor

    Backend at web interface uses trigonometry to estimate the measurable maximum depth of a well at a known well diameter (another parameter for calculating well volume). Wnterface allows the user to calculate to what maximum depth of the well each of the sensors is suitable based on its characteristics. Project is so easy to use even for laymen who do not know which sensor is more suitable for application in their well. Microcontroller used also plays an important role in the system. For the project, it is possible to use the Arduino platform (Uno / Mega) in revision R3 with an identical pinout, which can be connected to an Ethernet shield that communicates via the ICSP interface. It is also possible to use Ethernet modules and connect them directly to the hardware SPI pins of the microcontroller. Ethernet modules from Wiznet W5100, W5500, USR-ES1 are supported. From manufacturer MicroChip there is supported module ENC28J60 with software TCP stack. All Ethernet modules provide HTTP connectivity with the web server - port 80. WiFi microcontrollers from Espressif Systems - ESP8266 and ESP32 are also supported. Microcontrollers have several operating modes: StandBy, StandBy + OTA with the possibility of remote firmware upload via LAN network and deep sleep mode for ULP applications - Deep Sleep. In sleep mode for the ESP8266 microcontroller, it is necessary to add a physical jumper between GPIO16 (WAKE) and RST - see Wiring Diagram. ESP microcontrollers also allow to implement encrypted communication with the web server via HTTPS protocol. Both the ESP8266 and ESP32 platforms use the Root CA, which has issued a certificate (Issuer) for the web server domain. Certificate is embedded in the source code of the microcontrollers in .pem format. In order for the certificate not to take up space in the RAM memory of the microcontroller, it is inserted into the flash memory of the microcontroller - PROGMEM. Certificate of the certification authority is valid for 10 to 20 years, so it does not require frequent renewal of the certificate. Data on the current water level and water volume in the well are available in JSON format from the web interface. Water level monitor project can be integrated via MQTT into home automation (Hassio, Domoticz, Loxone) to display the water level in its own dashboard, e.g. Grafana. Subsequently, it is possible to perform peripheral control in the subsystem (irrigation, watering, activation of the domestic waterworks) on the basis of data on the water level in the well from the web interface.

    Operating mode StandBy StandBy + Over The Air (OTA) Ultra Low Power (ULP) FreeRTOS
    Microcontroller - - - -
    Arduino + Ethernet × × ×
    ESP8266 ×
    ESP32
    Source codes for Arduino, ESP8266, ESP32 (required installation of libraries): Available here

    Available libraries for microcontrollers (Arduino / ESP)


    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 RCW, US-XXX, IOE-SR0X, SR0X, HC-SR0X, HY-SRF0X, DYP-MEXXX, Parallax PING)))™.

    Download
    NewPingESP8266

    Library for ESP8266 and ESP32 microcontrollers. It allows to perform measurements with ultrasonic distance sensors RCW, US-XXX, IOE-SR0X, SR0X, HC-SR0X, HY-SRF0X, DYP-MEXXX, Parallax PING)))™.

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

    Screenshots of Water Level monitor webapp


    WaterWell Level monitor - webapp - main page - Last measured values with automatic refresh - AJAX WaterWell Level monitor - webapp - Historical measured datas with timestamp WaterWell Level monitor - Record, minimal, maximal value per day, week, month WaterWell Level monitor - graph of water level in time - week / year

    UART output of sensor nodes - FreeRTOS - ESP32:


    ESP32 - FreeRTOS - ESP-IDF - ultrasonic sensor measurement and data transfer to webserver via HTTP, POST transfer method ESP32 - FreeRTOS - ESP-IDF - ultrasonic sensor measurement and data transfer to webserver via HTTPS, POST transfer method Supported hardware for well level project - Arduino - Ethernet and WiFi connectivity - ESP8266 - ESP32 Sensor node ESP32 with PHY Ethernet module LAN7820 and ultrasonic sensor JSN-SR04T

    Schéma (Wiring diagram)

    Hladinomer - schéma zapojenia pre Arduino, ESP32, ESP8266 - ultrazvukový senzor vzdialenosti HC-SR04 / JSN-SR04T