water level with ultrasonic distance meter - error readings

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Barashur
Normal user
Posts: 3
Joined: 25 Apr 2019, 15:23

water level with ultrasonic distance meter - error readings

#1 Post by Barashur » 25 Apr 2019, 15:41

Hello everybody,

Im pretty new with ESP easy, in the past i have done few projects with arduino, now I wanted to test out D1 mini with ESP8266 since I want to do project over wifi and its pretty simple with ESP Easy. I dont have a vast knowledge on this topic, so I may have done some mistakes Im not aware of. I will start with quite general question with minimum details to keep it simple.

I have a water tank on my yard and I wanted to check water level in this tank with ultrasonic sensor. My setup is:

Solar panel -> battery charger -> 18650 battery -> step up to 5V -> D1 mini -> ultrasonic distance sensor


Everything is going smooth on non-liquid surfaces. I can get a precise reading +-0,5cm over 3 meters. But when I direct the sensor at the water surface it works correctly only up to 80cm. So the readings are 70cm = 70cm, 80cm = 80cm, 81cm = 51cm. This error is not linelar (like 20% error from measured distance or something) but this error is ALWAYS 25-30cm (when the sensor is 180 cm away from surface, the readings are steady on 150-151cm).

I have even tried out to pour water into a large bowl (I filed it to the top so there is no readings from the sides of the bowl) and the error was the same like in the tank.

Can anybody help me why this is occuring?

I have tried several distance sensors (JSN-SR04T, HC-SR04, HY-SRF05) but all of them are measuring the same errors. And yes, I can easily correct this issue with function in node-red but I would like to find root cause since I cannot trust those measurements.


Im using this D1 mini:
https://www.amazon.co.uk/Makerfire-Node ... B071S8MWTY



Thank you for your help in Advance!

Barashur

User avatar
grovkillen
Core team member
Posts: 3262
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: water level with ultrasonic distance meter - error readings

#2 Post by grovkillen » 25 Apr 2019, 18:37

I have a friend who suggested using a BME280 and use the pressure to measure water level. I would think that could be working.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Ton_vN
Normal user
Posts: 132
Joined: 21 Oct 2016, 15:20
Location: Hengelo (Ov)/ NL
Contact:

Re: water level with ultrasonic distance meter - error readings

#3 Post by Ton_vN » 25 Apr 2019, 19:56

@grovkillen

Is your friend referring to this kind of application of basic physics?
Please take note that I took shortcuts in the description at the righthand side of the drawing.

Waterlevel02 [640x480].jpg
Barometric measurement of liquid level
Waterlevel02 [640x480].jpg (47.99 KiB) Viewed 1579 times

'Devil in the details', but the principle setup is simplicity itself and completely passive/contactless.
Must be possible to realise as DIY with 2*(PVC-pipe + cap), 2*BME280 (or other pressure-sensor) and 1*ESP-with-solarcellPS.
Depth of measuring pipe is only limited by the length of the pipes you have available (and the length of the available drill, if used in soil for agricultural application!)
The sensors can be well protected above liquid-level.
Requires accurate dimensional measurements and careful calculations to have 'some' level of accuracy for the resulting data.

Update April, 26, 2019, because my quote from the Physics_book was not correct:
:oops: too long ago that I used that information.


The outside world is enormous and Actual Level is ruling versus the Reference Low level in relation to the volume of air in Pipe2
the difference in pressure measured by BME280_A is determined by Column of air with height H in Pipe2, translated to the weight of the equivalent Column of liquid.
;-) For further required arithmetics, better see your Physics_Book ..........
Reason to take Pipe2 rather large, is to get sufficient clean space as counterbalance to generate the difference in pressure:
a narrow pipe may become clodded.
A spacious Pipe1 is favourable for same reason, also allows you to crosscheck the liquid level in Pipe1 the old-fashioned way (with a stick dropping down beside Pipe2), and to perform some functional tests by pouring an amount of water into Pipe1.
Calibration is not possible that way, because Pipe1 has an open bottom, and the poured water will immediately flow out that way:
the water poured in will only slightly rise above the outside Actual level, certainly not in relation to the volume poured in.
BME280_B seems needed not only as reference, but also to take into account the meteorological pressure-effects.

