IR Distance Sensor GP2Y0A21YK0F With Cables

AED 68.25

Low stock


  • The IR GP2Y0A21YK0F distance sensor is an infrared sensor that is commonly used for measuring distances in various applications. It offers better performance than other IR sensors, while still being more affordable than sonar rangefinders. The sensor can interface easily with most microcontrollers, using its single analog output which can be connected to an ADC for distance measurement, or a comparator for threshold detection.
  • The detection range of the GP2Y0A21YK0F sensor is approximately 10 cm to 80 cm, making it suitable for use in projects that require accurate distance measurements within this range. It is designed with a compact and lightweight form factor, making it easy to integrate into different systems.
  • This product also comes with cables for easy connection to a microcontroller or other electronic devices. Overall, the GP2Y0A21YK0F IR distance sensor is an excellent choice for a wide range of applications, including robotics, automation, and object detection.

Screen Shot 2023-02-28 at 9 48 55 AM

How does an IR distance sensor work?

An IR distance sensor uses a beam of infrared light to reflect off an object to measure its distance. The distance is calculated using triangulation of the beam of light. The sensor consists of an IR LED and a light detector or PSD (Position Sensing Device). When the beam of light gets reflected by an object, the reflected beam will reach the light detector and an ‘optical spot’ will form on the PSD.

Screen Shot 2023-02-28 at 9 58 43 AM

When the position of the object changes, the angle of the reflected beam and the position of the spot on the PSD changes as well. See point A and point B in the image below.

Screen Shot 2023-02-28 at 9 58 50 AM

The sensor has a built-in signal processing circuit. This circuit processes the position of the optical spot on the PSD to determine the position (distance) of the reflective object. It outputs an analog signal which depends on the position of the object in front of the sensor.


  • Infrared technology: The sensor uses infrared light to detect distances, providing more accurate measurements than other IR alternatives.
  • Economical: The sensor is more affordable than sonar rangefinders, making it a cost-effective choice for many projects.
  • Wide detection range: The detection range of this version is approximately 10 cm to 80 cm, allowing it to be used in various applications that require accurate distance measurements within this range.
  • Analog output: The sensor provides a single analog output that can be easily interfaced with a microcontroller's ADC for taking distance measurements.
  • Comparator support: The sensor's output can also be connected to a comparator for threshold detection, making it suitable for applications that require binary output signals.


  • Operating voltage: 4.5 V to 5.5 V
  • Average current consumption: 30 mA (typical)
  • Distance measuring range: 10 cm to 80 cm (4" to 32")
  • Output type: analog voltage
  • Output voltage differential over distance range: 1.9 V (typical)
  • Response time: 38 ± 10 ms
  • Package size: 29.5 × 13.0 × 13.5 mm
  • Weight: 3.5 g (0.12 oz)


  • Robotics: The sensor can be used in robotics for obstacle detection, autonomous navigation, and distance sensing.
  • Automation: The sensor can be used in industrial automation for proximity detection, material handling, and quality control applications.
  • Object detection: The sensor can be used in security systems, traffic control systems, and other applications that require object detection.
  • Home automation: The sensor can be used in home automation for touchless switches, automatic faucets, and other applications that require distance sensing.
  • Gaming: The sensor can be used in gaming systems for motion detection and gesture recognition.
  • Medical devices: The sensor can be used in medical devices for non-contact measurement of body temperature, respiration rate, and other vital signs.
  • Agriculture: The sensor can be used in precision agriculture for measuring plant growth, soil moisture, and other environmental variables.
  • Drones: The sensor can be used in drones for obstacle avoidance, altitude control, and landing assistance.
  • Education: The sensor can be used in educational projects and experiments for teaching students about distance sensing and microcontroller interfacing.

    Pin Connections:

  • (Yellow): A0
  • (Black): GND
  • (Red): 5V

Screen Shot 2023-02-28 at 9 54 06 AM

Package Includes:

  • IR Distance Sensor GP2Y0A21YK0F With Cables

    Sample Project:

  • How to connect GP2Y0A21YK0F the with Arduino:

Screen Shot 2023-02-28 at 9 55 51 AM

  • Arduino code for IR GP2Y0A21YK0F distance sensors:
#include "Average.h"

Average<float> ave(10);

void setup() {

void loop() {
    int minat = 0;
    int maxat = 0;

    // Add a new random value to the bucket
    ave.push(27.728*1.3 * pow(map(analogRead(A0), 0, 1023, 0, 5000) / 1000.0, -1.2045));

  • you can open the serial plotter and see the output in stream


  • The lens of this device needs to be kept clean. There are cases that dust, water, or oil, and so on deteriorate the characteristics of this device. Please consider in actual application. • Please don't wash. Washing may deteriorate the characteristics of the optical system and so on. Please confirm resistance to chemicals under the actual usage since this product has not been designed against washing.