#define BLYNK_TEMPLATE_ID "TMPL3GT29u5oh"
#define BLYNK_TEMPLATE_NAME "Door lock"
#define BLYNK_AUTH_TOKEN "s74K2rPheDYVeMRZ0Dth6xsWJVmK0s33"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = "s74K2rPheDYVeMRZ0Dth6xsWJVmK0s33";
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
const int relayPin = 2;
const int LED = GND;
#define LOCKED LOW
#define UNLOCKED HIGH
BlynkTimer timer;
void setup() {
Serial.begin(115200);
pinMode(relayPin, OUTPUT);
pinMode(LED, OUTPUT);
digitalWrite(relayPin, LOCKED);
Blynk.begin(auth, ssid, pass);
}
void loop() {
Blynk.run();
timer.run();
}
BLYNK_WRITE(V0) {
int lockValue = param.asInt();
if (lockValue == 1) {
unlockDoor();
} else {
lockDoor();
}
}
void lockDoor() {
Serial.println("Locking door...");
digitalWrite(relayPin, LOCKED);
Serial.println("Door locked");
}
void unlockDoor() {
Serial.println("Unlocking door...");
digitalWrite(relayPin, UNLOCKED);
delay(1000);
digitalWrite(relayPin, LOCKED);
Serial.println("Door unlocked");
}