const int pirPin = 19; // PIR motion sensor connected to GPIO 2
const int redLedPin = 5; // Red LED connected to GPIO 4
const int greenLedPin = 21; // Green LED connected to GPIO 5
void setup() {
pinMode(pirPin, INPUT);
pinMode(redLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);
// Initially, turn off both LEDs
digitalWrite(redLedPin, LOW);
digitalWrite(greenLedPin, LOW);
Serial.begin(115200);
}
void loop() {
int motion = digitalRead(pirPin);
if (motion == HIGH) {
// Motion detected (Parking slot occupied)
digitalWrite(redLedPin, HIGH); // Turn on red LED
digitalWrite(greenLedPin, LOW); // Turn off green LED
Serial.println("Parking slot occupied");
} else {
// No motion (Parking slot empty)
digitalWrite(redLedPin, LOW); // Turn off red LED
digitalWrite(greenLedPin, HIGH); // Turn on green LED
Serial.println("Parking slot empty");
}
delay(1000); // Delay to avoid reading the sensor too quickly
}