Interested to hear any practical experiences related to this kind of setup, because see possible application at this location ;) to avoid wet feet .......
Last edited by Ton_vN on 01 May 2019, 20:00, edited 8 times in total.

Barashur
Normal user
Posts: 3
Joined: 25 Apr 2019, 15:23

Re: water level with ultrasonic distance meter - error readings

#4 Post by Barashur » 25 Apr 2019, 20:43

Ton_vN wrote:
25 Apr 2019, 19:56
@grovkillen

Is your friend referring to this kind of application of basic physics?

'Devil in the details', but is simplicity itself and completely passive/contactless.
Must be possible to realise as DIY with 2*(PVC-pipe+cap), 2*BME280 (or other pressure-sensor) and 1*ESP-with-solarcellPS.
Depth of measuring pipe is only limited by the length of the pipes you have available (and the length of the available drill, if used in soil for agricultural application!)
The sensors can be well protected above liquid-level.
Requires accurate dimensional measurements and careful calculations to have 'some' level of accuracy of the resulting data.

Interested to hear any practical experiences related to this kind of setup, because see possible application at this location ;) to avoid wet feet .......
Thank you for suggestion. I have few other projects in mind and I would definitely use this. Although for this water tank there is no posibility to attach such tubes into the water or to get in to attach it to the bottom. I attached the ultrasonic sensor on the bottom of the lid so its practical.

I think my problem has something to do with the angle the ultranonic sensor is picking up readings. I read somewhere that there is posibility to traight up the beam somehow and the information that it might help. I tried putting the sensor inside the 10cm long tube, it was indeed picking up correct signals but wrong measurements were still present on distances further than 80cm. But I dont have enough knowledge about this problematic so I cannot evaluate if its nonsense or not.

User avatar
grovkillen
Core team member
Posts: 3262
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: water level with ultrasonic distance meter - error readings

#5 Post by grovkillen » 26 Apr 2019, 07:44

Ton_vN wrote:
25 Apr 2019, 19:56
..
Waterlevel [640x480].jpg
..
Spot on! That's pretty much the idea he had. He also thought that maybe only one BME280 was needed (the internal one), the external (atmospheric) pressure might not influence the pipe that much. Should be easy to test.

Together we discussed the possibility to have an pump which pump air into the pipe and when the pressure stabilize the entire pipe is air filled. That would be easy to test to and see if that way is better than the static test.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Ton_vN
Normal user
Posts: 132
Joined: 21 Oct 2016, 15:20
Location: Hengelo (Ov)/ NL
Contact:

Re: water level with ultrasonic distance meter - error readings

#6 Post by Ton_vN » 26 Apr 2019, 08:21

Comparison of the 2 sets of pressure-data is not a big deal; just a little calculation.
Need/meaning of BME280_B is dependent on some 'what-if' estimations related to application:
1) if the liquidlevel shifts, how much pressure-difference/cm (to have a reference)?
2) how quick is a 'usual' shift in the liquidlevel relative to shifts in meteo air pressure?
Testcases for 2)?
a) If used in the garden to measure groundwaterlevel, probably the usual shift in waterlevel is very slow, and much slower than the change in meteo air-pressure.
b) In the same application, if a weatherfront is passing with heavy showers, you may be surprised by the amplitude of simultaneous changes for the meteo-pressure and for the waterlevel
c) If measuring the liquidlevel in a tank, the amplitude of change in liquidlevel in that tank probably overrules the change in meteo airpressure.
.......

For BME280_B you could take another source for local airpressure, but 2*BME280 is not expensive, easy for compatibility, and if read by same ESP, the synchronisation is 'automatic'.

diozoli
Normal user
Posts: 2
Joined: 08 Sep 2018, 13:07

