NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.7

Hi! Thanks for your reply.

teckel:
I have (4) HC-SR04 sensors and they all work just fine with the Arduino Uno R3 using every library version of NewPing as well as every example sketch. I've also run with Arduino 0023, v1.0 and have just switched to v1.0.1 all of which work. So, I believe it's unfair to say "I get 0cm like everyone else with an HC-SR04 reported". There's only a couple people that have reported a problem, it's running just fine for me with 4 different sensors, so not everyone is having a problem.

You're right - it was a poor choice of wording. I didn't mean to imply that every HC-SR04 owner had the "0cm" bug. I was trying to say that I had the same "0cm" bug that was reported here by other HC-SR04 owners. And it's certainly hard to diagnose problems like this if your HC-SR04s aren't showing the problem. Did you get them all from the same vendor?

teckel:
There's differences between my example sketches and the sketch at the link you provided. For example, it's only doing 2 pings a second while my examples are typically doing 20 pings a second. So, maybe your sensor can't ping that frequently. To diagnose this, I've modified my example sketch to duplicate what that other example is doing.
...
If this still doesn't work, it could be the VERY long trigger delay in the example you provided. It's waiting 1000 microseconds when the sensor specs state it should only require 10 microseconds. If your sensor is way out of spec, maybe it needs longer than 10 microseconds. To change this in the NewPing library, look for the "delayMicroseconds(10)" in the NewPing.cpp file (line 48 in the 1.4 pre-release) and change it from 10 microseconds to 1000 microseconds.

If it still doesn't work, try changing the MAX_SENSOR_DELAY in the NewPing.h file from 18000 to 180000 (add a zero at the end). This will give your sensor more time to finish the ping before waiting for the echo. The longest I've ever measured is around a 17000 microsecond delay, but maybe your sensor requires longer.

I will look at that. I tried this investigation from the other direction, modifying that sketch I provided to do 20 pings per second with a 10 microsecond trigger delay. It still works in that sketch. Those two timings do not appear to explain the difference in behavior with NewPing. I will try changing MAX_SENSOR_DELAY in NewPing to see if that is a factor.

teckel:
If it's still not working for you, you could send me your sensor. If I had the sensor, I could hopefully duplicate it and see what exactly is happening. Of course, I'd send it back when I was done with the diagnosis.

I may be able to do that, since I did buy a second sensor to try to compensate for the HC-SR04's occasional lie. (Sometimes reports out of range value when there is definitely something in range; sometimes reports in-range value when there is definitely nothing in range.) I'll also try my second sensor to see if it does or doesn't have the problem, but it appears to be the same exact build, and it's from the same reseller (so it may even be the same batch). I'll report back what I find.