Erratic measurements from Ultrasonic Ranger

Hello, I have connected my Ultrasonic Ranger to a Raspberry Pi 4 using the Base Hat. I installed and configured the Python 3 software as described in the wiki.

When I place the sensor face-up on the table, sometimes it will read stably at the correct value (about 210 cm). Other times it will bounce between the correct value and another value (say, alternating between 210 and 35 cm).

And when I mount the sensor on the wall, looking out into an empty room, where the far wall is greater than the sensor’s range, it generally gives very poor readings. Instead of constantly reading the maximum value (which seems to be about 533 cm), it bounces all over the place. For instance, it might bounce between 10 and 15 cm. After stopping and starting the script, it will bounce between 150 and 533 cm. Or 0 and 10 cm.

I have tested this with the code provided on the wiki and I have tried two sensors and multiple ports with the same result.

Am I missing something? Inside of about 50 cm, it seems to read accurately, but if it can’t see something in that range, it seems very unreliable. My use case is to detect if something walks within a certain distance of the sensor to start a video.

Any insight would be very helpful – thank you!

There will be such problems when Ultrasonic Ranger is used on Linux. The main problem is that Linux is not a real-time operating system, so it is impossible to accurately obtain the signal of Ultrasonic Ranger. @forceflow1049