Quick answer: to turn an ESP32 LED on and off with Blynk, create a template with a datastream on virtual pin V0 (integer 0–1) and add a Switch widget to it. Create a device and copy its Template ID, Template Name and Auth Token into the top of the sketch below. In BLYNK_WRITE(V0), write the value to the LED's GPIO with digitalWrite(). Wire the LED from GPIO23 through a 220–330 Ω resistor to GND (or use the onboard LED on GPIO2), upload, and flip the switch in the Blynk app. This guide also adds a brightness slider (PWM on V1) and an LED widget that shows the real state, so the app always matches the board.
The key idea: a virtual pin (V0, V1…) is not a physical pin. It's a data channel between the Blynk app and your sketch. Your code decides that V0 means "GPIO23 on/off" and V1 means "GPIO23 brightness". That separation is what lets the same pattern grow into relays, motors and sensors later.
| What you need | Notes |
|---|---|
| ESP32 dev board (DevKit V1 / WROOM-32) | ESP32-S3 and C3 work too; pick a free GPIO from their pinout |
| 5 mm LED + 220–330 Ω resistor | Or just the onboard LED (GPIO2 on most DevKits) |
| Breadboard, jumper wires, USB data cable | |
| Arduino IDE 2.x with the ESP32 board package | |
| Blynk account + Blynk IoT phone app | Free plan is enough |
Which GPIO should drive the LED?
| Option | GPIO | Notes |
|---|---|---|
| External LED (recommended) | GPIO23 | No boot-time role, PWM-capable, easy to reach on the DevKit V1 |
| Onboard LED | GPIO2 | Blue LED on most DevKit V1 boards, active-high. Some boards use another pin or have no user LED |
| Avoid | GPIO0, 2, 5, 12, 15 for external loads | Boot-strapping pins: an external load can stop the board booting or uploading |
| Can't be outputs | GPIO34–39 | Input-only |
Full details: ESP32 pinout guide. At 3.3 V with a red LED (about 2 V forward voltage), 330 Ω gives roughly 4 mA, which is bright enough and well within the pin's limits.
1. Wire the LED
| ESP32 pin | Connects to |
|---|---|
| GPIO23 | 330 Ω resistor → LED anode (long leg) |
| GND | LED cathode (short leg, flat edge) |
Never connect an LED straight from a GPIO to GND without the resistor, and never drive a relay coil, motor or buzzer module's coil directly from a GPIO: they need a driver transistor or a relay module (see the Blynk relay control guide).
No hardware yet? The same sketch runs in the free Wokwi online simulator, which can reach Blynk.Cloud: use the SSID Wokwi-GUEST with an empty password.
2. Set up the template, datastreams and widgets
- In blynk.cloud → Developer Zone → My Templates → New Template: name
SolderHub LED, hardware ESP32, connection WiFi. - Datastreams → New Datastream → Virtual Pin:
| Name | Pin | Data type | Min | Max | Default | Purpose |
|---|---|---|---|---|---|---|
| LED | V0 | Integer | 0 | 1 | 0 | On/off command from the switch |
| Brightness | V1 | Integer | 0 | 255 | 255 | PWM level from the slider |
| LED state | V2 | Integer | 0 | 1 | 0 | Reported back by the ESP32 |
- Web Dashboard: add a Switch on V0, a Slider on V1 and an LED widget on V2. Save.
- Devices → New Device → From template. Copy the three
BLYNK_lines shown on the device's Device Info tab. - In the Blynk IoT phone app, open the device, tap the wrench and add the same three widgets. Mobile and web dashboards are configured separately.
Treat the Auth Token like a password: keep it out of public repos, forum posts and screenshots. New to templates and datastreams? Read What is Blynk 2.0?.
3. Upload the sketch
- Arduino IDE → Library Manager → install Blynk by Volodymyr Shymanskyy.
- Select your board (for example ESP32 Dev Module) and port.
- Paste the sketch, replace the three
BLYNK_lines and the Wi-Fi details, and upload. The#definelines must stay above the#includelines.
// From Blynk.Console → your device → Device Info. Keep these ABOVE the includes.
#define BLYNK_TEMPLATE_ID "TMPLxxxxxxxxx"
#define BLYNK_TEMPLATE_NAME "SolderHub LED"
#define BLYNK_AUTH_TOKEN "REPLACE_WITH_DEVICE_AUTH_TOKEN"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
char ssid[] = "REPLACE_WITH_WIFI_NAME";
char pass[] = "REPLACE_WITH_WIFI_PASSWORD";
const int LED_PIN = 23; // external LED; use 2 for the onboard LED
bool ledOn = false;
int brightness = 255; // 0-255
void applyLed() {
analogWrite(LED_PIN, ledOn ? brightness : 0); // PWM on the ESP32 Arduino core
Blynk.virtualWrite(V2, ledOn ? 1 : 0); // report real state to the LED widget
}
BLYNK_WRITE(V0) { // Switch: 0 or 1
ledOn = param.asInt() == 1;
applyLed();
Serial.printf("LED %s\n", ledOn ? "ON" : "OFF");
}
BLYNK_WRITE(V1) { // Slider: 0-255
brightness = constrain(param.asInt(), 0, 255);
applyLed();
}
BLYNK_CONNECTED() { // after every (re)connect, fetch the last switch and slider values
Blynk.syncVirtual(V0, V1);
}
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW); // safe, known state at boot
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop() {
Blynk.run(); // keep loop() free of delay()
}How the sketch works
| Line | What it does |
|---|---|
BLYNK_WRITE(V0) | Runs each time the switch changes; param.asInt() is 0 or 1 |
BLYNK_WRITE(V1) | Runs when the slider moves; the value sets the PWM duty (0–255) |
analogWrite() | PWM output on ESP32 Arduino core 2.0.x and 3.x; for finer control use the LEDC functions (see the ESP32 PWM guide) |
Blynk.virtualWrite(V2, …) | Sends the applied state back, so the LED widget shows what the board actually did |
BLYNK_CONNECTED() + syncVirtual | After a reboot or Wi-Fi drop, restores the last switch and slider values from the server |
4. Test it
- Open the Serial Monitor at 115200 baud. You should see the Blynk banner,
Connected to WiFiandReady (ping: …ms), and the device turns Online in the app. - Flip the V0 switch: the LED lights, Serial prints
LED ON, and the V2 LED widget turns on. - Move the slider: the brightness changes smoothly.
- Leave the switch ON and press the board's EN (reset) button: after reconnecting, the LED comes back on by itself.
Command vs state: why V2 exists
V0 is what the user asked for; V2 is what the board reports it did. For an LED they're almost always equal. For a relay, a pump or a gate they can differ (no power, a stuck relay, the board offline), and showing the reported state is what makes a dashboard trustworthy.
The sketch starts with the LED off at boot, then applies the last switch value once it connects. That's right for an LED or a lamp. For something that must never switch on by surprise after a power cut, such as a heater or a motor, skip the syncVirtual for that pin, start OFF, and push the OFF state to the app instead: Blynk.virtualWrite(V0, 0) in BLYNK_CONNECTED().
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Compile error about BLYNK_TEMPLATE_ID | The defines are missing or below the includes | Put the three BLYNK_ lines at the very top |
Serial: Invalid auth token | Token mistyped or from another device | Copy it again from Device Info |
Stuck on Connecting to … | Wrong password or 5 GHz-only network | The ESP32 needs 2.4 GHz Wi-Fi |
| Device Online, switch does nothing | Widget linked to the wrong datastream, or editing another device | Check the widget's datastream and device name |
Serial prints LED ON but LED is dark | LED reversed, wrong GPIO, missing GND | Long leg to the resistor; confirm GPIO23 on your board's silkscreen |
| Slider has no effect | Slider not on V1, or the LED is OFF | Turn the switch on first; check the slider's datastream |
| Board won't boot or upload with LED fitted | LED on a strapping pin (0, 2, 12, 15) | Move it to GPIO23 |
| Device drops offline repeatedly | delay() in loop(), weak Wi-Fi, poor USB power | Keep loop() to Blynk.run(); use a good cable/supply |
| Token leaked | Posted publicly | Delete the device (or generate a new token) and update the sketch |
FAQ
What is a virtual pin in Blynk? A numbered data channel (V0–V255) between the app and your code. It isn't wired to anything: your sketch decides what each one controls or reports.
Can I control the ESP32 onboard LED?
Yes. On most DevKit V1 boards it's on GPIO2 and lights when the pin is HIGH. Set LED_PIN = 2. Boards differ, so check yours.
Do I need Blynk.Edgent? No. Edgent adds Wi-Fi provisioning from the app and over-the-air updates. The manual token method here is simpler for learning; switch to Edgent when you build devices for other people.
Can I control several LEDs?
Yes: one datastream and one BLYNK_WRITE(Vx) per LED, each with its own GPIO.
Does it work without internet? No. Blynk.Cloud relays every command. For local-only control, use MQTT with Node-RED or Home Assistant instead: Control an ESP32 LED with Node-RED and MQTT.
Before switching anything bigger
An LED is a safe first load. For lamps or appliances, use a properly rated relay module with its own driver, check whether it is active-low, decide what state it takes at boot and when Wi-Fi drops, and never wire mains on a breadboard. An app button is not an emergency stop.
Next steps
- Blynk relay control with state sync: the same pattern driving a relay safely.
- Blynk gauge and history chart with a DHT11: send sensor data the other way.
- Blynk automations and schedules: switch the LED on a timetable.
- Getting started with Blynk 2.0 on ESP32 and the complete Blynk 2.0 guide.
- Using a NodeMCU instead? NodeMCU ESP8266 Blynk tutorial.
Official references: Blynk documentation and manual device activation.




