hrgdavid
Posts: 15
Joined: Thu Jan 05, 2012 10:39 pm

Ultrasonic sensor readings become unstable

Tue Mar 05, 2019 1:58 pm

Hi,

I am using an ultrasonic sensor to measure the water level in an external water tank. The sensor board is in a watertight plastic box connected to the Raspberry Pi (in the house) via about 20m of cat5 cable. I take 10 sensor readings every minute, drop the largest and smallest and write the mean of the remainder to an RRD file.

This program runs perfectly - all 10 readings within 3% of each other - 24x7 for a few weeks. After that it starts getting an increasing number of readings that are just over twice the correct reading. (Correct reading 24.xxxx; errors: 51.xxxx). Although the number of readings in error generally increase over time, there are periods of hours where the readings remain accurate. Eventually, over a period of a few days, most readings are in error (twice the correct value).

Rebooting the pi does not resolve the problem. Unplugging and leaving it for a few days *does* fix it - until it returns again a few weeks later.

I also have a temperature/humidity sensor in the box and whilst that does not return wrong values; after a similar period of time, occasionally it just does not return any reading at all.

I have included some sample values below.

Does anyone have any idea how I can troubleshoot this further ? Is it possible a build up of static inside the plastic box could cause this ?

Thanks for any help !


24.756825
24.73981
24.246375
24.73981
24.756825
24.756825
24.67175
24.67175
24.756825
24.246375
Time 05-Mar-2019 13:25:35 Value: 24.74 Confidence: 97% Temp: 9.5*C Humidity: 91%
24.246375
51.130075
51.130075
24.654735
24.756825
51.14709
51.130075
24.756825
24.756825
51.130075
Time 05-Mar-2019 13:26:35 Value: 24.76 Confidence: -6% Temp: 9.5*C Humidity: 91%
51.130075
51.130075
51.130075
51.130075
25.097125
51.130075
51.130075
51.130075
51.130075
51.130075
Time 05-Mar-2019 13:27:35 Value: 51.13 Confidence: 100% Temp: 9.5*C Humidity: 91%

Idahowalker
Posts: 445
Joined: Wed Jan 03, 2018 5:43 pm

Re: Ultrasonic sensor readings become unstable

Tue Mar 05, 2019 2:04 pm

If you could, use 2 ultrasonic sensors and compare readings.
Without knowing why you are deleting my postings, I will not know how...

User avatar
B.Goode
Posts: 8553
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Ultrasonic sensor readings become unstable

Tue Mar 05, 2019 3:16 pm

A couple of 'stretching the envelope' ideas for you to consider -

You don't say anything about what the ultrasonic sensors are. A model number, or web link. Are they certified for use over a 20 metre cable run? (Maybe that makes them work too hard to drive a signal back to the RPi, and over time they break down?)


'Ultrasonic' implies sound waves. Could it be that there are some circumstances/situations that arise within the tank that give false echoes via multiple paths back to the detector? Or strong harmonic distortion? Like the way a guitar string resonates at fractions of 0.5 of its fundamental length?

User avatar
mikronauts
Posts: 2722
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Ultrasonic sensor readings become unstable

Tue Mar 05, 2019 3:24 pm

I am amazed it worked as well as it did for you, as triggering the sensor and reading the result over 20m of cable is a bad idea.

Put a pi close to the sensor, and have it report the watet level in a loop over wifi or ethernet.
hrgdavid wrote:
Tue Mar 05, 2019 1:58 pm
Hi,

I am using an ultrasonic sensor to measure the water level in an external water tank. The sensor board is in a watertight plastic box connected to the Raspberry Pi (in the house) via about 20m of cat5 cable. I take 10 sensor readings every minute, drop the largest and smallest and write the mean of the remainder to an RRD file.

This program runs perfectly - all 10 readings within 3% of each other - 24x7 for a few weeks. After that it starts getting an increasing number of readings that are just over twice the correct reading. (Correct reading 24.xxxx; errors: 51.xxxx). Although the number of readings in error generally increase over time, there are periods of hours where the readings remain accurate. Eventually, over a period of a few days, most readings are in error (twice the correct value).

Rebooting the pi does not resolve the problem. Unplugging and leaving it for a few days *does* fix it - until it returns again a few weeks later.

I also have a temperature/humidity sensor in the box and whilst that does not return wrong values; after a similar period of time, occasionally it just does not return any reading at all.

I have included some sample values below.

Does anyone have any idea how I can troubleshoot this further ? Is it possible a build up of static inside the plastic box could cause this ?

Thanks for any help !


