Introduction: Measuring Water Level With Ultrasonic Sensor

Picture of Measuring Water Level With Ultrasonic Sensor

For my next big project (automated plant watering system) I was in need of having water level meter. I was choosing from contact and contactless methods of measuring fluid level in tank. Contact methods are resistive method, capacitive and inductive methods (magnetostriction). Most often contactless methods are optical method, radar and ultrasonic method. Because we didn’t want to affect the quality of water in tank we implement one of the contactless methods.

What method to choose? All contactless methods work on same principle: we send a signal and we measure time that send signal needs to come back. Optical method uses optical signals. Optical method can be very accurate, but sensors can get dirty over time and we are not able to make measurement at all. Radar method uses radar signals. Because of that (radar signals are high RF signals) it is not suitable for DIY. Ultrasonic method is similar to radar. Instead of radar wave we are sending ultrasonic wave. This procedure is ideal for our needs because ultrasonic sensors are accessible and low priced.

We made water level meter with Arduino platform (we used Arduino Mega2560, but any arduino will work).

For damage occurred during reproduction I am not hold responsible.

Step 1: Parts and Materials

Picture of Parts and Materials


- Arduino (Uno, Mega 2560,...)

- ultrasonic sensor HC SR04


- wires for connecting censor to Arduino

- acrylic glass for housing (optional)

Step 2: Theory Behind Ultrasonic Level Sensor

Picture of Theory Behind Ultrasonic Level Sensor

First, let us talk about some theory behind ultrasonic method of fluid lever measuring. The idea behind all contactless methods is to measure distance between transceiver and fluid. As said before, we transmit short ultrasonic pulse and we measure travel time of that pulse from transceiver to liquid and back to transceiver. Ultrasonic pulse will bounce from liquid level since because change of density of ultrasonic pulse travel medium (ultrasonic pulse first travel through air and bounce of liquid with higher density than air). Because water has higher density, majority of pulse will bounce off.

Two disadvantages exist with ultrasonic method:

- 1st: because of pulse length there is small window that we cannot receive pulse with transceiver because transceiver is transmitting. This problem is simple to solve: we placed our sensor higher from maximum water level for few centimeters allowing receiver to start receiving.

- 2nd: because of the beam width we are limited with tank diameter. If tank diameter is too small, signal could bounce of tank’s walls and could cause false readings.

Before installing sensor in tank we tested it for those two disadvantages. We established that we could have stable measurements from minimum distance of 5 cm from sensor. That means, we must install our sensor 5 cm higher then maximum water level. We also established that we didn’t have any problems with signal bouncing from tank’s walls with 7.5 cm diameter tank (tank’s length was 0.5 m). We complied these two results at construction of water tank and at the setting up of ultrasonic sensor.

Step 3: Water Tank

Picture of Water Tank

Watering system will use free fall for water feeding. Because of that, water tank needs to be lifted up from floor level. We made water tank from drainpipe 1m in length and 16 cm in diameter. We divided pipe into two sections. Lover section (first 50 cm) will house valves. Upper section will serve as water tank. On the upper section we are using pipe end cap as water tank cover. On end cap we mounted ultrasonic sensor. For larger stability we added wooden base, which will also house electronics and battery pack.

Here comes the mathematical specification of the tank. This part is essential, because we want to codify fluid height measurement in %. Starting point of codifying is measurement alone. Measurement can be between 6 and 56 cm (6 cm offset). This is codified into 0 to 100 %. It comes down to simple cross calculus.

We chose homogeneous tank because of easier calculations of volume (we are using pipe – cylindrical shape). Diameter of pipe is the same through the length of the pipe. We have also made equation whit which we can measure volume of water still in the tank. We didn’t implement this because there was no need for it. For now!

Step 4: Ultrasonic Sensor, Schematics

Picture of Ultrasonic Sensor, Schematics

We soldered wires to ultrasonic sensor (we used FTP or UTP cable; it can be one of them). Then we installed sensor in small custom made housing from acrylic glass. Casing with sensor in it was sealed off and mounted on tank’s cover. Housing was a bit improvised and it is not essential. Because of that, there are no picture and no plans for it. You can figure it out somehow by yourself.

