#include #include const char* ssid = "YOUR_WIFI_SSID"; const char* password = "YOUR_WIFI_PASSWORD"; const char* apiKey = "YOUR_WRITE_API_KEY"; const long channelId = YOUR_CHANNEL_ID; const int PIRPin = 4; const int BuzzerPin = 2; WiFiClient client; void setup() { Serial.begin(115200); pinMode(PIRPin, INPUT); pinMode(BuzzerPin, OUTPUT); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.println("Connecting to WiFi..."); } Serial.println("Connected to WiFi"); ThingSpeak.begin(client); } void loop() { int motionState = digitalRead(PIRPin); if (motionState == HIGH) { digitalWrite(BuzzerPin, HIGH); delay(500); digitalWrite(BuzzerPin, LOW); ThingSpeak.setField(1, 1); } else { ThingSpeak.setField(1, 0); } int responseCode = ThingSpeak.writeFields(channelId, apiKey); if (responseCode == 200) { Serial.println("Data sent to ThingSpeak successfully!"); } else { Serial.print("Error sending data to ThingSpeak. Response code: "); Serial.println(responseCode); } delay(5000); // Send data every 5 seconds }