Introduction: Ultrasound Tank Level Meter

Need to monitor the fluid level in a large diameter well, a tank, or an open container? This guide will show you how to make a sonar non-contact fluid level meter using cheap electronics!

The sketch above shows an overview of what we aimed for with this project. Our summer cottage has a large-diameter well to supply drinking water for use in the house. One day, my brother and I talked about how our grandfather used to measure the water level manually in order to keep track of the water consumption and influx throughout the summer to avoid overdraft. We thought that with modern electronics we should be able to revive the tradition, but with less manual labour involved. With a few programming tricks, we managed to use an Arduino with a sonar module to measure the distance down to the water surface (l) with reasonable reliability and an accuracy of ± a few millimetre. This meant that we could estimate the remaining volume V, using the known diameter D and depth L, with about ±1 litre accuracy.

Because the well is located about 25m from the house and we wanted the display indoors, we opted for using two Arduinos with a data link in between. You can easily modify the project to use just one Arduino if this is not the case for you. Why not use wireless data transfer? Partly due to simplicity and robustness (the wire is less likely to be damaged by moisture) and partly because we wanted to avoid using batteries on the sensor side. With a wire, we could route both data transfer and power through the same cable.

1) Arduino module in the house
This is the main Arduino module. It will send a trigger signal to the Arduino in the well, receive the measured distance and display the calculated remaining water volume on a display.

2) Well side Arduino and sonar module
The purpose of this Arduino is simply to receive a trigger signal from the house, perform a measurement and send back the distance from the sonar module to the water level. The electronics are built into a (relatively airtight) box, with a plastic pipe attached to the receiving side of the sonar module. The purpose of the pipe is to reduce measurement errors by reducing the field of view so that only the water surface is "seen" by the receiver.

Step 1: Parts, Testing & Programming

We used the following parts in this project:

  • 2 x Arduino (one for measuring fluid level, one for showing the results on a display)
  • A basic 12V power supply
  • Ultrasound (sonar) module HC-SR04
  • LED display module MAX7219
  • 25 m telephone cable (4 wires: Power, ground and 2 data signals)
  • Mounting box
  • Hot glue
  • Solder

Parts cost: About €70

To make sure that everything worked as it should, we did all soldering, wiring and simple bench testing first. There are plenty of example programs for the ultrasound sensor and LED module online, so just we just used them for making sure that the measured distance made sense (picture 1) and that we were able to catch the ultrasonic reflection from the water surface on-site (picture 2). We also did some thorough testing of the data link to make sure that it works ever for long distances, which proved to be no problem at all.

Don't underestimate the time spent on this step, as it is vital to know that the system works before putting effort into mounting everything nicely into boxes, digging down cables etc.

During testing, we realized that the sonar module sometimes picks up a sound reflection from other parts of the well, such as the sidewalls and water supply tube, and not the water surface. This meant that the measured distance suddenly would be much shorter than the actual distance to the water level. Since we cannot simply use averaging to smooth out this type of measurement error, we decided to discard any new measured distances that were too different from the current distance estimate. This is not problematic since we expect the water level to change rather slowly anyway. Upon startup, this module will do a series of measurements and select the largest value received (i.e. the lowest water level) as the most probable starting point. After that, in addition to the "keep/discard" decision, a partial update of the estimated level is used to smooth out random measurement errors. It is also important to allow for all echoes to die out before conducting a new measurement - at least in our case where the walls are made of concrete and therefore very echo-y.

The final version of the code we used for the two Arduinos can be found here:

https://github.com/kelindqv/arduinoUltrasonicTank

Step 2: Civil Works

Since our well was located at a distance from the house, we had to create a small trench in the lawn in which to put the cable.

Step 3: Connecting and Mounting All Components

Connect everything as it was during testing, and hope that it still works! Remember to check that the TX pin on one Arduino goes to the RX of the other one, and vice versa. As shown in picture 1, we used the telephone cable to supply power to the Arduino in the well, to avoid using batteries.

The second and third picture shows the plastic pipe arrangement, with the transmitter placed outside the pipe and the receiver placed inside (yes, this was an uncomfortable shooting position...)

Step 4: Calibration

Having made sure that the distance from the sensor to the water level is calculated correctly, calibration was just a matter of measuring the diameter of the well and the total depth so that the fluid volume can be calculated. We also adjusted the algorithm parameters (time between measurements, the partial update parameters, number of initial measurements) to give a robust and accurate measurement.

So how well did the sensor track the fluid level?

We could easily see an effect of flushing the tap for a few minutes, or flushing the toilet, which is what we wanted. We could even see that the well was refilling at a relatively predictable rate overnight - all by just a glance on the display. Success!

Note:
- The time-distance conversion is currently not correcting for changes in speed of sound due to temperature variations. This could be a nice future addition, since temperatures in the well will vary quite a bit!

Step 5: Long Term Use

1 year update: The sensor works flawlessly without signs of corrosion or damage despite the humid environment! The only issue during the year has been that condensation accumulates on the sensor during cold weather
(in winter), which obviously blocks the sensor. This is not an issue in our case since we only need readings during summer, but other users may have to get creative! :) Insulation or ventilation are probably feasible solutions. Happy inventing!