Hi!
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:
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?
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
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.
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.