const int pirPin = 28; // GPIO 2 connected to PIR sensor
const int ledPin = 15; // GPIO 15 connected to LED
void setup() {
pinMode(pirPin, INPUT); // Set PIR sensor pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial1.begin(115200); // Initialize serial communication
}
void loop() {
int sensorValue = digitalRead(pirPin); // Read the PIR sensor value
if (sensorValue == HIGH) {
digitalWrite(ledPin, HIGH); // Turn LED on if motion is detected
Serial1.println("Motion detected!");
} else {
digitalWrite(ledPin, LOW); // Turn LED off if no motion
Serial1.println("No motion.");
}
delay(500); // Wait for 500 milliseconds before reading again
}