Ultrasonic sensor give false values

I'm currently using the ultrasonic sensor for my node red project to calculate distance.
Often it gives me the correct distance, but sometimes it sends a random value.
This is the sensor i'm using:


Any ideas on what could be wrong and how to fix it?

They are not 100% devices.
I usually take an odd number of readings, sort them into order and then take the middle value as the reading.

In my project i use the distance sensor as a "tripwire" to notify me when someone passes through. In practical use i set the sensor to transfer the data only: if msg.payload < value, so that way i exclude all the other data.
This doesn't work, considering the random values i get range from 38 all the way to 146.
Are there any easy methods to fix this?

How often can you sample and for how long a period will the distance be short?

I think i just have to realize that the sensor can't operate 100% and figure out a different way to solve the problem.
Thanks alot for fast replies :slight_smile:

You didn't answer the question. What is the fastest rate you can sample at, and how long would you expect the distance to be below the threshold? There may be a simple solution with a Trigger node if the sensor can be sampled quickly enough

I recieve data from the RPI-SRF Node every 0.2 seconds and i want to recieve the distances lesser than value 80 from the sensor.

the fastest i have been able to recieve data was 0.1 second before there were to much interference

what distance are you trying to measure?

There a great video showing a comparison of the HC-SR04 and two other sensors you might find useful viewing. It's by 'The Guy with the Swiss accent' here is the link.

If, with it going as fast as is practical, try checking for two (or more) in a row below the threshold. You can do that with a Trigger node.

It's a common misconception that in the IOT space these 'hobbyist' sensors will do the job. What is your application, what surface medium are you targeting(measuring), what distance(80?), ambient conditions? If you look at the datasheet for this product there is zero 'accuracy statement', no uncertainty of measurement. What this means is you can't rely on it (depends what you want of course) Industrial Ultrasonic Sensors have sophisticated algorithms to ignore 'bad measurements' maybe even sensor output lockout if its confused and cost many hundreds of GBP/USD. Even as an avid watcher of the 'Guy with the Swiss accent' - it's not really something he ever really discusses...things to consider is sensor path vertical or horizontal, vertical much more difficult due to possible temperature variations, is your target distance in the sensor range 'calibration sweetspot'? from memory these things are not linear and most inaccurate at the bottom of the range(close to Tx). I have not watched the video that zenofmud posted maybe some good stuff there.