What is an IR Sensor?
An **Infrared (IR) Sensor Module** is a small, low-cost electronic device that detects the presence of nearby objects using infrared light. It consists of an **IR LED** (emitter) that emits infrared light and a **photodiode** (receiver) that detects reflected infrared light.
When an object comes within the sensor's range, the infrared light emitted by the LED bounces off the object and is detected by the photodiode. The onboard comparator circuit then outputs a digital signal — **LOW when an object is detected** (active low) and **HIGH when nothing is present**.
Key Specifications
|---|---|
Working Principle & Active-Low Logic
1. The **IR LED** continuously emits infrared radiation.
2. When an **object** comes in front of the sensor, the IR light reflects back.
3. The **photodiode** picks up the reflected IR signal and changes its internal resistance.
4. The onboard **LM393 comparator** compares this voltage against the reference threshold set by the potentiometer.
5. If the reflected signal crosses the threshold, the **OUT pin goes LOW** (active low).
Wiring with Arduino
**Connections:**
- **VCC** → Arduino 5V
- **GND** → Arduino GND
- **OUT** → Arduino Digital Pin 7
#define IR_PIN 7
void setup() {
Serial.begin(9600);
pinMode(IR_PIN, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
int val = digitalRead(IR_PIN);
if (val == LOW) {
Serial.println("Obstacle Detected!");
digitalWrite(LED_BUILTIN, HIGH);
} else {
Serial.println("Path Clear");
digitalWrite(LED_BUILTIN, LOW);
}
delay(200);
}
genbots

