// Code
// Define pins
int ledPin = 13; // Pin for theLED
int pirPin = 7; // Pin for thePIR sensor
void setup() {
pinMode(ledPin, OUTPUT); // SetLED pin as an output
pinMode(pirPin, INPUT); // SetPIR sensor pin as an input
Serial.begin(9600); //Begin serial communication fordebugging
}
void loop() {
int pirValue =
digitalRead(pirPin); // Read thePIR sensor
if (pirValue == HIGH) {
digitalWrite(ledPin, HIGH); //Turn the LED on
Serial.println("Motion detected!LED ON");
} else {
digitalWrite(ledPin, LOW); //Turn the LED off
Serial.println("No motion. LEDOFF");
}
delay(500); // Small delay toprevent bouncing
}