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

teckel:

snailshoe:
I am having the same problem with two of my HC-SR04s. All I'm getting is a reading of 0cm regardless of what's in front of the sensor. These sensors both work with a different ultrasonic library. Does anyone have an idea of what may be causing this?

First, try using the example sketch below, it's the new example that's being included with NewPing. Be sure you have the trigger and echo pins wired correctly. Don't change anything in the example, even the pins used.

Google Code Archive - Long-term storage for Google Code Project Hosting.

Also, when you say you have a problem with two sensors, does that mean you have other sensors that work and two that do not? I've found the SR04 sensors tend to have a terrible quality control. Of the 4 that I have, only 1 I would say works correctly. The other 3 work, but get all wonky at distances beyond 50cm.

Finally, just to make sure we're both using the same library, attached is my development version of NewPing (v1.4 pre-release). Just replace these files with the ones already in the NewPing folder.

Tim

At the moment, I only have the two sensors. There seems to be something wrong with one sensor. It works fine by itself, but as soon as I apply power to the second sensor, the reading of the first sensor shows that something is 5cm away. If I take power away from the second, the first sensor then works fine. With the new library and example sketch, everything else seems to be working. I'll have to get some more of the HC-SR04s and try them out.