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.

sparkfun has a few thousand in stock currently


excellent. I needed something, because these sensors have the bug that makes distance measurements fluctuate, so is more accurate.
thanks for the info tomorrow I approve this arrangement.

i have just tested with the oscilloscope my new sharp module

i do not have this issue

my readings are clear with or without caps on power rails


question: how did you provided +vcc to the sensor? battery? ac-dc adapter? or from a robot?



I've tested different sensors GP2D12 and GP2D120, all with the same output noise. Connected to a programmable DC power supply.

will this thing work if i connect the capacitor first on a breadboard and then connect the sensor through jumper wires..?

I've not tested it but I think this won't work. The caps should be as close as possible on the sensor power pins.

I'm having my own troubles with Sharp causing noise on the power lines. While trying to solve that I also tested if the placing of filtering capacitors makes a difference. My setup was like this:

1 = Test point 1. Power from 4 x AA NiMH cells to breadboard power rail.
2 = Test point 2. Power from breadboard to Sharp. Caps were here when they were placed on the breadboard

For placing caps on the Sharp I soldered two female pin headers to it first so I can easily try different caps. This is how it looked like:

Caps on Sharp. 100uF cap placed on pin headers and 100nF cap "holds on" to the other caps with its legs. Good enough for testing. Don't use on robots ;-)

For testing a Sharp GP2D120 was placed about 10cm away from a semiglossy cardboard CD Box. Here's what I got from my scope (you'll have to click the image to get readable pic or just click here: http://letsmakerobots.com/files/userpics/u8860/sharp-noise-cap-placing-01.png):

CH2 (cyan) shows voltage from Sharp's output. CH1 shows voltage from breadboard power line (+).

The first row has pictures when caps are placed on the breadboard. In pictures on the second row caps were placed on Sharp. Both rows have pictures at 500us/div, 5ms/div and 200ms/div on horizontal axis. As you can see from those pictures capacitor placing makes a big difference. When caps were on the breadboard there were over 1.5 volt spikes on Sharp's output. When caps were placed on Sharp those spikes were gone.

Conclusion: Placing of caps does matter! Like RobotFreak said: Place your caps as close to Sharp's power pins as you can.

Now if I only could get rid of that "square" noise on the power line (I'll start a new thread about that later).

Thanks nuumio, for this detailed description. That makes things more clear.

No problem. I'm writing a new post about that power rail noise right now (yeah, multitasking). Any suggestions to solve that are welcome :-)


"The normal use of these sensors is for the automatic flush of a restroom urinal, not for robotics.


Sharp GP2D120 has a range fro  4..30cm"


Why, exactly, is an inside range of 4cm  necessary in this case? who stands only 4cm from the urinal?