The Sharp GP2D120
Original report: Paul Feder
This is an Infrared (IR) sensor that detects changes in distance to an object and outputs an analog voltage corresponding to how close or far away the object is to the sensor. It is almost identical to the GP2D12, only the GP2D120 has a shorter range. The range of values that you get when connected to a computer through serial is about half of the 0-1023 range of a Potentiometer.
PROS and CONS
As I have discovered, there are some major weaknesses in IR sensors, listed below. However, all in all, the simplicity of use and the relatively narrow focus cone of the sensor outweighs the negatives for me. In certain ways, the Ultrasonic sensor is more reliable in more situations than the IR. Here is an article that delves into the limitations of the IR sensors and Ultrasonic sensors: Ultrasonic and IR Sensors Compared
1. They have a dead zone right in front of the sensor which will yield garbage data.
2. They are nonlinear, and using an equation to convert it to linear data is processor heavy.
3. They have difficulty detecting transparent material.
4. They are subject to interference from other sources of IR light. For instance, if you point a remote control at it, the readings will go haywire.
5. The readings have a fair bit of noise- you have to do some software filtering to smooth out the results.
1. They are relatively cheap.
2. They are very easy to set up and use.
3. They have a rather focused beam of detection, which is a plus depending on the application.
How it works
Basically, there is an infrared emitting LED, and a lens, side by side. Inside the unit is a CCD that recieves the light from the lens. When an object is in front of the sensor, the CCD will "see" the reflected IR light off from the object. Based on the angle of the reflection, distance is detected:
The connections are pretty simple. There are three wires: Power (Vcc), Ground (GND), and Output (Vo). In order to keep the circuit happy, you should put a by-pass capacitor * of 10uF between Vcc and GND near the detector (bypass capacitors are decoupling capacitors. They smooth out any dips and spikes in the sensor's power supply. They're usually placed as close to the sensor as possible. -tigoe)
I've tried to use the GP2D120 without a by-pass capacitor, and my Pic chip would lose power, and restart, because presumably the detector drew too much current too fast.
Here are the Min/ Typ/ Max ratings when using a white piece of paper as the object the IR sensor is sensing.
- Measuring Distance (Range, or delta L): 4 cm - 30 cm
- Supply Voltage (Vcc): Happy: 4.5 V Ė 5.5 V (Unhappy: Min Ė0.3 V, Max 7 V)
- Output terminal voltage (Vo): Min 0.25 V, Typical 0.4 V, Max 0.55 V
- Output voltage difference (delta Vo): Min 1.75 V, Typical 2.0 V, Max 2.25 V
- The average supply current (Icc): Typical 33 mA, Max 50 mA
Measuring Distance Explained: As long as you donít put objects closer than 4cm to the sensor, you will get reliable readings. The output curve is non-linear; the closer you get, the more the voltage increases per distance increment. However, when you get too close to the sensor, the output voltage drops suddenly, and past that point, the output values are not reliable. Here's a graph of the GP2D120's output curve (Y axis is Output Voltage (Vo), and the X axis is distance measured in cm):
Here's a link to acroname's site, where they explain how to make the curve linear. I had trouble getting it to work perfectly however: How to make the output linear.
Supply Voltage (Vcc) Explained: This sensor is happiest when itís getting 4.5 Ė 5.5 V!
Output Voltage delta Vo refers to the voltage range, as it corresponds to the distance range. For example, for a 4-30cm range, the output voltage range is 1.95 - 2.25 volts. -tigoe
Average Supply Current Explained: The Max current is what you would want to keep in mind if you have a lot of other electronics hooked up to the breadboard. You would want to find the sum of all the Max current values of all your electronics and make sure it doesnít add up to more than the amount of current your voltage regulator can supply (e.g. 1000mA for a 7805 5V regulator).
Crys Moore did a nice write-up on linearizing these sensors using Acroname's formulas on an Arduino. -tigoe
I found an interesting presentation online for a "Smart Wheelchair" design, which uses Sharp IR sensors. Smart Wheelchair with IR The conclusion of this article was that they would use IR sensors in conjunction with Ultrasonic sensors for redundancy and thus higher accuracy. This method seems to be popular in many robotics applications. For instance, this R2-D2 look-alike: JA bot
The IR sensor can be used to make a simple theremin instrument, which can raise and lower pitch depending on how close your hand is to the sensor.
Iíve been working on a musical instrument that uses two GPD120 sensors. The instrument is a cube that generates melodies (using Max/Msp), and I can tweak the phrasing of the melodies by waving my hands back and forth. In order to get around the dead zone issue, I constructed a box with a hole on two sides, with my two sensors mounted 2 inches back from the surface of the box. This way, I can bring my hands right up to the box without worrying about hitting that dead zone of the sensor.
In order to get around the noise of the sensor, through software, I lopped off a little bit of the range of the sensor on either end. Even though I lose a bit of range, the increased reliability is a big plus. The reason I took off the range far from the sensor is to ensure that any fluctuations in the sensor when there is nothing present wonít be sent to Max/MSP. The reason I took off some of the range close to the sensor is that even though I designed the cube in order so that I could bring my hand right up to the hole, the palm of my hand is not fully flush with the box, and therefore canít get exactly to the minimum distance the way a flat piece of paper would. By limiting the range, my hand can be right nexta to the box, or slightly away from the box, and both will give end of range values.