We connected sensor on Arduino board following schematic in picture.

Step 5: Program

Picture of Program

We converted program for measuring distance to program for measuring water level. Program for measuring distance is not of our making but was found on internet in this tutorial we cannot find anymore.

First we transmit signal and then we wait and measure time between transmitted signal and received signal. This time is then converted to centimeter and centimeters are then converted to % and send via serial connection to computer. We could also calculate water volume that is still in the tank.

Step 6: Testing

Picture of Testing

Because in the future we wish to implement automatic watering system with two stages regulator, we must measure tank’s flow characteristic. Question is why we must do that? You see, outgoing flow in the tank depends on hydrostatic pressure inside of the tank. With basic knowledge of physics anybody see that hydrostatic pressure id decreasing with falling water level in tank. Because we want to feed plants every time with same amount of water, we must adjust valve opening time. With tank’s flow characteristic we can calculate how much water can flow out of tank at any time and with that we can determine how long valve must stay in open position.

Also we wanted to test our level meter. We filled up water tank to maximum height. Then we opened a valve and let all the water run out. Because drain pipe is mounted to prevent sucking out sediments, tank was emptied to 2%. In picture is presented response to step function. From this response we can approximate function on which water level is changing (with Excel, Matlab, or other powerful mathematical tool).

We can conclude that sensor works in accordance with expectations.

Step 7: What's Next?

Picture of What's Next?

Implemented water level meter serves as a concept of principle. If we would want to use this meter in DIY project and in semi industrial or other applications we would have to make test of sensor endurance and resistance to water splattering. After that test we would be able to see if sensor is appropriate for use in DIY projects or any other environments. Right now I can only say that sensor is working fine within this short period of time.

Because sensor is measuring water level with contactless method water can stay unspoiled. Implemented meter is also cheap and accessible and because of this it is very suitable for DIY.

Please feel free to comment and let me know if I made any grammar mistakes (english is not my first language).


Johnny J made it! (author)2015-02-04

Sensor with film stretched across....

im_anwar (author)Johnny J2017-11-27

Doesn't Work.

Zapnologica (author)Johnny J2016-02-02

no way that will work? The sound is going to bounce back off the plastic film right back into the receivere?

sgbotsford (author)Zapnologica2016-11-12

You may get some reflection, but because the film is flexible and has air on both sides, most of the sound will transmit through.

vonPongrac (author)Johnny J2015-02-05

Good job! Does it work properly? =D

vonPongrac (author)vonPongrac2015-02-05

Awesome! =D

I will implement this in on my sensor! =D

bigslo (author)vonPongrac2015-02-24

Have you tried the cling wrap method. Mine doesn't seem to work with it.

Johnny J (author)bigslo2015-02-24

Yes. Worked fine for me.
You need to make sure the film is stretched tightly over each transducer, and that the ultrasound can't "leak" between them.
mine seemed to work exactly the same with or without the film.

im_anwar made it! (author)2017-11-27

What about think this ultrasonic waterproof JSN-SR04T-2.0 Sensor, water gets moisture specially in winter , doesn't work due to water drops on the sensor transducer,readings will get wrong ,what can i do? any idea please share.

Johnny J (author)2015-02-02

Excellent idea! I suspect the sensors could be covered with food-wrap film to splash proof them without interfering too much with their operation.
I'll be trying it!

vonPongrac (author)Johnny J2015-02-03

Hmm... Food foil could work but I am a bit skeptical! Ultrasonic (or ultrasound) wave are same as sound just frequency is to high for you to hear it. Ultrasonic waves are mechanical waves of presure. Because of that, foil can interupt with measurment! This is why radar method is better in industry because it use high frequency electromagnetic waves which can penetrate some materials and waterproofing a transceiver is not so hard.

Johnny J (author)vonPongrac2015-02-03

I was thinking of the thin plastic film ("cling film" in the UK).
It's very thin and flexible, and I think it would vibrate with the ultrasound to transmit the vibrations if it was stretched over the sensors.
The calibration may need some adjustment, but I think it might work.
I'll try it and report back. :)

vonPongrac (author)Johnny J2015-02-03