Re: water level with ultrasonic distance meter - error readings

#7 Post by diozoli » 29 Apr 2019, 07:06

Hi Most probably you have problem with the reflection from the liquide surface. I would propose a simple, none technical solution: put a piece of wood as big as the tank to float on top of fluid an the problem might be solved

Ton_vN
Normal user
Posts: 132
Joined: 21 Oct 2016, 15:20
Location: Hengelo (Ov)/ NL
Contact:

Re: water level with ultrasonic distance meter - error readings

#8 Post by Ton_vN » 01 May 2019, 16:58

A floating disc sounds like a very practical solution for controlled ultrasonic reflection!

For the barometric concept a simple, empirical way to quickly check in practise whether calculation and practise are matching:
  • put a BME280 inside a pipe closed airtight at the end of the BME280
  • push that pipe vertically down in a bucket of water
  • read the data from the BME280
Or an equivalent setup.
Looking in my junk found a pressure sensor Bosch artnr 0 273 003 204 capable to deal with 200kPa, originally applied in the automative industry:
it generates a DC signal as function of pressure.
;-) In the good, old days applied that device to build a barometer with my Acorn Electron computer, visualizing pressure steps of approx. 1 hPa with the Electron's ADC & Software.
For this test attached a 4mm air hose to the device and dropped the end of that hose in a bucket with water.
Measuring the output signal with an electronic meter, with present open air pressure of 1014 hPa it shows 2.29V, which is according to expectation.
Pushing the end of the hose under water to -25cm (which should raise the pressure by 25 hPa) the reading is still 2.29V, not the expected 2.35V

Apparently 'something wrong' in the test setup related to the transfer of pressure .......
:? Headscratching: tomorrow another try ......
Last edited by Ton_vN on 02 May 2019, 10:23, edited 8 times in total.

kimot
Normal user
Posts: 165
Joined: 12 Oct 2017, 20:46

Re: water level with ultrasonic distance meter - error readings

#9 Post by kimot » 01 May 2019, 20:04

It looks like software problem with your code.

I am using HC-SR04 without any problem reading water surface.
My measuring range is 110 cm = empty tank, 2 cm = full tank. ( this is now ).

Only problem I have got - when it is raining, some water drops condenses on sensor at night.
Or I need better cover for my sensor ...
I eliminate by Domoticz code those bad readings.

I send to Domoticz actual distance and calculate volume in m3 and percentage and water influx or consumption.

But I am using battery powered Arduino mini with MySensors network.
So I am cutting power off for SR04 during sleep and when it power on again, there is little delay and I read three times distance
and use only last reading, because independently on delay time, first readings returns zero sometimes ...

Another problem is, that I power SR04 directly from battery, which voltage changes a little according ambient temperature.
Using voltage stabilizer for SR04 is necessarily.
It was very quick project and I try different solution at future:
Arm with float and potentiometer to measure angle of this arm and calculate distance.

IMG_20190501_191554.jpg
IMG_20190501_191554.jpg (446.17 KiB) Viewed 1576 times
Nadrz.png
Nadrz.png (365.98 KiB) Viewed 1576 times
Distance.png
Distance.png (179.9 KiB) Viewed 1576 times
Volume.png
Volume.png (161.6 KiB) Viewed 1576 times

Ton_vN
Normal user
Posts: 132
Joined: 21 Oct 2016, 15:20
Location: Hengelo (Ov)/ NL
Contact:

Re: water level with ultrasonic distance meter - error readings

#10 Post by Ton_vN » 02 May 2019, 09:20

Some more 'analysis' related to the barometric approach for measuring water level.

Calculated pressure rise due to water depth/column is approx. 1 hPa/cm.
=> -0.5m = +50hPa
=> -1m = +100hPa
=> -1.5m = +150hPa
=> -2m = +200hPa

During te most recent calibration-run in real weather for my meteo barometers relative to the qualified nearby KNMI Meteo-station I measured
- lowest meteo air pressure = 970 hPa
- highest meteo air pressure = 1030 hPa

