Source codes for Arduino, ESP8266, ESP32, NewPing Library: Github repo
Try Water Level Monitor + Rainfall RG-11 sensor project for free with your hardware: HERE
Support for project Water Level Monitor with Rainfall sensor extension was ended in 2020 year.

Water & Rain level monitor project

Arduino Ethernet Wiznet W5100 / W5500 ESP8266 ESP32 Ultrasonic HC-SR04 JSN-SR04T RG-11 Sigfox

Supported microcontrollers for Water Level monitor - AVR / ESP



Transmission technology modules - Ethernet / Sigfox



Compatible ultrasonic distance sensors



Supported IR rain sensors



Water Level monitor - Arduino / ESP8266 / ESP32


The water level meter project uses a web interface to visualize the measured data on the water level in the well, tank. The responsive web interface in the Bootstrap Bar template adapts to any screen on which the data is visualized. The data is readable on watches, smartphones, computers, Smart TVs and other devices. The web interface of the project uses a backend written in PHP, which processes incoming data supported by the POST request method, converts the measured temperature to the actual water level, calculates the well volume based on known data on depth and well diameter entered into the system by the user. The data is sent to a web server by a microcontroller, which performs measurements every 300 seconds - i. For 5 minutes, or in the case of transmission via the Sigfox IoT network, the data is sent every 11 minutes. Water level measurement is performed using ultrasonic sensors - HC-SR04, or its waterproof variant JSN-SR04T, or UART sensor URM07 (SKU SEN0153) - available only in a special version of the project Level meter. It can measure a distance of up to 750 cm, due to the large detection angle, it does not fit into a large number of wells ... The principle of measuring ultrasonic sensors is to send a Trigger signal with a length of 10μs (microseconds) and based on the time when the signal returns to the receiver - Echo it is possible to calculate the distance between the sensor and the level. An important parameter in both ultrasonic sensors is the beam width, in other words the detection characteristic. The 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). The JSN-SR04T waterproof sensor has a detection characteristic of 60 to 75 °, which does not allow it to be used in narrow wells, as the beam expands greatly with distance and requires a well with a diameter of several units (6 meters at 4.5 well depth).


The web interface uses trigonometry to estimate the measurable maximum depth of the well at a known well diameter (another parameter for calculating the well volume). The web interface allows the user to calculate to what maximum depth of the well each of the sensors is suitable based on its characteristics. The project is so easy to use even for laymen who do not know which sensor is more suitable for application in their well. The microcontroller used also plays an important role in the system. The project used the Arduino (Uno) platform connected to an Ethernet module / shield from the Wiznet model W5100 and W5500 series, respectively, which provided HTTP connectivity and enabled the microcontroller to transfer data to a remote web interface on the Internet. As the level meter is an outdoor project, many users would also like the possibility of using a WiFi platform without having to pull Ethernet connectivity to the well. WiFi platforms from Espressif Systems - ESP8266 and ESP32, which are used in the project allow operation in various modes - StandBy, Deep Sleep (deep sleep with WiFi antenna off), StandBy + OTA - allows you to remotely upload to the board new firmware directly from the LAN Arduino IDE environment. For the Deep Sleep operating mode, there is a modified wiring diagram for the ESP8266 platform, which uses a signal that is fed to the RST to wake up the WAKE microcontroller. At the same time, this connection does not allow the program to be updated without disconnecting this jumper. For ESP32, the Deep Sleep mode is used using an RTC timer, which wakes up ESP after a certain time. Platforms can communicate with the web interface via HTTP, but also HTTPS protocol. The ESP8266 platform uses a fingeprint of the web server's public key in SHA1 format, but requires more frequent renewals, as they are valid for a maximum of one year or 2 years, respectively. The microcontroller from the ESP32 series uses the certificate of the root certification authority, which issued a certificate for the web server - the ROOT CA certificate in .pem format for the HTTPS connection. From the point of view of operation, this option is better, as the certificate of the certification authority is also valid for 20 years and no renewal of the certificate is necessary.


