How to improve Sharp GP2Dxxx sensors

gp2d12-small.jpg

Indroduction:

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.

Solution:

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.

gp2d12-2.jpg

sharp.png

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.
https://www.youtube.com/watch?v=fgmQ4G8u1pg

Nice traces!

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,

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

I had actually got better

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…

Nice display of data there.

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.

What type of cap?

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

Only the old models like the

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

just i need

hi.

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’ve used 100-330 when I

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.  :slight_smile:

100-330

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

I’ll give it a try this

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 thought I added that…it

I thought I added that…it was uF.

i have just tested with the

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

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

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

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 tested it and it doesn’t work

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:

sharp-noise-setup-01.jpg


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:

sharp-noise-setup-02_small.jpg


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 :wink:

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: https://www.robotshop.com/letsmakerobots/files/userpics/u8860/sharp-noise-cap-placing-01.png):

sharp-noise-cap-placing-01_small.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

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

No problem

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

 

"The normal use of these

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

<snip>

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?