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