// Define the digital pin connected to the PIR sensor
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 value from the PIR sensor
int motionDetected = digitalRead(pirPin);
// If motion is detected, print a message
if (motionDetected == HIGH) {
Serial.println("Motion detected!");
} else {
Serial.println("No motion detected");
}
// Add a small delay to avoid continuous detection
delay(500);
}