How Does an IR Distance Sensor Work?
IR distance sensors use a beam of infrared light that reflects off objects to determine distance via triangulation. The GP2Y0A21YK0F includes an IR LED and a Position Sensing Device (PSD). Reflected light creates an optical spot on the PSD, and its position changes based on object distance. A built-in signal processor calculates distance and provides an analog voltage output.

Features:
- Infrared technology for accurate distance measurement
- Affordable alternative to sonar rangefinders
- 10 cm to 80 cm detection range
- Single analog output for easy microcontroller interface
- Compatible with comparators for binary detection
Specifications:
- Operating voltage: 4.5 V to 5.5 V
- Average current consumption: 30 mA (typ.)
- Measuring range: 10 cm to 80 cm
- Output: Analog voltage
- Output voltage variation: 1.9 V (typ.)
- Response time: 38 ± 10 ms
- Size: 29.5 × 13.0 × 13.5 mm
- Weight: 3.5 g
Applications:
- Robotics: Obstacle detection, navigation
- Automation: Proximity and material handling
- Security: Object detection and monitoring
- Home automation: Touchless switches, faucets
- Gaming: Motion and gesture control
- Medical devices: Non-contact measurements
- Agriculture: Growth monitoring, soil moisture
- Drones: Altitude control, obstacle avoidance
- Education: Teaching distance sensing concepts
Pin Connections:
- Yellow: A0 (Analog Output)
- Black: GND
- Red: 5V

Sample Project:
Connecting with Arduino

Arduino Code Example:
#include "Average.h"
Average ave(10);
void setup() {
Serial.begin(9600);
}
void loop() {
ave.push(27.728 * 1.3 * pow(map(analogRead(A0), 0, 1023, 0, 5000) / 1000.0, -1.2045));
Serial.println(ave.mean());
delay(100);
}
Open the Serial Plotter to visualize the sensor's output over time.
Notes:
- Keep the lens clean from dust, oil, and water to ensure proper function.
- Do not wash the sensor as it can affect the optical system.
References:
How Does an IR Distance Sensor Work?
IR distance sensors use a beam of infrared light that reflects off objects to determine distance via triangulation. The GP2Y0A21YK0F includes an IR LED and a Position Sensing Device (PSD). Reflected light creates an optical spot on the PSD, and its position changes based on object distance. A built-in signal processor calculates distance and provides an analog voltage output.

Features:
- Infrared technology for accurate distance measurement
- Affordable alternative to sonar rangefinders
- 10 cm to 80 cm detection range
- Single analog output for easy microcontroller interface
- Compatible with comparators for binary detection
Specifications:
- Operating voltage: 4.5 V to 5.5 V
- Average current consumption: 30 mA (typ.)
- Measuring range: 10 cm to 80 cm
- Output: Analog voltage
- Output voltage variation: 1.9 V (typ.)
- Response time: 38 ± 10 ms
- Size: 29.5 × 13.0 × 13.5 mm
- Weight: 3.5 g
Applications:
- Robotics: Obstacle detection, navigation
- Automation: Proximity and material handling
- Security: Object detection and monitoring
- Home automation: Touchless switches, faucets
- Gaming: Motion and gesture control
- Medical devices: Non-contact measurements
- Agriculture: Growth monitoring, soil moisture
- Drones: Altitude control, obstacle avoidance
- Education: Teaching distance sensing concepts
Pin Connections:
- Yellow: A0 (Analog Output)
- Black: GND
- Red: 5V

Sample Project:
Connecting with Arduino

Arduino Code Example:
#include "Average.h"
Average ave(10);
void setup() {
Serial.begin(9600);
}
void loop() {
ave.push(27.728 * 1.3 * pow(map(analogRead(A0), 0, 1023, 0, 5000) / 1000.0, -1.2045));
Serial.println(ave.mean());
delay(100);
}
Open the Serial Plotter to visualize the sensor's output over time.
Notes:
- Keep the lens clean from dust, oil, and water to ensure proper function.
- Do not wash the sensor as it can affect the optical system.
References: