Let's Make Robots!

How to improve Sharp GP2Dxxx sensors

Show how to improve the output of analog sensors


The Sharp GP2Dxxx family is often used in robotics as distance sensors because the sensors are cheap and everywhere available. The normal use of these sensors is for the automatic flush of a restroom urinal, not for robotics.

The following sensors with analog output exists:

  • Sharp GP2Y0A02YK has a range from 20..150cm
  • Sharp GP2D12 (replaced by GP2YA21YK) has a range from 10..80cm
  • Sharp GP2D120 has a range fro  4..30cm

Using analog sensors in robotic environment isn't as easy as it's seems. When you attach the Sharp sensor output to an oscilloscope you'll see a noisy signal with a lot of spikes.


The solution for this problem is really simple. Add a capacitor of 100nF between VCC and GND to eliminate the spikes. A second capacitor of 10..100µF will eliminate most of the bounces from the output signal. The capacitors must be connected as close as possible on the sensor. The following pictures shows a solution with SMD capacitors.

More Tips:

  • The housing of the Sharp sensors is conductive. If your robot has a metallic chassis, you should isolate the housing from the chassis.
  • The output signal of the sensor isn't linear. Especially at a closer distance, closer than the specific sensor minimum , you can't get any useful signal.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Off topic question: why does your video refer to the node with the LMR logo, or is that just copy pasta?

Damn, I just noticed that, too. Thanks for the info.

I had actually got better readings connecting the sig line and gnd with a cap when I was doing my tests...The readings were quite less erratic at least...

What cap did you use to do that?

I read in some notes from Sharp that you shouldn't use a cap on the signal line and ground, because it will screw with your readings too much. I cant remember I read that though. I'm guessing you dont have that problem?

The datasheet says to use a 10uF between GND and V

I've used 100-330 when I tested it.

I'm not sure how it'll screw with the readings, but sure, I guess it could slowing down the speed at which the reading would be at the point of reading if it were in a transition.. When comparing distance values, they were all within the spike level when not using a cap.

For me it was a noticable difference between the servo being jumpy and having minial updates to it's position.

EDIT: I don't have a scope to show my readings so my data proof would be showing readings from two controled tests...though if anyone with a scope wants to try it...they would probably get more detailed data.  :)

you mean 100-330 nF or 100-330 uF??

I thought I added that...it was uF.

I'll give it a try this evening. IMHO a 100..330nF cap on the output will eliminate the spikes, but not the bouncing of the signal. A 100..330µF cap on the output is a no go.

I fought these things forever it seemed, back in the day. The noise was preventing my RF RX from working. I knew there was noise, I know caps smooth things out, I had no idea how much... The o-scope makes things so clear!

Great post. Too bad they don't make these things anymore.

Only the old models like the GP2D12 will be discontinued, because there are non RoHS conform (not lead free).