Maker Pro
Maker Pro

Eliminating ping sensor noise on an arduino

liomry

May 7, 2012
16
Joined
May 7, 2012
Messages
16
Hi all,

So I have a ping sensor (HC-SR04) which I'm using as a rangefinder for my robotics project. Everything is working but I seem to be getting odd readings every couple of pings which I think is due to noise on the circuit. I've tried adding a 100nF ceramic capacitor across the 5v / ground as shown but that seemed to stop the ping from going beyond 12cm. Any ideas ? (I've tested the code and sensor when it's the only thing plugged into the arduino with no issues)

If it makes a difference the arduino is sharing a 9.6v power source with a Raspberry Pi, maybe I need to put an electrolytic capacitor somewhere in that circuit?

The 5v for the ping sensor is coming from the Arduino +5v rail.

Currently on the Arduino I have this sensor and a serial connection to the Raspberry Pi. This serial connection is being used at every ping to report the distance measured.
 

Attachments

  • ping.png
    ping.png
    2.4 KB · Views: 183

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Have you considered taking multiple readings and ignoring any outliers?
 

liomry

May 7, 2012
16
Joined
May 7, 2012
Messages
16
Hi Steve, thanks for getting back to me,

I have considered this but it's a case that every second reading is incorrect, therefore if I drop one reading or if it picks the wrong group to start with the majority return will be incorrect.

Incidentally the incorrect reading seems to start at 66cm and then very slowly drop towards 0, I've seen it reach 59cm within ~ 8 mins. This is what leads me to believe that there's something funny with the circuit, maybe ground isn't 100% free of current?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
You could try adding a (say) 10uF capacitor in parallel with the 0.1uF capacitor. It may help if the problem is noise.

I have one of these devices, but I haven't ever played with it.

Have you considered that it might be a bug in your code? If it happens every second reading, it sounds too regular to be random.
 
Top