const int pirPin = 2;
void setup() {
// Initialize serial communication for debugging
Serial.begin(9600);
// Set the PIR pin as input
pinMode(pirPin, INPUT);
}
void loop() {
// Read the state of the PIR sensor
int pirState = digitalRead(pirPin);
// Check if motion is detected
if (pirState == HIGH) {
Serial.println("Motion detected!");
} else {
Serial.println("No motion detected.");
}
// Delay for stability
delay(500);
}