#define PIR_PIN 12 // PIR motion sensor connected to digital pin 2
#define LED_PIN 10 // LED connected to digital pin 13
void setup() {
pinMode(PIR_PIN, INPUT); // Set PIR sensor pin as input
pinMode(LED_PIN, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int motionState = digitalRead(PIR_PIN); // Read PIR sensor state
if (motionState == HIGH) {
// Motion detected
digitalWrite(LED_PIN, HIGH); // Turn on LED
Serial.println("Motion detected!");
delay(1000); // Delay to avoid rapid toggling due to continuous motion
} else {
// No motion
digitalWrite(LED_PIN, LOW); // Turn off LED
}
}