// Ilham Najmul Umam TI721184
int pirPin = 2; // PIR sensor output pin
int ledPin = 13; // LED pin
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Set the PIR pin as input
pinMode(pirPin, INPUT);
// Set the LED pin as output
pinMode(ledPin, OUTPUT);
}
void loop() {
// Read the PIR sensor output
int pirState = digitalRead(pirPin);
// If motion is detected, turn on the LED and print "Motion Detected"
if (pirState == HIGH) {
digitalWrite(ledPin, HIGH);
Serial.println("Motion Detected");
} else {
// If no motion is detected, turn off the LED and print "No Motion"
digitalWrite(ledPin, LOW);
Serial.println("No Motion");
}
// Small delay to avoid rapid state changes
delay(100);
}