Water level monitor - Arduino, ESP32, ESP8266 + ultrasonic

17/07/2020


The water level monitor project is a type of project with recording and storing data that can be used for extended statistics of daily water level development. Thanks to this, it is possible to determine the months of the year when there is a shortage of water in the wells and the opposite, when there is enough water or even an excess. The project can become the basis for another project - automatic irrigation controlled by a microcontroller.

The project can also integrate advanced control of power elements - pumps, waterworks, solenoid valves, which can be used to water the garden and flower beds - irrigate, or even pump water and use it as a utility for flushing, washing. The project from the basic version used only logging data to a MySQL database at regular 5-minute intervals. To record the height of the water level (but also the height of other quantities, such as snow, coal, wood), I used the affordable ultrasonic distance sensor HC-SR04, which is characterized by high reliability and simple operation and low consumption.

It can measure a distance of 2-450 centimeters. It uses ultrasound at a frequency of 40 kHz with a transmission pulse of 10 microseconds in length. Based on the time since the reflection of the reflected wave, it is possible to use a formula to calculate the distance of the object from which the wave was reflected. However, the surface is required to be perpendicular to the ultrasonic distance sensor for measurement accuracy.

The description shows that it is possible to measure a maximum well with a height of 450 cm. The sensor is placed on the upper level, preferably in the middle of the well. In order to make the measurements as accurate as possible, a total of 5 measurements are performed, which are averaged. However, since the measurement result is rotated - the distance from the top is measured and not from the bottom, it is necessary to subtract the result from the maximum height (450 cm - or another at a shallower well) and create an absolute value. This is how we can determine the height of the water in the well. If we know the diameter of the well and also the height of the water column, we can also determine liters of water in a reasonable amount.

Technical parameters of the HC-SR04 sensor:

  • Operating voltage 3.8-5.5V
  • Consumption 8mA
  • Ultrasound frequency 40kHz
  • Maximum distance 450cm
  • Minimum distance 2cm
  • Trigger pulse 10μs
  • Effective detection angle 15 °

The technical specification shows that the sensor is also suitable for low-power applications where deep-sleep or another sleep mode of the microcontroller is used when running on batteries.

In order to be able to adapt the project for transmission by various technologies, I have created several source codes that allow transmission by these technologies and microcontrollers:

  • Arduino + Ethernet (Wiznet W5100 / Wiznet W5500)
  • ESP8266 (Wemos D1, Wemos D1 mini, NodeMCU, Generic module) - WiFi

  • ESP32 (Generic, devkit v1-v4, Lolin32) - WiFi
  • (*) Sigfox Wisol - IoT (requires more demanding initial configuration + HTTPS callback)
  • (*) NB-IoT
  • (*) GSM
  • * - any microcontroller

All technologies allow transfer to a web interface, where data is processed, stored in a MySQL database and archived for more extensive statistics. An HTTP request is made from the Arduino with the Ethernet shield, which sells the data to the web interface. When using ESP boards, or Sigfox module, or GSM, NB-IoT, it is possible to make an HTTPS request, which sends the data to the web interface.

I would like to add that with ESP32 and ESP8266 it is suitable to use a voltage divider from the input pin, which is 5V tolerant, but the logic of the board is 3.3V.

The web interface uses the Google charts library to represent 2-hour, 24-hour, 7-day, and 30-day data in bar charts. With the possibility of displaying the graph for the selected month or day. Thanks to this, it is possible to view the differences between years, months and days and evaluate the yield of the well and also whether it gains in yield due to years or dries out.

The system also includes a real-time table in which the latest data with a tendency of the water level is always displayed automatically. For longer-term statistics and averages, the site uses alarm presentations that visualize highs and lows, averages for 24 hours / 7 days / 30 days.

For a historical overview of measured data, it is possible to use a simple table, which also contains information about the time of the record and a comparison of the previous value, so it is possible to determine the increase or decrease of water - water level in the well.

Login system with the possibility of changing data is a matter of course, including logging IP addresses that have connected or did not connect to the system due to entering bad data.

© 2025 Arduino Blog - . All rights reserved - martinius96@gmail.com
Powered by Webnode Cookies
Create your website for free! This website was made with Webnode. Create your own for free today! Get started