According to the ESPEasy-Wiki, the BME280-sensor has a specified pressure range of 300 - 1100 hPa
In relation to the expected pressure-rise, it implies that in practise with a BME280
at highest, practical meteo air pressure it is not possible to measure deeper than
1100 - 1030 => -70cm
Luckily more candidate pressure sensors are available
MS5611-sensor has pressure range of 10 - 1200 hPa (and even better resolution than BME280)
which would allow (at the max. meteo pressure) measurement till a max. depth of - 1.7m
And the 'good old' Bosch pressure sensor mentioned in earlier message with it's 200kPa [= 2000hPa] would even allow -2.7m

Status of test
Have a suspicion that the (considerable) length and the flexibility of the applied air hose have negative effect on the transfer of the pressure-rise:
possibly the hose gradually expands under the difference in pressure, and as result the difference in pressure 'does not arrive' at the sensor
;-) The difference between theory and practise => 'lessons learned' ......
In this case: use very short&stiff air hose, or better no hose, but put the sensor in Pipe2 inside at the closed top.

Grovkillen's mentioning of an air pump might solve another practical aspect.
A static setup is nice, but airtightness for Pipe 2 is then a very critical aspect.
To remedy air leakage, with a small aquarium air pump you forcibly could keep water out of Pipe2:
if Pipe2 is completely airfilled, then bubbles will appear in Pipe1, and pressure in Pipe2 is approx. according to water depth.
[But the bubbling only starts at slight overpressure (which aspect 'destroys' the accuracy of the measurements), continuous running of an aquarium pump needs significant power, which is not 'green', and that power is not available at remote locations]
Instead of continuous forced pressurization, you could fit a small valve to Pipe2 enabling you to manually blow the pipe at installation and later for maintenance if you suspect that leakage has caused intrusion of water.
;-) All those small, practical aspects .........
Last edited by Ton_vN on 18 May 2019, 11:10, edited 1 time in total.

Wiki
Normal user
Posts: 138
Joined: 23 Apr 2018, 17:55

Re: water level with ultrasonic distance meter - error readings

#11 Post by Wiki » 02 May 2019, 14:45

kimot wrote:
01 May 2019, 20:04
[...]
Arm with float and potentiometer to measure angle of this arm and calculate distance.
[...]
I think using a potentiometer will be problematic due to rough environment causing corrosion. Better way would be to use a MPU 6050 or similar in a sealed box for measuring the angle of the floating arm.

Drum
Normal user
Posts: 266
Joined: 07 Feb 2016, 11:56

Re: water level with ultrasonic distance meter - error readings

#12 Post by Drum » 02 May 2019, 15:58

Something like this might work, but this one is only 12 inches, there is probably a longer one somewhere. It is specifically for measuring liquid levels.

https://www.adafruit.com/product/1786

It is made buy https://milonetech.com/ they have 2 models up to 800mm. Not cheap, but if it works well I think it is worth it, certainly worth looking at.


seb82
Normal user
Posts: 18
Joined: 05 Sep 2018, 10:56

Re: water level with ultrasonic distance meter - error readings

#14 Post by seb82 » 05 May 2019, 18:40

Hello everyone,

I have been looking for quite some time at this question (measuring levels in a fuel tank and a swimming pool) and I tried to summarize some experience and references below. Hopefully it can help and give ideas for specific cases.

For fuel tank:
- HC-SR04 was seeing the walls (too large beam), not adequate
- GP2Y0A02YK0F was not very stable
- VL53L0X was kind of ok if fuel was not moving at all (boiler fully stopped, no recirculation)
- GY-US42V2 (1 cm resolution) was working well if it was hold 5 cm below the plug, otherwise it was disturbed (not acceptable for me because of the risk to loose parts in the tank) - this sensor is "somehow" equivalent to I2CXL-MaxSonar-EZ4 from Maxbotix ; please note that mine was not of great quality as I had to push a little bit on the plastic cap to get a reading (most likely a bad weld)
- Some people reported good result using HRLV-MaxSonar-EZ4 sensor but it is more expensive (please note the use of EZ4 series which has a narrower beam)
- Some other people used a 4-20 mA pressure sensor that must be placed at the bottom of the tank. I did not try this solution myself, but from my industry experience I believe it would work very well.
For information, finaly solution was completely different as I have put a CT meter on the boiler power supply and used the burner consumption specs and tank dimension => result is within 5% of real level measurement which is acceptable for me.

