const int irPin = 2; // IR sensor output pin
const int ledPin = 13; // LED pin
void setup() {
pinMode(irPin, INPUT); // Set IR sensor pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Initialize Serial Monitor
}
void loop() {
int irState = digitalRead(irPin); // Read the state of the IR sensor
if (irState == HIGH) {
// If the IR sensor detects an object
digitalWrite(ledPin, HIGH); // Turn on LED
Serial.println("Object detected!");
} else {
// If the IR sensor does not detect an object
digitalWrite(ledPin, LOW); // Turn off LED
Serial.println("No object detected.");
}
delay(5000); // Wait for 100 milliseconds before the next loop
}