#define BLYNK_TEMPLATE_ID "TMPL3-uencsME"
#define BLYNK_TEMPLATE_NAME "led with relay"
#define BLYNK_AUTH_TOKEN "7QUNq0Dup9XjQVOTvNMt8Y4KKt4209lH"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
char auth[] = "7QUNq0Dup9XjQVOTvNMt8Y4KKt4209lH";
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
const int relayPin = 15; // GPIO pin connected to the relay module
bool motorState = false;
void setup() {
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(relayPin, OUTPUT);
}
void loop() {
Blynk.run();
}
BLYNK_WRITE(V0) { // Virtual pin V0 in the Blynk app
int value = param.asInt();
if (value == 1) {
digitalWrite(relayPin, HIGH); // Turn the relay on
motorState = true;
} else {
digitalWrite(relayPin, LOW); // Turn the relay off
motorState = false;
}
Serial.println(motorState ? "Motor ON" : "Motor OFF");
}