(article continued from previous page)
Before measurements can begin with the Sharp infrared sensor, the setup needs to comply with the manufacturer’s requirements. The Sharp GP2D12 sensor is very hobbyist-friendly with large screw holes, 5V power supply requirements, and only three pins to connect in total. However, the usage of one or more capacitors turns out to be important.
The manufacturer’s datasheet recommends using a 10 µF capacitor or larger near the infrared sensor. I knew from other people’s sites that the Sharp distance sensor draws a lot of current with each infrared pulse. As such, it was expected that a responsive power reservoir (a capacitor) would produce observable results.
5V power supply shows a +8V spike due to sensor emitter bursts.
I was shocked to see, that without any capacitors, the 5V power supply line spiked up to 13V and drooped down to 3V when the sensor emitted an infrared pulse. This could easily damage a component or reset a microcontroller.
A bench power supply was used during sensor testing and there were no other components in the circuit. In normal usage, there would be capacitors on a circuit board and perhaps some stray capacitance and inductance that would reduce these spikes. Also, an on-board voltage regulator might due a superior job of regulating the supply. Although you should consider the above trace a “worst case” scenario, a remotely located sensor with long wires might encounter similar spikes in real life.
Even a 0.1uF capacitor makes a 4X improvement in spike reduction.
Placing a 0.1 µF ceramic capacitor near the Sharp infrared distance sensor significantly reduced power supply noise. The power spike is down to about 0.5V or about 10% of the power supply voltage. This suggests there is probable value in soldering a small capacitor across the +Vcc and GND pins on these sensors.
The recommended 10uF capacitor almost eliminates power supply corruption.
Replacing the 0.1 µF capacitor with a 10 µF tantalum capacitor virtually eliminates spikes and droops. In fact, the oscilloscope timescale had to be zoomed out by 2500 times to visualize any impact. At this scale, the trace is showing the effect of a burst of multiple pulses, repeated five times.
So, now you see that following the manufacturer’s instructions of adding an appropriate amount of capacitance is really important. It isn’t magical pixy dust, CYA, or guesswork.
The Sharp infrared distance sensor outputs come in three major flavors:
Specifically, the Sharp GP2D12 sensor has an analog output. This part is an appropriate choice for use with a comparator chip, op amp, or microcontroller’s analog-to-digital converter.
I wondered whether the analog output would also show a spike or droop at any point.
A 1/3 of a volt spike lasts about 1.66 microseconds on the Sharp sensor analog output pin, regardless of the output pin voltage level.
In fact, even with a 10 microfarad capacitor across the supply lines, the output pin of the Sharp distance sensor repeatedly showed a 0.33V spike even though the distance to the target was steady. This could cause a comparator misfire or an incorrect reading on a microcontroller.
The spike intensity did not decrease at lower voltage levels that occur when the target is at the far end of the sensor’s specified range. That means the signal-to-noise ratio due to the spike is worse when the object is farther away.
A 4.7 nF capacitor at the sensor’s output pin reduced the spike by half but increased the duration by 10 times.
I experimented with adding a different capacitance values on the sensor output pin to see if the spike could be reduced. A large capacitor would reduce the responsiveness of changes in the sensor’s values when the object’s distance changes. So, capacitors in the microfarad range and higher should be avoided.
Small capacitances, such as 4.7nF seemed to alter the output signal somewhat, but with some side effects. That is, the spike height was reduced from 0.33V down to 0.14V, but the length of the spike increased from 1.66 µs to 10.75 µs.
The spike disappeared entirely (up to the sensitivity of my equipment) with a 47 nF capacitor. And, the ability for the output signal to change rapidly in response to object location appeared generally unaffected (which is good).
I suspect the “perfect” capacitance value will vary based on sensor placement (wire length, surrounding electronics, capacitance and inductance of the input pin on destination IC). Or, a microcontroller could simply take multiple readings and discard the highest value to eliminate spikes. You may need to experiment to find the right value if your application requires precision.
All of this work leads up to getting samples of actual distances measured by the Sharp infrared sensor. My test setup consisted of a bench power supply, a 10 µF capacitor on the sensor’s power supply lines, no capacitor on the output pin, and multiple readings on a digital multimeter (discarding an intermittent outlier). Samples were taken at 1 cm increments.
Voltage output of the Sharp GP2D12 infrared distance sensor at measurements from 1 cm to 80 cm. (Results below 10 cm are shown for completeness, but are not actually within the specified range of the sensor.)
My test results are similar but not identical to the datasheet and other people’s web sites. The curve on my results seems a little lumpy from 35 cm to 65 cm.
To rule out test errors:
In the end, the test results were the same. I have not had a chance to test with a different target (maybe gray paper) or a different power supply.
Because the sensor case is made of carbonic ABS, it conducts electricity. Some people believe this means the manufacturer expects the case to be grounded. I could not find a recommendation for this practice in the datasheet. Nor could I detect any change whatsoever by grounding or not grounding the case. Although perhaps there is some application where grounding the case may have value, I believe the case is conductive to either prevent static electricity damage or to act as an RF shield. Because of the electrical pulses generated during infrared bursts, I lean toward the RF shield theory to prevent interference with other devices.
It is worth noting is that the output pin shows stair-stepping at greater distances / lower voltages. I believe the sensor’s DAC (digital-to-analog converter) has a limited resolution of approximately 0.019V. That would indicate an 8-bit DAC since 5V / 28 = 0.01953. Thus, the sensor is unable to communicate a 1 millimeter change after about 33 cm.
Of course, conversion errors can also occur during reading. If you’re hooking the sensor to a microcontroller, it is a good idea to use more than 8-bits on your ADC (analog-to-digital conversion). On the Atmel ATtiny861, I opted to use a 10-bit conversion with a 2.56V reference (rather than a 5V reference) to achieve a resolution of 2.56V / 210=0.0025V. That eliminates read errors at lower voltage levels.
All in all, I am glad I took the time to test the Sharp infrared distance sensor. The tests confirmed my belief in liberal use of capacitors. The complete set of data points alerted me to resolution issues at greater distance. And, finally, testing provided evidence against the rumored practice of grounding the sensor case.