As the Arduino platform is more prone to program "crashes" due to severely limited memory and performance resources (compared to ESP platforms), a watchdog has been added to the source code that is able to restart the platform and restore operation. The software implementation of the microcontroller firmware is extended by recording data from the IR rain gauge Hydreon RG-11, which can emulate the flipping bucket method based on switched DIP switches (it also supports other modes that are used in the automotive industry, horticulture). This allows the microcontroller to read the number of pulses coming from the rain gauge in an interruption, where one pulse represents a rainfall value of 0.01 mm. The pulse comes in the form of a LOW signal, which is fed via an integrated relay that switches to the NO state (from NC). A pullup resistor is connected to the digital input, which holds the HIGH level until a pulse from the tipping bucket occurs in 0.01 mm increments. Since the input is still HIGH and enters the LOW state only when the precipitation increment is added, the increment is detected by the FALLING interrupt method, which responds to the leading edge. Between pulses, debouncing is performed with a length of 15ms, which prevents the addition of one pulse several times due to signal oscillation. Up to 66 pulses can be recorded per second, which corresponds to a 0.66 mm increment. The rain gauge has protection against UV radiation, it does not degrade over time, its convex glass, on which precipitation is captured, has a self-cleaning effect. The operation is thus fully maintenance-free and reliable, as the tipping bucket is emulated by an IR rain gauge and does not contain a mechanical part like a classic tipping bucket, where there is also a risk of it becoming clogged with dirt. The rain gauge uses an Arduino / ESP outlet with interrupt support. The pulse is added to a volatile variable that can be serviced in the interrupt. The data from the rain gauge thus form the sum of precipitation for the period after the data has been sent. The web interface is also extended for this possibility with graphical and textual visualization of precipitation development. Text output allows the sum of precipitation per hour, day to year. The rain gauge project is currently only available for the Arduino platform, but with a few changes it is also possible to run it under ESP32, ESP8266 Both versions of the projects are fully translated into English, Slovak, Russian and German.

Hlavný prehľad - Hladinomer + Zrážkomer - aktuálne namerané údaje

For locations where there is no coverage of the fixed Internet, it is also possible to use the IoT network Sigfox, which covers almost 90% of Slovakia, BTS broadcasting stations are located on TowerCom transmitters. This technology allows you to transmit small volumes of messages up to 12B in size. In the case of the Level meter project, the 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 length that it can, i. 12B. Payload messages can also be supplemented with various system information, for example: GEO data (longitude / latitude), RSSI (Signal Strength), message number and others. The communication module that was used for the project is a Sigfox WISOL 868MHz UART modem. 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 must make 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.

Water Level meter + Rainfall - Callback settings in Sigfox Backend:
  • Callbacks --> Custom --> New
  • In Custom payload config we write: cislo1::float:16 cislo2::uint:16
  • To URL pattern: http://arduino.clanweb.eu/studna/data.php (or another URL of your web server where the project will run), the possibility to use HTTPS
  • In HTTP method select: POST
  • To the Body (body of the message) we add:
  • dazd={customData#cislo1}&hodnota={customData#cislo2}
  • To Content-Type: application/x-www-form-urlencoded

  • Web interface visualizations - Level meter + Rain gauge


    Main Dashboard of Waterlevel monitor with Rainfall monitor Historical datas - Water level monitor, Rainfall monitor WaterWell Level monitor - graph of water level in time - week / year Water level monitor - rainfall in time - line graphs - Hydreon RG-11

    Sensor detection characteristic HC-SR04 - 15°


    Water Level monitor - HC-SR04 detection characteristics - ultrasonic distance sensor

    Sensor detection characteristic JSN-SR04T - waterproof - 45°


    Water Level monitor - JSN-SR04T detection characteristics - ultrasonic distance sensor