//IoT_Based Staircase LED Indicator By Abdul-Hafees Tijani, NXU 2024
const int pirPin = 2; // PIR sensor pin
const int ledPin = 3; // LED pin
int pirState = LOW; // Start with no motion detected
int val = 0; // Variable for reading the pin status
void setup() {
pinMode(pirPin, INPUT); // Declare the PIR sensor as an INPUT
pinMode(ledPin, OUTPUT); // Declare the LED as an OUTPUT
Serial.begin(9600);
}
void loop() {
val = digitalRead(pirPin); // Read PIR sensor value
if (val == HIGH) { // If motion is detected
digitalWrite(ledPin, HIGH); // Turn on LED
if (pirState == LOW) {
Serial.println("Motion detected!");
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // Turn off LED
if (pirState == HIGH) {
Serial.println("Motion ended!");
pirState = LOW;
}
}
}