Contents

Interfacing GP2Y0A51SK0F Infrared Distance Sensor with Arduino

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 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

Arduino UNO R3 × 1
GP2Y0A51SK0F Distance Sensor × 1
Male Female Fumper Wire × 1

Software Apps

Arduino IDE

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.

https://github.com/MajenkoLibraries/Average

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); }
After running the code, you will see the following image in the serial output.
Liked What You See?​
Get Updates And Learn From The Best​

Comments (2)

  • Boburjon Nabiev Reply

    Thank you for your tutorial.
    I would like to make it in raspberry, do you have the code ?

    June 2, 2021 at 7:58 am
    • Mehran Maleki Reply

      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/”

      June 4, 2021 at 10:37 am

Leave a Reply

Your email address will not be published. Required fields are marked *