Description
GP2Y0A21YK0F is a distance measuring sensor unit,composed of an integrated combination of PSD(position sensitive detector) , IRED (infrared emittingdiode) and signal processing circuit.This device outputs the voltage corresponding to the detection distance, So this sensor can also be used as a proximity sensor.
Features
- Distance measuring range : 10 to 80 cm
- Analog output type
- Supply voltage : 4.5 to 5.5 V
- 3-pin JST connector
Getting started with Sharp GP2Y0A21YK0F 10~80cm Infrared Proximity Distance
In this tutorial we are going to see! how to interface it with arduino so that we can develop big system such as security system, counter,… this infrared proximity sensor has a simple theory of light reflection if the there an obstacle it reflect the light and the photodiode vary the resistance according to the amount of reflected right. so let’s start
Step1: Hardware required
Step2: Hardware connections
connect the infrared sensor as shown below so that we can read the data from the sensor
after now we are ready to upload the sample sketch and see, how it works
Step3: Testing the circuit
You can get the library for this system here You can install the library by going to Sketch > Include Library > Add .ZIP Library in the Arduino IDE. Upload the code below and you will start to get value.
Arduino Code:
/*SHARP GP2Y0A21YK0F IR distance sensor with Arduino and SharpIR library example code. More info: https://www.makerguides.com */ // Include the library: #include <SharpIR.h> // Define model and input pin: #define IRPin A0 #define model 1080 // Create variable to store the distance: int distance_cm; /* Model : GP2Y0A02YK0F --> 20150 GP2Y0A21YK0F --> 1080 GP2Y0A710K0F --> 100500 GP2YA41SK0F --> 430 */ // Create a new instance of the SharpIR class: SharpIR mySensor = SharpIR(IRPin, model); void setup() { // Begin serial communication at a baudrate of 9600: Serial.begin(9600); } void loop() { // Get a distance measurement and store it as distance_cm: distance_cm = mySensor.distance(); // Print the measured distance to the serial monitor: Serial.print("Mean distance: "); Serial.print(distance_cm); Serial.println(" cm"); delay(1000); }
Take an object (like a book, or your hand) move forward and backward you will see how the values are changing according to the distance between an object and a sensor as shown below
Conclusion
In this article I have shown you how the SHARP GP2Y0A21YK0F IR distance sensor works and how you can use it with Arduino.
Reviews
There are no reviews yet.