teckel:
Pin 13 was my first guess as to the cause of the problem as there's an LED attached to it. I've been suggesting to people to try different pin assignments and changed the default sketch to use pin 12 and 11 for a few weeks now.
Ok. I didn't come across that. I see that you did switch your sketch example at some point to use pin 12, but I'm sorry if I missed a general message about using different pins. In my case, because the "minimal pair" test was with NewPing vs without NewPing, NewPing itself appeared to be the issue, not the pin allocation.
teckel:
With that said, I didn't ask you specifically not to use pin 13 for two reasons. First, pin 13 works fine on the Uno and we both assumed you were using the Uno at the begining. Secondly, the sketch you linked to at TrollMaker.com is for sale | HugeDomains also uses pins 12 and 13. So, to totally close this case, were you using the exact trollmaker sketch including using pins 12 and 13 or did you use that sketch but with different pins?
I used pins 12 and 13 with both NewPing and the linked sketch. On the Duemilanove, it worked unless I used NewPing. On the Uno R3, it worked in both cases. If I switch from pin 13 to pin 11, the Duemilanove works with NewPing.
teckel:
The TestF library is basically exactly the same as the trollmaker sketch. If the Duemilanove really can't use pin 13 as a input, it shouldn't be able to with either the NewPing library or the trollmaker sketch (as it uses pin 13 for input).
I didn't try that one at the time, since the pin switch resolved the problem I was having, but I just re-did the baseline tests now using the test sketch you sent me a couple of days ago to report timings.
Linked sketch with pins 12 and 13, Duemilanove = works
"TestF" NewPing library with pins 12 and 13, Duemilanove = works
v1.4 NewPing library with pins 12 and 13, Duemilanove = 0cm, 0uS
teckel:
I don't ever remember seeing false positives or false negatives. For example, if I put an object a foot away from the sensor it will show a distance every time. It may fluctuate a bit as far as the distance, but will never give a 0 reading. Likewise, if I set the maximum distance at 200cm and have it ping out at a wall that's 15 feet away, it will always get a 0 reading. Some, have incorrectly interpreted this as incorrect. But, this is the correctly designed behavior. You wouldn't want the sensor to report back 200cm when there was something 400cm away as you've set the sensor to only listen for objects 200cm away or closer. A reading of 200cm would tell you that something is 200cm away, when there is not. Any object beyond the specified maximum distance is returned as 0, which means "all clear". It's slightly different with the timer interrupt method as we don't create an event unless there's something in-range.
I understand that 0cm is the return value for "out of range." As I explained to someone else in this thread, the sensor couldn't actually hear a ping from an object 0cm away, because it would either be blocking the emitter or the receiver, so 0cm makes perfect sense as "out of range."
At least one other person posted output from a run where he was getting values in the ~50cm range, with a 0cm value appearing anomalously. This mirrors the false negatives I've seen. The false positives are rarer, but they do happen, at least to me.
Even if your sensor/board/sketch/pin combination does not produce false positives or negatives, a digital filter is useful beyond that. If the only thing you want to do is leap to action as soon as the sensor state changes from out of range to in range, or from in range to out of range, that's one use case. Another use case is acting upon a "steady" state of some sort. In my case, aiming the distance sensor at my head while I walk on a treadmill, I don't want the sensor to leap to action as soon as it can't see my head. I may be leaning over to pick something up for a second, and I don't want it to conclude that I'm not walking anymore and shut the treadmill off.
teckel:
I used the below sketch with your HC-SR04 sensor. It does VERY fast pings and displays a "." if it gets a ping within 200cm or an "0" if it gets no ping (zero). It displays it in 80 columns so a lot of data can quickly be looked after the test is complete. Each line ends with the ping microseconds for the final ping (kind of a test to make sure you're understanding what it's showing).
I'll give this a shot and report back. I'll try both "easy" objects like fixed-position objects with simple geometry and tricky objects like my moving head (about 60cm away from the sensor).