Ultrasonic range finder behaving oddly

Thread Starter

MrSoftware

Joined Oct 29, 2013
1,559
My ultrasonic range finder is giving bad measurements and I'm trying to figure out if the problem is electrical, or physical (sound transmission though the PCB), and how to fix it. Suggestions are welcome!

Data sheet: https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf

A 10us pulse on the trigger pin initiates a sound burst. A short time later the echo pin goes high for a duration that is proportional to the distance the sound had to travel. This sequence repeats at about 16Hz. The problem I'm having is that the sensor is acting as if there is an object directly in front of it (very short echo pulse), UNLESS I do ONE of the following:
  1. Place a finger firmly on top of the PCB
  2. Lower the input voltage (Vcc) down to about 3.4V (specification is 5v)
  3. Continually wiggle it around in the breadboard until I get it in just the right position.
So I'm trying to figure out if the problem is electrical, or physical. It's wired directly to an Arduino, using the 5v output from the Arduino as Vcc.

When it's not working, the echo reads as if there is something directly in front of it, even when there is nothing in front of it. Here's a scope picture. The short blue pulse is the trigger, the yellow is the echo indicating the object is a couple of inches away, even though the object is much much further:

DS2_QuickPrint21.png

This is what I do to make it work:
upload_2017-2-2_22-32-32.png

And this is what it looks like on the scope when it's accurately measuring distance, notice the longer echo:
DS2_QuickPrint22.png

Here's how it does not work, unless I do one of the things listed above:
upload_2017-2-2_22-32-2.png

Any thoughts?
 
Last edited:

GopherT

Joined Nov 23, 2012
7,983
You have to make sure a trigger pulse times out before retriggering it (if no echo is sensed).


About 50 milliseconds. If you retrigger too soon, there are some issues. There are a few different encarnations of this model. Connect it to a scope and make sure it is never triggered while waiting for an echo. Some can be retriggered and get confused, some have non-retriggering circuit so it is impossible.
 

Thread Starter

MrSoftware

Joined Oct 29, 2013
1,559
Thanks for your comment. I am waiting 60ms between triggers.

When it's giving bad readings, I can watch the scope and it does still measure distance in the range up to about 2-3" from the sensor (the echo duration changes as I move the object), but if you keep moving the object away it just continues to report the distance as just a couple of inches, as shown in the first scope screen shot above. When it is working, it will measure longer distances just fine as you move the object away.
 

panic mode

Joined Oct 10, 2011
1,782
well it looks to me that distance is at best couple of inches until you get reflection. try positioning your breadboard on the edge of the desk to avoid reflection from below...

this is not laser distance sensor - sound beam is conical in shape... front area increases with distance
 

GopherT

Joined Nov 23, 2012
7,983
Thanks for your comment. I am waiting 60ms between triggers.

When it's giving bad readings, I can watch the scope and it does still measure distance in the range up to about 2-3" from the sensor (the echo duration changes as I move the object), but if you keep moving the object away it just continues to report the distance as just a couple of inches, as shown in the first scope screen shot above. When it is working, it will measure longer distances just fine as you move the object away.
Then you may be getting multiple reflections and the further one is coming in shortly after you fire the next. Use a large target at 90-degrees to incoming signal as a test (or move to bigger open space).

If that doesn't work, I'm out of ideas.
 

Thread Starter

MrSoftware

Joined Oct 29, 2013
1,559
Thanks guys, I'll keep playing until I figure it out. When it's working correctly it works fine whether it's in the middle of my desk, or on the edge. But when it's not working, it shows something nearby no matter where I put it, even if it's pointed up at the ceiling. I'll have to wrap it in something soft, and then try soldering the wires instead of using the breadboard. Maybe that will help determine if it's physically resonating, or having an electrical issue.
 

Tonyr1084

Joined Sep 24, 2015
3,577
Peanut gallery here:

If you have to place your finger on it to make it work then either there's a bad solder joint OR your breadboard is causing some intermittent interference, which is negated by the presence of greater pressure on the connection(s). Try a different BB if you have one or reassemble it on the opposite side of the BB.

I have considerable experience with solder joints. Been an inspector over 30 years and have been IPC certified (yeah, bragging a bit about nothing). I remember whacking the side of my old TV (when I was a kid) to make it work. The problem? A bad solder joint. A neighbor gave me a "Haunted" TV. Laughed my arse off at that one. It had two issues: Horizontal, and 15 minutes after turning it on it would turn itself off. 15 minutes EXACTLY! So I knew I had to reflow the solder joints on the horizontal circuit and shut off the sleep timer.
 
Top