- Mon Mar 02, 2015 8:25 am
#180154
I've got a project where I'm going to be using a large number of ultrasonic rangefinders, so I bought a few HC-SR04s to test them out since they are very low-cost. In general they work well. I'm testing them with the NewPing Arduino library and when an object is in range, they're accurate enough for my application.
The modules have 4 pins: VCC, Trig, Echo, and GND. You're supposed to give the Trig pin a 10uS pulse, and the Echo pin is supposed to go high and remain high until the ultrasonic burst comes back, then it goes low. The length of time the Echo pin is high corresponds to the distance.
The problem occurs when the ultrasonic burst never comes back (you aim it into space, a block of foam, etc.). When this happens, the Echo pin stays high forever and there doesn't appear to be a timeout. Even if you pulse the Trig pin again it still keeps Echo high, waiting for the response. You can trick it into thinking it got a response by tapping the receiving transducer can with a screwdriver or something, but other than that it seems like power cycling the module is the only thing that works.
What confuses me is that these sensors are sold everywhere and people don't seem to have issues (except for a few posts I found that didn't offer a fix). I've bought some from a few different places now, and they all have this problem.
Can anyone who has one of these confirm this behavoir? Is there something special you're doing to get them to timeout properly?
Thanks!
The modules have 4 pins: VCC, Trig, Echo, and GND. You're supposed to give the Trig pin a 10uS pulse, and the Echo pin is supposed to go high and remain high until the ultrasonic burst comes back, then it goes low. The length of time the Echo pin is high corresponds to the distance.
The problem occurs when the ultrasonic burst never comes back (you aim it into space, a block of foam, etc.). When this happens, the Echo pin stays high forever and there doesn't appear to be a timeout. Even if you pulse the Trig pin again it still keeps Echo high, waiting for the response. You can trick it into thinking it got a response by tapping the receiving transducer can with a screwdriver or something, but other than that it seems like power cycling the module is the only thing that works.
What confuses me is that these sensors are sold everywhere and people don't seem to have issues (except for a few posts I found that didn't offer a fix). I've bought some from a few different places now, and they all have this problem.
Can anyone who has one of these confirm this behavoir? Is there something special you're doing to get them to timeout properly?
Thanks!