Let me know about the results! I am very curious if this foil you are talking about will work! =)

Johnny J (author)vonPongrac2015-02-04

It does. :)
I tried it.... You need stretch the film over each sensor individually to avoid vibration transfer between the two, but otherwise it seems fine.
I just stretched film across the front of the sensors, folded it back along the sensor bodies and held it in place with rubber bands.
I couldn't see any difference in readings between the sensor with or without the film.
I suspect it would work with thin polythene as well, but I haven't tried that yet.

SandeepT23 (author)Johnny J2017-08-21

Waw thats nice.. That was something I was also looking for. Since you already tried it, I have no worries. Out of a curiosity can you find any difference in result after wrapping it in film.

I made a similar one at my home water tank. but at summer when water getting vaporized and it getting on the sensor.

vonPongrac (author)Johnny J2015-02-05

Awesome! =D

Thanks for update!

amorarun (author)vonPongrac2015-02-04

Very nice instructable...

If the cling wrap method makes the sensors waterproof of sorts. Will definitely implement it in the water storage tank at my home. But I don't think it is a possibility..

BoydG1 (author)2017-06-16

I want to measure the fluid level of sewage in a tank. Will the sensor work if glued to the outside of the top of the tank? If it will, does the thickness of the tank wall make a difference? The tank is 9mm thick plastic.


GabrielP96 (author)BoydG12017-07-01

BoydG1 it wont work, plastic being much more dense material than air, the sound signal will bounce right back at the sensor, and then the readings will be always 0, for this to work, you would need to cut a hole in the sewage tank (on the top) and install the sensor there. And further more, you got to check the specs of your sensor for the max distance it reads.

SanathK9 (author)2017-06-01

What will be the max depth this sensor can measure??

SanathK9 (author)SanathK92017-06-01

Can you suggest any sensor which can measure a depth 6m and another sensor for 100m

Droxz (author)2017-05-01

Wow real nice instructable, thanks for sharing and keep up the good work! :)

AbhishekS98 (author)2015-11-09


If I talk about Level sensing application, what is the minimum resolution (in cm) of water level difference ,we can measure

AyushT21 (author)AbhishekS982017-05-01

With HC-SR04 the minimum is 2 cm

sgbotsford (author)AbhishekS982016-11-12

That would depend in part on the frequency of the ultrasound. It's hard to get really clipped edges with the chirps, so accuracy closer than 1 lamda (wavelength) is tough. Probably 3 lamda is easily achievable. So at 60,000 Hz and if speed of sound is 300m/s you should be able to get accuracy of around a cm.

Two other factors come into play: Speed of sound is temperture dependent being roughly linear with kelvin temperature. So 1% increase for every 3 degrees C increase. Speed of sound is also dependent on the molecular weight of the gas, being higher in lighter gasses. Since warm air can hold more moisture than cold air, and water has a molecular weight of 18 compared to air's ~30, this will increase the earlier effect.

This may also have an effect if you are working in an environment that generates methane (monitoring fluid level in bio-reactor) or CO2 (compost monitoring) However if you are measuring differences, then most of these effects will largely cancel out.

bruster999 (author)2016-12-27


I built a similar hydroponics system with an HC-SR04 to measure the fluid level of the tank that housed the plant roots. It worked great other the level seemed to rise and fall with varying temperature. Even at a constant temp, them measurements were sometimes +/- 1 of the actual level. I tried using an averaging algorithm to even out the numbers but still saw these non-linear values. Anyone have any experience with getting stable and accurate fluid level readings?

AyushT21 (author)bruster9992017-05-01

Use a temperature sensor to detect the temperature and add this variable to your algorithm to prevent fluctuations in water level (author)2016-11-26

Hi, great job

few queries- on what type of tanks you have tried?? Will it work on metalic tank where reflections from metals are more ??

AmratanshG (author)2016-10-22

​How can i use this level measuring sensor to turn off the motor which is remotely located in order to avoid overflow using Arduino?

Darklingmilehi (author)2015-09-27

