#define BLYNK_TEMPLATE_ID "TMPL3J75tDH5M"
#define BLYNK_TEMPLATE_NAME "led"
#define BLYNK_AUTH_TOKEN "a1UBc-umP8ALxuvZKjO0ouONJLhgkaZG"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Your WiFi credentials
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
const int ledPin = 2; // GPIO2 (D2) for external LED
// This function is called every time the button widget on Virtual Pin V0 changes state
BLYNK_WRITE(V0)
{
int pinValue = param.asInt(); // Get the value from the button (0 or 1)
if (pinValue) {
digitalWrite(ledPin, HIGH); // Turn on the LED
Serial.println("LED is ON");
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
Serial.println("LED is OFF");
}
}
void setup()
{
Serial.begin(115200);
pinMode(ledPin, OUTPUT); // Configure GPIO2 as an output
digitalWrite(ledPin, LOW); // Ensure the LED starts off
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass); // Connect to Blynk platform
}
void loop()
{
Blynk.run(); // Run the Blynk library
}