#define IR_PIN 2 // Connect OUT pin of IR sensor to D2
void setup() {
// Initialize the serial communication
Serial.begin(9600);
// Set IR_PIN as input
pinMode(IR_PIN, INPUT);
Serial.println("IR Sensor Test Initialized");
}
void loop() {
// Read the IR sensor value
int sensorValue = digitalRead(IR_PIN);
// Print the sensor value
if (sensorValue == HIGH) {
Serial.println("No Obstacle Detected");
} else {
Serial.println("Obstacle Detected");
}
// Small delay for better readability
delay(100);
}