Sharp GP2Y0A21 IR Distance Sensor
Analog IR distance sensor for obstacle detection at 10-80cm range — reliable and well-documented.
A Sharp analog infrared distance sensor commonly used in line-following robots and obstacle-avoidance builds. It combines an infrared emitter and a position-sensitive detector so that the angle of returned light (rather than just its intensity) determines distance, giving reasonably consistent readings across the 10-80cm range regardless of ambient light — a well-documented, reliable classic choice, though its non-linear analog output curve needs a lookup table or formula to convert to an actual distance value.
Specifications
| Sensor type | Sharp GP2Y0A21YK0F analog IR triangulation distance sensor |
| Operating voltage | 4.5V–5.5V DC |
| Operating current | ~30-33 mA typical |
| Measuring range | 10cm-80cm |
| Output | Analog voltage, inversely (non-linearly) related to distance — requires a lookup table or curve-fit formula to convert to centimeters |
| Update rate | ~16.5ms cycle time (roughly 60Hz) |
| Field of detection | Narrow beam, best for single-point distance measurement rather than wide-area sensing |
| Interface | Single analog output pin, read with analogRead() |
Pinout
| Pin | Name | Description |
|---|---|---|
| 1 | VCC | Power, 4.5–5.5V DC |
| 2 | GND | Ground |
| 3 | Vo (analog output) | Analog voltage output — inversely related to distance, needs conversion to a usable distance value |
The output voltage-to-distance relationship is non-linear (the sensor is much more sensitive at close range than far range), so most projects use either a published lookup table from the datasheet or an approximate inverse-power curve-fit formula in code to convert the raw analogRead() value into centimeters — a straight linear mapping will give inaccurate results, especially near the extremes of the 10-80cm range. The sensor also reports unreliable/erratic values for objects closer than its minimum 10cm range.
Variants
The GP2Y0A21 remains a well-documented, reliable classic for its 10-80cm range, but if starting fresh, the VL53L0X often gives more consistent results with a simpler digital interface and no need for a non-linear conversion curve — worth considering as a modern drop-in alternative for new designs.
| Variant | Temp range | Hum range | Accuracy | Protocol | Price |
|---|---|---|---|---|---|
| GP2Y0A21 (10-80cm) | ~$5-10 | ||||
| GP2Y0A02 (20-150cm) | ~$6-12 | ||||
| VL53L0X (laser ToF) | ~$3-6 |