I'm working on something that involves a lot of ultrasonic sensors. I had a few HC-SR04s but a few were defective and so I ordered a few more. The new ones appear to be a slight revision, but they still act exactly the same way and are plenty accurate... except when something is out of range.
Note, my code is only meant to read up to 3m - beyond that doesn't really matter to me.
When I either cover up the trigger transducer, or, if something is very far away, the value spikes between 3m and somewhere between 0-90cm. This does not happen with my old sensors, but ALL of my new ones appear to be doing this. It's difficult to correct this because what if something really does jump in front of the sensor and is actually less than 100cm away?
To ensure it wasn't my code, I tried using pulseIn with the default timeout, which is pretty long. This does the same thing. I don't think the sensors are defective, because they do actually accurately read when something is in range.
Any idea why this is happening and what I can do to prevent it?
PS: Sorry if this has been asked before. I'm not really sure how to search for this problem.