GP2Y0A51SK0F Infrared Sensor Features
Sharp GP2Y0A51SK0F is an IR sensor that uses infrared wave to measure distance. The output of the sensor is analog voltage, which can be easily read by the microcontroller’s ADC converter. This sensor can be used in industry and especially in robotics. The efficient range of this module is 2 to 15 cm.
Note
At distances over 15cm, the sensor’s output is not accurate (usually shows higher than real value).
You can download the datasheet of this module here.
GP2Y0A51SK0F Infrared Distance Detection Sensor Datasheet
GP2Y0A51SK0F Infrared Sensor Pinout
This module has 3 pins:
- VCC: Module power supply – 5V
- GND: Ground
- OUT: The output of the module which is analog voltage.
You can see the pinout of this module in the image below.
Required Materials
Hardware component
Software Apps
Interfacing GP2Y0A51SK0F Sensor with Arduino
Step 1: Circuit
Connect the module 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 your Arduino.
/*
modified on Sep 9, 2020
Modified by MohammedDamirchi from https://github.com/MajenkoLibraries/Average
Home
*/
#include <Average.h>
#include <math.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() {
ave.push(4600.5 * pow(map(analogRead(A0), 0, 1023, 0, 5000), -0.94));
Serial.println(ave.mean());
delay(100);
}
Comments (2)
Thank you for your tutorial.
I would like to make it in raspberry, do you have the code ?
You’re quite welcome!
Unfortunately, we don’t have a tutorial for that. You can check the link below.
“https://tutorials-raspberrypi.com/infrared-distance-measurement-with-the-raspberry-pi-sharp-gp2y0a02yk0f/”