const int pirPin = 13; // Pin where the PIR sensor is connected
int pirState = LOW; // PIR state to track motion detection
void setup() {
Serial.begin(115200);
pinMode(pirPin, INPUT);
// WiFi setup here (as shown above)
}
void loop() {
int motionDetected = digitalRead(pirPin);
if (motionDetected == HIGH) {
if (pirState == LOW) {
Serial.println("Motion detected!");
// Trigger an action over WiFi
pirState = HIGH;
}
} else {
if (pirState == HIGH) {
Serial.println("Motion ended.");
pirState = LOW;
}
}
}
void sendNotification() {
// This function can send a HTTP request to a server, send data to an IoT platform, etc.
Serial.println("Sending WiFi notification...");
// Example: Send an HTTP request to a server
}