#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL6_uhy7w4I"
#define BLYNK_TEMPLATE_NAME "Project Smart Home"
#define BLYNK_AUTH_TOKEN "c5oU50hhpAKVeIp7lNukzP1sbeYj4tO6"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
int relay1 = 12;
int relay2 = 5;
int pintuUtama = 21;
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST"; //ganti sesuai hotspot/wifi yang tersedia
char pass[] = "";
BlynkTimer timer;
BLYNK_WRITE(V0)
{
int relay1Value = param.asInt();
digitalWrite(relay1, relay1Value);
}
BLYNK_WRITE(V1)
{
int relay2Value = param.asInt();
digitalWrite(relay2, relay2Value);
}
void sendData(){
int statusPU = digitalRead(pintuUtama);
if (statusPU == HIGH)
{
Blynk.virtualWrite(V2, "TERBUKA");
Blynk.virtualWrite(V3, statusPU);
}
else
{
Blynk.virtualWrite(V2, "TERTUTUP");
Blynk.virtualWrite(V3, statusPU);
}
}
void setup() {
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(pintuUtama, INPUT);
timer.setInterval(200L, sendData);
}
void loop() {
Blynk.run();
timer.run();