Waterwell Level Monitor - Arduino / ESP8266 / ESP32 / Sigfox + Ultrasonic Distance Sensor

by martinius96 in Circuits > Arduino

2201 Views, 5 Favorites, 0 Comments

Waterwell Level Monitor - Arduino / ESP8266 / ESP32 / Sigfox + Ultrasonic Distance Sensor

water.gif
water5.jpg

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. Project's 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 / LPWAN IoT Sigfox), which performs measurements every 300 seconds - i. 5 minutes, or in the case of transmission via LPWAN IoT network Sigfox, data is sent every 11 minutes, as the modem is limited by the network to transmit a maximum of 140 messages per day. Water level measurement is performed using ultrasonic sensors - HC-SR04, or its waterproof variant JSN-SR04T. Other sensors with Trigger / Echo signals from the US-02X, IOE-SR0X, SR0X, HC-SR0X, HY-SRF0X, DYP-ME007, Parallax PING)))™ series can also be used.

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.

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 monitoring)
  • Production (detection of products, their height and quantity, height of wound material)
  • Car parks (detection of free and occupied parking spaces)

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 (floater)
  • Magnetic (Hall)
  • Microwave (radar)
  • Note: If the water level from the bottom of well is recalculated on the microcontroller's side, parameter - Well depth in web interface must be set to 0 cm!

Supplies

  • Arduino Uno / Nano / Mega
  • Ethernet module (shield) Wiznet W5100 / W5500 / USR-ES1 or ENC28J60
  • ESP8266 (NodeMCU, Wemos D1 Mini)
  • ESP32 (Devkit, generic module)
  • Ultrasonic distance sensor HC-SR04 / JSN-SR04T / HY-SRF05 or similar

Optional transmitting technology modules:

  • LPWAN IoT Sigfox UART WISOL modem

  • SIM7000E for NB-IoT

Web Interface & Program Implementation for Microcontrollers

water2.png
water3.png
water4.png

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. Ethernet module ENC28J60 is supported also from manufacturer MicroChip. All Ethernet modules provide HTTP connectivity with the web server. 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.

Sigfox - Best Option for Locations Without Internet

sigfox.PNG
sigfox.png
sigfox2.png
sigfox3.png
sigfox4.png

For states, regions without internet coverage, it is also possible to use the LPWAN network Sigfox, which covers most European countries, certain Asian countries and some American countries.. This technology allows you to transmit small volumes of messages up to 12B in size. In the case of the Level project, a 4B water level value is sent. For a project extended by a rain gauge, the value 8B value is sent, which is formed by the height of the water level and the increment of precipitation.

As Sigfox allows a maximum of 140 messages to be transmitted per day, the data transmission interval is extended to 11 minutes. In both cases, the message does not contain the full usable length of the payload. Payload messages can also be supplemented with various system information, for example: GEO data (longitude / latitude) based on data from the GPS service Sigfox Atlas, RSSI (Received Signal Strength), message number and others. Communication module that was used for the project is a Sigfox WISOL UART LPWAN modem (version RC2 - 902 MHz required for USA, Canada, RC4 - 920 MHz is required for Asia, Australia and New Zealand).

This modem communicates via AT commands via the UART interface, which is software emulated on microcontrollers. The communication will take over at a speed of 9600 baud / s. The WISOL modem is equipped with an integrated u.FL connector on the PCB module for antenna connection, which significantly reduces coverage even indoors / shaded outdoors. For successful data transmission, coverage by two, preferably three or more BTS stations is required for successful data transmission. The BTS sends the transmitted information to the Sigfox backend, where it is necessary to make a callback, which will start after receiving the data. The callback makes an HTTP or HTTPS request to the domain where the web application is running with the POST method and a suitably encoded payload that the web application backend expects.

Level meter - Callback settings in Sigfox Backend:

  • Callbacks --> Custom --> New
  • In Custom payload config we write: cislo1::uint:16
  • To URL pattern: http://arduino.clanweb.eu/studna_s_prekladom/data... (or another URL of your web server where the project will run), the possibility to use HTTPS
  • In the HTTP method, select: POST
  • To the Body (body of the message) we add:hodnota={customData#cislo1}&token=123456789
  • To Content-Type: application/x-www-form-urlencoded

Codes for Microcontrollers and Webapp Codes

water6.png
water7.png

There are available source codes for three operation modes (if supported by microcontroller):

  • StandBy
  • StandBy + OTA
  • Ultra Low Power
  • Experimental (IoT Sigfox / SIM7000E for NB-IoT)

Source codes are in webapp dynamically created based on URL address of webserver and depth of dirs, where .php file is located. All implementations are made in Arduino Core (Wiring .ino app). There are also a few experimental implementations for ESP32 in Arduino Core and in framework ESP-IDF with using FreeRTOS and task oriented sketch.


HTTP protocol test web interface: http://arduino.clanweb.eu/studna_s_prekladom/?lang...

HTTPS protocol test web interface: https://hladinomer.000webhostapp.com/index.php?lan...

Water Level monitor have its own webpage: https://martinius96.github.io/hladinomer-studna-sc...

Source codes of all implementations are available on Github: https://github.com/martinius96/hladinomer-studna-s...

If you are interested in web interface codes, contact me at: martinius96@gmail.com