// Define the pin numbers for the LEDs and the motion sensor
#define LED1 4
#define LED2 5
#define PIR_SENSOR 2
void setup() {
// Set the LED pins as output
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
// Set the motion sensor pin as input
pinMode(PIR_SENSOR, INPUT);
}
void loop() {
// Read the state of the motion sensor
int motionState = digitalRead(PIR_SENSOR);
if (motionState == HIGH) {
// Motion detected
digitalWrite(LED1, HIGH); // Turn LED1 on (connects to 5V)
digitalWrite(LED2, LOW); // Turn LED2 off (connects to GND)
} else {
// No motion detected
digitalWrite(LED1, LOW); // Turn LED1 off (connects to GND)
digitalWrite(LED2, HIGH); // Turn LED2 on (connects to 5V)
}
delay(100); // Small delay to prevent rapid switching
}