Can the ultrasonic pulse be detected when needing to be sent at maximum 6 feet from sesnor to bottom of tank? And what would be the input read from the response, would it calculate distance on its own, or does it strictly relay the time it took to reflect back? Needing to graph data of water level from 2000 gallon underground tank that supplies water to my house. i have access to the top and am making a custom lid with some boards and sesnors, that will hopefully send an ultrasonic pulse every 1.5 hours depending the maximum range of theae sensors, so if any one knos the height limit or has completed a similar project i would love to see ur take on it email me @ omniscientlife@gmail

SevP (author)Darklingmilehi 2016-09-30

Hi darkling, did you end up completing this project? I'm working on something very similar.

anmolveer taggar (author)2016-08-06

can u please suggest one sensor that can meaure the underground water levels for coal miners.....weare currently working on a project of smart helmet for coal miners.

hope to get the response at the earliest.

DwoodsF (author)2016-04-29

can this sensor pass sound wave through arcylic sheet ? or you need to make two holes for each sensor ?

reply at


Exop (author)2016-04-29

What is the highest level it can measure?

PunitS7 (author)2016-03-22

Hey there , Can anyone please tell me, how are we relating the pulse duration to the height by the following formula

h = t / 58

how come dat 58 occurs in the denominator.

level = speed of sound in air * pulse time / 2(This is the formula i am using)

An elaborate explanation will be helpful :)

XuxaA (author)2016-03-17

Hi. Can the ultrasonic sensor HC SR04 be use for Fuel Sensing? I am currently working for a project that can detect the fuel accurately.

Btw. Nice Project. :)

SadmanH made it! (author)2016-03-04

works perfectly! Though I've used this tutrotial for the code instead ( Going to use it to turn on/off water pumps for rooftop tanks so also going to add a relay later, for now it simply turns on or off an LED.

ahsanidrees (author)2016-02-01


Great Instructable! I have a hard time figuring out how to make my sensor being moisture proof due to humidity in the tank. Any success or suggestions?

Zapnologica (author)ahsanidrees2016-02-02

This is also my concern, Its going to rust and not last very long.

Zapnologica (author)ahsanidrees2016-02-02

This is also my concern, Its going to rust and not last very long.

ReubenC7 (author)2016-01-11


i am a final year engineering student and wanted intending of doing a level sensor project. do i need to program the arduino board like we program other pics or there is a special program

yes you do need to program the arduino like you normally would to get it to work with the sensor

WessamA2 (author)2016-01-15


Is the acrylic glass for housing invisible to the sonar?

PatrickA8 (author)2015-08-09

Youv'e mentioned that you installed the ultrasonic sensor 5 cm above the maximum water level right? But why does it seem in the picture that the ultrasonic sensor is just in plane with the top or the maximum attainable height of water? And does this doesn't effect the readings of the sensor?

vonPongrac (author)PatrickA82015-08-10

Pipe cap is about 5 cm high. But there is no physical barier beetwen watter level and sensor.

This is done becouse sensor can not measure first few cm (it does efect readings).

jagdishparm (author)2015-07-12

Hiii I tried to made a water flow sensor which is used from external so please give me suggestions

aslamxtreme (author)2015-06-21

Hi. I tried using the same method but with Picaxe 08M2 microcontroller.. I used the same HC-SR04 to sense water level in my watertank.. few days later it started giving weird readings. i found out that since my tank gets quite hot in the noon, the water gets evaporated inside the tank and it started condensing on the ultrasound sensors covering the mesh over the transducers.. so the readings were not reliable.. it showed 0 most of the time even though the tank was full...

arzleb (author)2015-05-23

Hello, can I translate the results into a graphical web interface? for remote monitoring? and can I link 2 Ultra Sensors to monitor 2 twin tanks?

vonPongrac (author)arzleb2015-05-24

Yes, you can do both (remote monitoring and 2 tanks). Here are some resources for you:

ganeshsp (author)2015-03-18

Hi Von,

A couple of requests:

1) I need to implement one more sensor in the ground level tank to prevent dry run.

2) I need to display the current water level in both the tanks using a 16x2 lcd display.

Would you be able to help please..?



About This Instructable




Bio: I am an engineer and a maker who loves technology challenges.
More by vonPongrac:Robotics guideArduino attendence loggerLED Night Light (Dark Sensor)
Add instructable to: