In this article, you can find how to solve the measuring the water level in the reservoir (e.g. rainwater reservoir). The values are converted into the volume in liters.
Ultrasonic waterproof distance sensor JSN-SR04T
Pi-Home – if you don’t have it, see How to section
This sensor consists of two parts, an electronic board and a water-resistant sensor. The electronic part must be in tank also stored in a water-resistant casing. The sensor is operating based on acoustic waves. For more information see for example: https://www.electronicwings.com/sensors-modules/ultrasonic-module-hc-sr04. The sensor can measure from about 20 cm to 450 cm at an angle of about 45°. It is therefore very important that there are no obstacles near the sensor and also on the sides. It is ideal to have your own sensor in a plastic tube and place it about 25 cm above the maximum water level in the middle of the tank.
We can fit the sensor in any tube. The sensor head is 25 mm in diameter so use tube with same or larger internal diameter. Connect cable to an electronic board. We are using IP44 bushing for the UTP cable. Plug in four wires depending on how it looks on the Arduino plate of the sketch.
Next, we’ll upload a sketch to Arduino. Sketch subtracts distance values. Then there is the conversion into tank volume and reading frequency. Focus and edit this part of the sketch according to your tank. The code can, of course, be combined to collect distance, temperature, PIR and other useful sensors on one Arduino board.