water cistern level measurement
Two version with Arduino UNO R3 and later a changeover with ESP8266 NodeMCU and improvement of using different Ultrasonic sensors are available. Find here the details of the project with descriptions and demo sketches.
Click here to return to "Making of" overview.
1. Level and volume measurement of a water cistern with Arduino
While watering the garden during the past hot summer days, finally the irrigation stopped. With no water level or cistern volume indication in place at that time, this made me searching for an affordable solution. You can find such amazing solutions in the world-wide-web "www" or https://www.arduino.cc
- The project is solved using an Arduino UNO R3, first with an Ultrasonic sensor HC-SR04. That was a simple task, as there are many programs, so called "sketches" or video tutorials available in the www. So please search out there using e.g., "hc-sr04 arduino" as search words or simply download the pdf of my provided solutions. The sensor HC-SR04 was installed in a water proven box inside at the cistern top, with holes for the ultrasonic sender/receiver. The module is connected with a +5V DC power supply and needs two more data cables to the Arduino, situated in the basement of my house. Even on a 25m distance this works fine.
- My advise is to start with a simple sketch to measure the distance from the sensor to an movable object, in this case simulating the water level. Then adding the equation for the volume calculation of a cylinder (my Mall cistern luckily is cylindric shaped). On uploading and execution, the measurements can be seen on the programming tool Arduino IDE in the serial monitor.
- Update December 2020: For different reasons I have changed the Arduino UNO unit to be now an Arduino ESP NodeMCU E12 version. This enables access via WLAN with easy updating the sketch and a simpler connection to the router. As the unit is placed now outdoor in a water proven box, there need came up to attach an external antenna to the Arduino ESP unit for a proper WLAN signal strength. The sketch and more hints will be provided at a later date here.
Please find a demo sketch right here for download for the Uno R3:
Next then, was the idea to send those data to a cloud, making the level visible in a widget on my mobile devise or my PC. An "easy step" as well, as the Arduino UNO has an extension board to be plugged on top, the so called "Arduino Ethernet Shield W5100". That gives you the link from the processor board to your Internet router via LAN. With some needed extension commands on the Arduino sketch, this works simply well. I have noticed, that the Ethernet adapter can get a bit hot.
Having that sketch in place (see pdf below), the cloud was suggested by various communities to be "Thingspeak" (www.thingspeak.com). You simply register and define your "channels", meaning your sensor data that you are transferring with an API code. You get the API keys there to write and read your data. All you need to insert them into the Arduino sketch. As well you can easy add widgets on your Thingspeak channel. For your convenience please use App called "Thingview" providing as well nice and simple working charts for mobile devises. Below in the pdf or in the web you find many exampels how to solve the Ethernet program by using keywords "arduino ethernet shield thingspeak".
Lessons learned:
Need of a humidity resistant sensor: The application using the HR-SC04 was running very well in dry run and for about four weeks in the cistern. Then the App / the charts in Thingspeak showed the "maximum level". After exchange of the HR-SR04 with a new one, I got it back to work again. Four weeks later the same issue again. Obviously the sensor is not made for being used in a humid environment inside a water cistern, which in none of the tutorials is stated, even though many are using the sensor in similar projects. Find below the following
Tips&Tricks:
1. Humidity resistant sensor: Searching the web for experiences, I was glad to find finally the hint in the www-community with suggestions for the use of alternative sensors, compatible to the Arduino connection and sketch. The JSN-SR04T model, which is looking similar to an Automotive distance sensor for anti-collision.
2. Ultrasonic data reading: To make it really running well, one has to set the sequence settings using the JSN sensor for "high-low" compared to the HC-SR04 of the Ultrasonic delay from "10" to "20".
3. Creating an average value: Secondly, users blame the sensor to be sensitive and returning alternating data for its sender/receiver in one "eye". That is simply true, but just implement a sequence in the sketch, that reads for examples, e.g., "7" times or more the sensor distance value with a short delay in between each read. Then adding up that value in a variable and division at the end the total value by the number of reads, e.g., "7". The result is a stable set of data!
4. WLAN signal improvement by external antenna:
Using an external WLAN Antenna: The WLAN connection of the ESP8266 works fine and connects well to the router. In my project, some reasons did result in WLAN connectivity issues leading to problems with reaching the unit by OTA program uploads and a not stable data transformation to the Thingspeak server (reasons for weakening the WLAN signal: 1.additional housing of ESP project, 2. placement outdoors in a chamber next to the cistern, 3. increased distance to the router by location in the garden).
Therefore, it was essential using an external antenna at the ESP8266 (please check the internet to find instructions how to modify for the various ESP types onboard antennas). The parts needed additionally for my project:
- Alda PQ antenna including stainless steel mounting bracket, 5m cable suitable for e.g., 3G, UMTS, WiFi, Bluetooth (ASIN code: B00K8AJRWO, model 6749).
- Alda PQ antenna pigtail (ASIN code: B06Y49P1TT, reference number AC-705). This pigtail is cut and soldered at one side to the ESP8266 and the other side remains as is with the coupling nut for connection of the antenna cable in case of exchanges. By this the cable end of the antenna remains untouched.
Find the complete sketch for your reference and a newest one for the ESP8266 with a JSN sensor: