Go Down

Topic: Ultrasonic distance sensor HC-SR04 lack of timeout problem (Read 55729 times) previous topic - next topic


I ran into this today while putting together a blog video for how to daisy-chain my little octosonar board to drive 12 of these little buggers with my sonari2c library (apologies for the plug).

I prototyped all this using SR04s I bought last year from somewhere in China (not banggood - it's not in my purchase history there) and it all works just dandy. Those units don't look like either of the ones pictured above.

The new ones I *did* get from Bangood recently and look like the "bad" ones above (same circuit, narrow silk screen) and my tests/demos were locking up occasionall (I was blaming it on wiring). I finally got to the bottom of this today (reproduce 100% by putting thumb over sensor) and google found this thread.

The most obvious difference between my "good" ones and the "bad" ones is the "bad' ones have 10K pullup resistors on Trig and Echo. My "good" ones do not - very high resistance between Trig, Echo and Vcc,Gnd.

The "good" and "bad" ones above both seem to have the pullups (R1/R2) so they are clones. Sometimes clones have different component values due to the cloners not being as good as the dudes on Kamino.

I tried tying the Echo to ground - seemed to clear it, but I can't do that through my board, nor can I flap the power.

While debugging I connected echo to the LED on my protoshield so I'd have a visual indicator. Bingo. Problem cleared right up. The protoshield has an inline resistor with the LED, but I figured these pulses are short, so how about just connecting a LED directly across Trig and GND. Seems to work....

Can someone else try this and verify?

Also can the guy with the good and bad clones check the resistance on r1/r2 on the "good" ones? I suspect they may be more than 10k i.e. weaker.

Update: I tried a variety of LEDs direct connect and they did not all work. The little red ones with 1.6V forward voltage did not lock up my board, but did not give a signal back from the rogue sensor either - probably pulling the voltage too low for the logic gate.

The rest seem to be 2V forward voltage and work direct without a resistor. All the LEDs fix the issues with a 220 ohm series resistor.

I was thinking of putting blinky activity LEDs on the next version of my board anyway, I think this clinches it.

Why does this work? No idea.


I take it back about the clone thing and cheaper components. A closer squint at the picture DaveEvans posted on Oct 10 tells me these are a clone with fewer components. The overall circuit layout looks almost identical, but there are a lot less capacitors.


Is that an LED and resistor on each sensor?


yes, attached between the sensor echo and ground. I just tried a 1k resistor (no LED) and that worked too.


It occurs to me that those 10K pullups may be supposed to be 10k pull-downs. I got some protoshields last month that had one of the tracks mis-designed and connected Vcc direct to Groun, so dumbassity like this definitely happens in the knock-off world.

If someone could check that on the "good" ones it might explain a lot.


How to solder diode to prevent locking problem. Almost any diode will go (no need such big one, i just didn't have other in my inventory).


How can I Stop the measurement of ultrasonic sensor.... during program ruining.....please help me


Mar 23, 2018, 04:50 am Last Edit: Mar 23, 2018, 04:58 am by arielnh56 Reason: adding picture of sensors I use, as they differ from the ones previously shown
I was updating my tindie text for these sensors and came back here and realized I had never come back and listed the solution found to this issue.

My sincere apologies. Open source is give and take, not just take.

many thanks to @jlmyra above for figuring out the actual cause - and persuading me by this action to buy an oscilloscope. http://www.bitscope.com/product/BS05/

The bad sensors raise the echo pin when they don't get a response. They never time out. Period. In brief: avoid.

They do reset the echo when a new cycle is started, so they are not a completely lost cause, once their behavior is understood.

The data sheets say that the timeout from no response is 37ms. While this may have been true for the original HC-SR04, the observed value for the not-bad clones is between 150ms and 200ms. So even with the "good" sensors my original octosonar board was getting interference between adjacent sensors when there was no echo as that sensor would still be hanging up the pin when the next one came active after the 50ms rotation period. This was patched in software to force a wait until the pin dropped.

The revised version of my "OctoSonar" board uses tri-state buffers to isolate the echoes from each other entirely and enforces a sensible 50ms (software changeable) time window to each sensor, eliminating the lockups and delays above, regardless of whether the sensor is one of the "good" or "bad" ones.

The "good" sensors I use have a different board layout from either of the ones shown in port #70. They are distinguished by having the passive components arrranged in two vertical rows.

Go Up