For swimming pool:
- GP2Y0E03 and VL6180X are under testing at the moment. I use the hole on top of the skimmer. They seem to work well if you put inside the skimmer something that floats and does not reflect light. Otherwise, water surface is badly reflecting the signals.
- GP2Y0E03 has a 1 cm resolution and appears to be a very good sensor. You can even add a transparent protection layer or put it in a transparent box.

@Ton_vN, @grovkillen: I found an example using an air pump. The article is in french but content is really worth reading with clear schematics. They do not use a BME280 sensor but a specific pressure sensor MPX5050DP. After some research I found that MPVZ5004GW7U and MPXV5004DP may also be good candidates but it really depends on the height of water. It also explains that using long hoses helps to stabilize the pressure measurement.

@Drum: I wanted to go with eTape sensor, but I read in some forums that it is quite difficult to setup as it is very sensitive to any constraints on its top to hold it

@Barashur, I would suggest to try first one of Maxboxtix EZ4 sensor or maybe its copy GY-US42V2 from Aliexpress

Ton_vN
Normal user
Posts: 132
Joined: 21 Oct 2016, 15:20
Location: Hengelo (Ov)/ NL
Contact:

Re: water level with ultrasonic distance meter - error readings

#15 Post by Ton_vN » 18 May 2019, 11:24

BME280 and MS5611 measure absolute pressure.
If you want to measure the difference in pressure caused by a liquid column, then you need 2 sensors:
- sensor A to measure the 'liquid pressure'
- sensor B to measure the atmospheric pressure as reference.

MPX5050DP as a differential pressure sensor would principally eliminate the need to have the reference for the actual atmospheric pressure:
nicely simple ......
It's range of 0 ~ 50kPa (=> 0 ~ 500hPa) allows measurement till great depth under surface.
On the other hand, it's sensitivity of 90mV/kPa is a weak aspect vs. the mightly 1V/kPa of the MPXV5004s over their limited range of 0 ~ 4kPa.
True, how deep & how accurate do you want to measure?

Barashur
Normal user
Posts: 3
Joined: 25 Apr 2019, 15:23

Re: water level with ultrasonic distance meter - error readings

#16 Post by Barashur » 22 May 2019, 22:01

seb82 wrote:
05 May 2019, 18:40

For fuel tank:
- HC-SR04 was seeing the walls (too large beam), not adequate

.........

@Barashur, I would suggest to try first one of Maxboxtix EZ4 sensor or maybe its copy GY-US42V2 from Aliexpress
Thank you for suggestion.

With HC-SR04 you are correct. After several days of testing I found out that the probelm is too wide beam on all of ultrasonic sensors i had. After few tests I found out that sensors were picking up some little vertical plane which is running around whole tank. It was like 1-2cm wide, probably used as tank stability enhancement. But those 2cm were enough for mess up with the measurements.

I was thinking how to narrow the beam and I tried to buy a plastic vuvuzela. I used only middle part. And it worked suprisingly well. My sensors are picking up right measurements in around 80% the time, this is something I solved with NodeRed functions (High Filter).

Image

This solution is functional but I dont like it since its not clean. I definitelly try that CY-US42V2.



One more thing, someone wrote above that I will have problems with battery due voltage decreasing. I used step-up regulator for such purpose, in my case if the voltage is 2-4,8V on the input, the ouput has always 5V. Even if the nominal value on 18650 battery is 3,7V, the largest voltage I measured was 4,2V when the battery was fully charged. I assume there would not be the case that there will be more that those 4,8V.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests