Consistency with HC-SR04

I'm sure this is no surprise, but I'm having some consistency problems with the HC-SR04 ultrasonic sensor that I bought on ebay for $2.00.

My project uses the sensor set on top of a servo, I have the servo pan 180 degrees, taking a range reading at each degree, and then it will continue to scan back and forth to detect anyone approaching (change in distance at each degree as compared to original scanned difference). Getting a lot of false readings.

I've noticed that it seems to work better when I'm running it off a freshly charged 9v, so I'm guessing that consistent power is the issue. Currently it runs straight off the power from the arduino uno (via a motorshield). Does anyone have some experience with making this thing work right? Would I be better off with a dedicated power source for the sensor? Would capacitors in the line help? Is the product just such a cheap piece of garbage that it will never achieve the kind of consistency that I'm looking for?

How fast are you sweeping the servo? How fast does your SR04 take measurements? I would take a good look at that...

My code gives the command to move the servo one degree, delay 20, scan for range, delay 20... then rinse and repeat. (badji, based on the project you just posted on LMR I know you're a huge fan of "delay" :slight_smile: )

My reason for thinking this is a power issue is that I've noticed that the sensor works far better when running off a freshly charged battery. Back when I was just using the sensor to test proximity in my obstacle avoiding robot, the bot would continually act as though there were an obstacle in front of it unless I had a fresh battery hooked into it (as opposed to one with plenty of charge that I'd been using for a while).

First, use my NewPing library for the ultrasonic sensor. Secondly, I'm not a fan of using a 9v battery to power an Arduino. Instead, use 2S LiPo batteries. You can get a 1000mAh for $3-$4 from a company like Hobby King. Or, much larger batteries if you need to power your "off the grid" project for a longer time.

In any case, I'm not surprised that it's not working with a 9v battery. Try the project with a proper power supply and see if it works. If so, it's the 9v.



Just quickly glanced across your ping library page and I think that using that will greatly improve the performance of my robot/killing machine.

I'll try out a 2S Lipo battery pack (I think they have a whole wall of them at the radio shack here in town). I've been using 9V's and AA's because I understand them and as I work through this project I've been trying to build off things I already know and learn just one new thing at a time. I think I'm getting familiar enough with batteries that I can step it up a notch.

Thanks for the help!


Thanks for the posts! I have been frustrated with a similar inconsistency in my ultrasonic sensors performance and assumed that I just got a faulty unit. I never considered the supply power (should have been obvious since it seemed to get worse when using it in conjunction with a servo...). Guess it is time to pick up some LiPo batteries!

Thanks again!