Component guide · Beginner · 3 min read
Sharp IR Distance Sensors

GP2Y0A21, GP2Y0A02 and I2C Models for Arduino
By Geekobot Learning Team · Updated 29 Oct 2026
On this page
Sharp IR distance sensors measure distance by triangulation and output an analog voltage that falls as the distance grows. The curve is non-linear, so convert the reading with a formula or table. Add a capacitor across the supply to reduce noise, ignore readings closer than the minimum range, and choose the model for your range (for example 20 to 150 cm for the GP2Y0A02YK0F).
Key specs at a glance
- GP2Y0A02YK0F
- 20 to 150 cm analog output
- GP2Y0A21-class
- 10 to 80 cm analog output
- GP2AP03VT00F
- Digital I2C model
- Supply
- 4.5 to 5.5 V, about 30 mA
- Update
- About 25 to 40 ms per reading
- Mounting
- Brackets and 3-pin cables
How it works
The sensor shines a narrow IR beam and a position-sensitive detector sees where the reflection lands. The angle gives the distance by triangulation, so colour matters less than with simple IR reflectance sensors. The analog output is highest at close range and falls with distance, and it also drops if the object is closer than the minimum distance, which gives a wrong, far-looking reading.
Wiring
Connect VCC to 5 V, GND to ground and the signal wire to an analog input. Place a 10 to 100 µF capacitor across the sensor's supply pins right at the connector, since it draws current in pulses. On 3.3 V boards read the output through the ADC range or a voltage divider; see ADC basics and voltage dividers.
Converting voltage to distance
The relation is roughly inverse: distance ≈ k / (V − b). Calibrate with a few known distances and fit the formula, or use a lookup table with interpolation. Average several readings, and discard values outside the datasheet range. The ADC resolution tool shows the step size of your reading.
Brackets and mounting
Use a bracket to aim the sensor parallel to the floor and keep it steady. Several sensors in a ring give a rough scan around a robot; stagger their readings in time so their beams do not interfere. Keep the lens clean and away from direct sun.
Alternatives
Time-of-flight sensors such as the VL53L0X give a digital distance, ultrasonic sensors work on any material and LiDAR suits long range. Simple obstacle detection is covered in IR sensor modules.
Try it: Adc resolution calculator
Change the values and the diagram and results update as you type.
Common mistakes to avoid
- Reading closer than the minimum distance.
- Skipping the supply capacitor.
- Treating the output as linear.
- Putting several sensors in a row firing at once.
- Using it in direct sunlight.
Frequently asked questions
How do I convert the voltage to centimetres?
Use a calibration table or a fitted inverse formula.
Why does my reading jump?
Supply noise, object too close or reflective surfaces. Add a capacitor and average.
Does colour matter?
Much less than with reflective IR modules, but very shiny surfaces can cause errors.
Can it work at 3.3 V?
It needs 4.5 V or more, but the output can be read by a 3.3 V ADC with a divider.
Which one for a robot?
The 10 to 80 cm model for small robots; the 20 to 150 cm model for larger ones.
Parts for this guide
Calculators
Terms in this guide
Projects that use it
Put this into practice: 1 step-by-step build in our project library uses parts from this guide.
Keep learning
Sources
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.






