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.
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.
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.
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
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’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.
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’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
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).