// Define the pins
const int irSensorPin = 2; // IR sensor OUT pin connected to Arduino digital pin 2
const int ledPin = 8; // LED pin connected to Arduino digital pin 8
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 for debugging
}
void loop() {
int sensorValue = digitalRead(irSensorPin); // Read the sensor value (HIGH or LOW)
if (sensorValue == HIGH) {
digitalWrite(ledPin, HIGH); // Turn on the LED if IR sensor detects an obstacle
Serial.println("Obstacle detected!");
} else {
digitalWrite(ledPin, LOW); // Turn off the LED if no obstacle detected
}
delay(100); // Delay for stability
}