Skip to main content

IR Distance Sensor SHARP GP2Y0A02YK with Arduino

The Sharp GP2Y0A02YK infrared ranger is able to continuously measure the distance to an object. The usable range is 20 cm to 150 cm. The device generates an analog voltage that is a function of range, and the output voltage can be measured by an analog-to-digital (ADC) input line. The voltage will range from approx. 0.4V at 150cm to 2.7V at 20cm. 

Material:
- sensor: Sharp GP2Y0A02YK 
- Arduino UNO (other models also are fine) × 1 + power cable (sold seperately)
- Dupont jumper wires Male - male
- Capacitor(≥10 µF)
- breadboard

1 Solder some male jumper wires on the cable that comes with the sensor for easy connection to arduino or breadboard.

2 Connect the parts according this schematic:

SHARP-GP2Y0A21YK0F_bb.png
These type of distance sensors tend to be a bit noisy, so it is recommended to add a capacitor between Vcc and GND. The datasheet suggests a capacitor of 10 µF or more (I used 220 µF). Connect the positive lead of the capacitor to the Vcc wire connection and the negative lead to the GND wire connection (see picture). Capacitors are often marked with a stripe which indicates the negative lead. The positive lead is often longer then the negative lead.

3 In the Arduino software Click the Manage Libraries ... menu item (under Tools), search for the SharpIR library written by Guillaume Rico and Thibaut Mauon. Install it.

 

source: 
https://www.makerguides.com/sharp-gp2y0a21yk0f-ir-distance-sensor-arduino-tutorial/