24.756825
24.73981
24.246375
24.73981
24.756825
24.756825
24.67175
24.67175
24.756825
24.246375
Time 05-Mar-2019 13:25:35 Value: 24.74 Confidence: 97% Temp: 9.5*C Humidity: 91%
24.246375
51.130075
51.130075
24.654735
24.756825
51.14709
51.130075
24.756825
24.756825
51.130075
Time 05-Mar-2019 13:26:35 Value: 24.76 Confidence: -6% Temp: 9.5*C Humidity: 91%
51.130075
51.130075
51.130075
51.130075
25.097125
51.130075
51.130075
51.130075
51.130075
51.130075
Time 05-Mar-2019 13:27:35 Value: 51.13 Confidence: 100% Temp: 9.5*C Humidity: 91%
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

hrgdavid
Posts: 15
Joined: Thu Jan 05, 2012 10:39 pm

Re: Ultrasonic sensor readings become unstable

Tue Mar 05, 2019 7:01 pm

Thanks for all your replies.
If you could, use 2 ultrasonic sensors and compare readings.
I could - but I'd have to get another sensor and control board and do a lot of re-configuring. Not sure what it will show though - if they both have similar errors, what would that mean ? i guess if the second one continues to work (for longer than a few weeks) then it would point to a sensor/board error with the first one. Will try this if the last option below doesn't work.
You don't say anything about what the ultrasonic sensors are. A model number, or web link. Are they certified for use over a 20 metre cable run? (Maybe that makes them work too hard to drive a signal back to the RPi, and over time they break down?)
It's one of these: https://www.ebay.co.uk/itm/1Pcs-Waterpr ... SwZKRbMXbn
'Ultrasonic' implies sound waves. Could it be that there are some circumstances/situations that arise within the tank that give false echoes via multiple paths back to the detector? Or strong harmonic distortion? Like the way a guitar string resonates at fractions of 0.5 of its fundamental length?
It's possible ! There's a water pump in the tank that pumps when we turn a tap on. But there doesn't appear to be a correlation between the pump working and the sensor giving incorrect values. At first I only get one of two incorrect readings and then slowly, over a period of days, they build up until nearly every reading is incorrect.
I am amazed it worked as well as it did for you, as triggering the sensor and reading the result over 20m of cable is a bad idea.

Put a pi close to the sensor, and have it report the watet level in a loop over wifi or ethernet.
Yes, I was impressed that it worked over that distance, but it did - and like I say, is reliable for a few weeks - but eliminating the cable length is a good idea. I'll have to get a waterproof box for the pi and see if I can use POE to drive it.

Thanks again for all the ideas.

pcmanbob
Posts: 6939
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Ultrasonic sensor readings become unstable

Wed Mar 06, 2019 2:08 pm

looking at the link for the sensor you are using it states
Farthest distance: 4.5m
Blind: 25cm
now I am wondering does that mean that distance measurement under 25 cm is no possible ?

looking at your results your problems seem to start when your measured distance gets down to the 25-24cm range. :?
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

hrgdavid
Posts: 15
Joined: Thu Jan 05, 2012 10:39 pm

Re: Ultrasonic sensor readings become unstable

Thu Mar 07, 2019 4:49 pm

now I am wondering does that mean that distance measurement under 25 cm is no possible ?
I tested it when I first got it and it appears to measure accurately down to about 21/22 cms so I think that's okay.

I went to the water tank yesterday whist it was still reporting incorrect readings and simply pulled out the LAN cable (that it uses to transmit the readings back to the house) on the sensor box and plugged it back in. The readings immediately corrected and since then I've had no issues.

So, I'm sure the problem is related to that box. The LAN cable clicks into a LAN socket and was in securely (and it's a waterproof socket). I'm fairly sure it's not a connection issue otherwise I think I'd get more random results.

Could it be something to do with a static build up ? That might explain the slow build up of incorrect readings and apparent quick fix when I touched the cable. I really don't know enough about static to know what/how it could impact the readings or how I can avoid it (earth cable?). Next time it happens, I'll simply touch the LAN cable without removing it and see if that fixes the problem.

Thanks for your help.

Idahowalker
Posts: 445
Joined: Wed Jan 03, 2018 5:43 pm

Re: Ultrasonic sensor readings become unstable

Sun Mar 10, 2019 3:51 pm

Is the LAN cable shielded? Try grounding the shield at only the Pi end to turn the shield into a cap that can absorb spurious signals. If the LAN cable is not shielded then try wrapping a small wire around the outside of the LAN cable. You would wind the wire in tight coils at each end and towards the middle you can spread the coil out a bit. I'd start off with grounding just the Pi end.

I'd also find out the ohm value of the length of the cable, most especially the ground wire. If the wires ohms out to more then, say .1 ohm, your wire(s) is too small for the distance given.
Without knowing why you are deleting my postings, I will not know how...

Return to “Automation, sensing and robotics”