// Define the pin connections const int irSensorPin = 2; // IR sensor OUT pin connected to digital pin 3 const int ledPin = 3; // LED connected to digital pin 13 const int buzzerPin = 4; // Buzzer connected to digital pin 12 void setup() { // Initialize the IR sensor pin as an input pinMode(irSensorPin, INPUT); // Initialize the LED pin as an output pinMode(ledPin, OUTPUT); // Initialize the Buzzer pin as an output pinMode(buzzerPin, OUTPUT); // Start serial communication for debugging Serial.begin(9600); } void loop() { // Read the status of the IR sensor int sensorValue = digitalRead(irSensorPin); // If the sensor detects an object (sensor value LOW) if (sensorValue == LOW) { digitalWrite(ledPin, HIGH); // Turn ON the LED digitalWrite(buzzerPin, HIGH); // Turn ON the buzzer Serial.println("Object Detected! LED ON, Buzzer ON"); } else { digitalWrite(ledPin, LOW); // Turn OFF the LED digitalWrite(buzzerPin, LOW); // Turn OFF the buzzer Serial.println("No Object Detected. LED OFF, Buzzer OFF"); } // Delay for a short time delay(100); }