Let's Make Robots!

How to improve Sharp GP2Dxxx sensors

Show how to improve the output of analog sensors

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.

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.

Here is a characterization of the Sharp GP2Y0A21YK Proximity Sensor using a Current Probe. Notice something odd?

32 Strobes of IR Measure

According to the spec, this device has a Typical Dissipation Current of 30 mA and a maximum of 40 mA. The measured value here is an average (mean) of 114.5 mA! Yes, I can see that I haven't adjusted by vertical timescale to only take in one period of measure, ie only 32 pulses and the dead time inbetween, but even the minimum value is still way above the specified value. 45 mA vs 30 mA typical.

One of the single strobes is shown here:

Single Strobe of IR Measure

The following was taken from the output of the sensor (white wire). Note what occurs to the output values from the sensor when the reading is being made. This is why this sensor's output should always be sampled several times and averaged, taking care to throw out the values that are out of norm before the average is taken. If you only take one sample and make a decision on it, you could easily sample one of the voltage spikes and send your robot off into the weeds.

Signal Output from Sharp IR Sensor

 

Maybe someone can make use of this info. I'm snowed under at the moment, so the hobby stuff is taking a back seat, but I had to at least understand why the Arduino's 5v supply was being pulled low by 200-300mV. It's all that current!

The capacitors reduced the noise I was picking up. However the sensor I've got works fine from 10cm to about 50cm after that the voltage rises again. Same result monitoring it on a voltmeter or via Arduino. It's powered from the 5V rail on the (Uno32)

Here's a graph to explain:

Sharp Sensor Problem

 

Any Ideas?

Oh I have just noticed that the USB-powered Uno32 seems to only have 4.5 - 4.6 volts on it's 5V rail. So maybe that's it.

Update: Powered from a 1A 5V regulator has inproved the range. It now (not particularly accurately) measures up to around 1m. But As soon as I give it free space it goes back to 1.5V (20cm). Is this an inherant problem with this type of sensor? I've tried a 10k resistor from the signal to ground which doesn't seem to have made a difference.

Ok I've fixed it.. It was picking up readings off a wall to the side of the sensor.

so basically.... adding a 100uF capacitor to the sensor will improve the reading????

However, when used in my circuit, when only reading the adc values from the sensor, it gives back a constant reading of 60 - 90 even if nothing is in front of the sensor!! I tried putting a 10 uF electrolytic and .1 uF non-elec. between GND and VCC right on the sensor, but it only brought the maximum false reading down from 100. This is a huge problem, since it reduces the maximum distance into about 1/3 - 1/4 of the normal. As in, when I have the sensor pointed at the ceiling even with the lights off, it gives a reading of ~ 60. As such, it has greatly reduced my robot functionality. As I've said, by itself in an otherwise empty circuit, it works great, so it's not the sensor completely to blame. I am using 3AA (1.5V) batteries to power my robot......please reply asap.. 

The sensor needs 5V regulated to function. You're giving it 4.5V, that is the minimum the sensor can take. Here is what it happens: when the sensor fires his IR LED, there is a short drop in voltage which falls below the minimum limit of the sensor voltage needs. Even with a large capacitor mounted on the sensor, when other devices are using power from the same unregulated 4.5V battery, the voltage will get lower than the sensor needs and it will throw off the readings. Add an extra AA battery to your battery pack (6V) and feed that to a 5V LDO voltage regulator then feed that to your electronics. Make sure no servos or motors are fed from the regulated voltage, if the regulator provides less than 1A. 

so basically u mean that i should have a regulated 5V input for the sensor and the others (moter n servo) should have the 4.5V? I am making the "Start here", object avoiding robot.... so should i use two different power source? could u please elaborate a bit more on "Make sure no servos or motors are fed from the regulated voltage, if the regulator provides less than 1A".

Thnkx

The voltage regulators come in different voltage and current ratings. Regular electronics components need small currents to function, but they need the voltage to be constant (regulated) to function reliably. So it is better to power the microcontroller, H-bridge, sensors from a 5V regulated power source. The servos and motors need a higher current, usually more than the voltage regulator can provide, so it is better to power them directly from the battery. Servos are rated for up to 6V, that makes a 4AA Alkaline battery pack or a 5AA rechargeable NiMH battery pack. Most motors are rated for higher voltages than servos, but they can work fine at 6V. If you motors need more than 6V, you also need to regulate the power for the servos, be it for 5V, and you will use a single voltage regulator for both the electronics and the servos (for example a 3A 5V regulator), or for 6V, and you need to get a high current 6V regulator, or better a switching voltage regulator. Why? Because the voltage regulator will waste the voltage difference from the battery voltage to the regulated voltage, multiplied by the current, as heat. The higer the current, the more heat is generated, thus the voltage regulator will get extremely hot and will need a heat sink radiator. Also, when choosing a voltage regulator you need to keep in mind the input source level. Regular 7805 regulator need an input voltage with 1.2V greater than the regulated output, so your battery voltage should be greater than 7.2V (for instance 6xAA NiMh or a 2S LiPo). But that is not good for the servos. To use a 6V battery pack, you need to get a LDO voltage regulator that accepts the input to be at least 0.5V greater than the output. I use the LM2940-5CT (from Parralax or Digikey) voltage regulator (5V 1A) in my circuits. Also, here is a trick to reduce the voltage for the servos from 7.2V to 6V: place 2 high current (1A) diodes in series from the battery to the servos power input. Each diode will have a voltage drop of about 0.7V, totaling 1.4V, resulting 5.8V for the servos, which is perfectly fine.

can you tell me which value uF capacitor is best for the sensor ?..

i used 10µF and a 100nF but it didnt make much difference as compared to the reading without the capacitors ..

The capacitor should be between 10..100µF, bigger is better. For best result a low ESR type is recommended. There is also a difference between SMD and normal capacitors. The SMD caps give better results. I didn't test it with tantal types.