

An IR (Infrared) sensor is an electronic device that detects infrared radiation emitted by objects. It is widely used in applications such as proximity sensing, motion detection, and remote control systems. IR sensors are versatile and can be found in devices like automatic doors, obstacle-avoiding robots, and TV remote controls. They are valued for their ability to detect objects without physical contact.








| Pin | Name | Description |
|---|---|---|
| 1 | VCC | Power supply pin. Connect to 3.3V or 5V DC. |
| 2 | GND | Ground pin. Connect to the ground of the circuit. |
| 3 | OUT (Digital) | Digital output pin. Outputs HIGH or LOW based on object detection. |
| 4 | OUT (Analog)* | Analog output pin (if available). Provides a voltage proportional to distance. |
*Note: Some IR sensors may not have an analog output pin. Check your specific model for details.
Below is an example of how to use a digital IR sensor with an Arduino UNO to detect an object:
// IR Sensor Example with Arduino UNO
// This code reads the digital output of the IR sensor and turns on an LED
// when an object is detected.
const int irSensorPin = 2; // IR sensor digital output connected to pin 2
const int ledPin = 13; // Built-in LED on Arduino UNO
void setup() {
pinMode(irSensorPin, INPUT); // Set IR sensor pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int sensorValue = digitalRead(irSensorPin); // Read the IR sensor output
if (sensorValue == LOW) { // Object detected (LOW signal from sensor)
digitalWrite(ledPin, HIGH); // Turn on the LED
Serial.println("Object detected!");
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
Serial.println("No object detected.");
}
delay(100); // Small delay for stability
}
The sensor is not detecting objects.
False detections or erratic behavior.
Analog output is not working.
Can the IR sensor detect transparent objects?
Transparent objects like glass may not be detected effectively due to low IR reflection.
What is the maximum detection range of an IR sensor?
The range varies by model but is typically between 2cm and 30cm.
Can I use an IR sensor outdoors?
Yes, but performance may be affected by sunlight or other IR sources. Use an IR sensor with ambient light filtering for better results.
By following this documentation, you can effectively integrate an IR sensor into your projects for reliable object detection and proximity sensing.