//Sensor PIR
//By : Silma Kamilah
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPLzqo-R0J3"
#define BLYNK_DEVICE_NAME "Smart Home"
#define PIR 2
#define LED 14
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = "pYSNHEYo67RDxcziaCclD1p5cUYWr2UL";
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
bool pirbutton = 0;
BlynkTimer timer;
BLYNK_WRITE(V0) {
pirbutton = param.asInt();
}
void setup () {
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(LED, OUTPUT);
pinMode(PIR, INPUT);
timer.setInterval(100L, pirsensor);
}
void pirsensor() {
bool value = digitalRead(PIR);
if (pirbutton == 1) {
if (value == 0) {
digitalWrite(LED, LOW);
} else if (value == 1) {
Blynk.notify("Warning! Please check your security system");
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED,LOW);
}
}
}
void loop() {
Blynk.run();
timer.run();
}