GP2Y0A02YK0F Infrared Sensor Features
Sharp GP2Y0A02YK0F is an IR sensorusing infrared wave to measure distance. The output of the sensor is analog voltage, which can be read easily by ADC channel of the microcontroller. This sensor can be used in industry and especially in robotics. Sharp GP2Y0A02YK0F has an efficient range of 20 to 150cm.
Note
The sensor’s output data would be incorrect at distances less than 20 cm and more than 150 cm.
You can download the datasheet of this module here.
GP2Y0A02YK0F Infrared Distance Sensor Datasheet
1 file(s) 64.96 KB
GP2Y0A02YK0F IR Sensor Pinout
This module has 3 pins as follows:
- VCC: Module power supply – 5V
- GND: Ground
- OUT: The output of the module which is analog voltage.
You can see pinout of this module in the image below.
Required Material
Hardware component
Software Apps
Interfacing GP2Y0A02YK0F Sensor with Arduino
Step 1: Circuit
Connect the sensor to Arduino according to the following image.
Step 2: Code
Install following library on your Arduino board.
Note
If you need more help with installing a library on Arduino, read this tutorial: How to Install an Arduino Library
Upload the following code to Arduino.
/*
modified on Sep 8, 2020
Modified by MohammedDamirchi from https://github.com/MajenkoLibraries/Average
Home
*/
#include <Average.h>
// Reserve space for 10 entries in the average bucket.
// Change the type between < and > to change the entire way the library works.
Average<float> ave(10);
void setup() {
Serial.begin(9600);
}
void loop() {
int minat = 0;
int maxat = 0;
// Add a new random value to the bucket
ave.push(60.374*1.3 * pow(map(analogRead(A0), 0, 1023, 0, 5000) / 1000.0, -1.16));
Serial.println(ave.mean());
delay(100);
}
After running the code, you will see the following image in the serial output.