Skip to content

Tutorial

ESP32 Blynk LED Control: On/Off and Brightness from Your Phone

Turn an ESP32 LED on/off and dim it from the Blynk app: safe GPIO choice, template and datastreams, full sketch with PWM, state feedback and sync, and fixes.

  • 4 min read
  • Updated November 2, 2026
ESP32 Blynk LED Control: On/Off and Brightness from Your Phone

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 needNotes
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 Ω resistorOr 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 appFree plan is enough

Which GPIO should drive the LED?

OptionGPIONotes
External LED (recommended)GPIO23No boot-time role, PWM-capable, easy to reach on the DevKit V1
Onboard LEDGPIO2Blue LED on most DevKit V1 boards, active-high. Some boards use another pin or have no user LED
AvoidGPIO0, 2, 5, 12, 15 for external loadsBoot-strapping pins: an external load can stop the board booting or uploading
Can't be outputsGPIO34–39Input-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 pinConnects to
GPIO23330 Ω resistor → LED anode (long leg)
GNDLED 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

  1. In blynk.cloud → Developer Zone → My Templates → New Template: name SolderHub LED, hardware ESP32, connection WiFi.
  2. Datastreams → New Datastream → Virtual Pin:
NamePinData typeMinMaxDefaultPurpose
LEDV0Integer010On/off command from the switch
BrightnessV1Integer0255255PWM level from the slider
LED stateV2Integer010Reported back by the ESP32
  1. Web Dashboard: add a Switch on V0, a Slider on V1 and an LED widget on V2. Save.
  2. Devices → New Device → From template. Copy the three BLYNK_ lines shown on the device's Device Info tab.
  3. 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

  1. Arduino IDE → Library Manager → install Blynk by Volodymyr Shymanskyy.
  2. Select your board (for example ESP32 Dev Module) and port.
  3. Paste the sketch, replace the three BLYNK_ lines and the Wi-Fi details, and upload. The #define lines must stay above the #include lines.
sketch.ino
// 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

LineWhat 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() + syncVirtualAfter a reboot or Wi-Fi drop, restores the last switch and slider values from the server

4. Test it

  1. Open the Serial Monitor at 115200 baud. You should see the Blynk banner, Connected to WiFi and Ready (ping: …ms), and the device turns Online in the app.
  2. Flip the V0 switch: the LED lights, Serial prints LED ON, and the V2 LED widget turns on.
  3. Move the slider: the brightness changes smoothly.
  4. 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

SymptomLikely causeFix
Compile error about BLYNK_TEMPLATE_IDThe defines are missing or below the includesPut the three BLYNK_ lines at the very top
Serial: Invalid auth tokenToken mistyped or from another deviceCopy it again from Device Info
Stuck on Connecting to …Wrong password or 5 GHz-only networkThe ESP32 needs 2.4 GHz Wi-Fi
Device Online, switch does nothingWidget linked to the wrong datastream, or editing another deviceCheck the widget's datastream and device name
Serial prints LED ON but LED is darkLED reversed, wrong GPIO, missing GNDLong leg to the resistor; confirm GPIO23 on your board's silkscreen
Slider has no effectSlider not on V1, or the LED is OFFTurn the switch on first; check the slider's datastream
Board won't boot or upload with LED fittedLED on a strapping pin (0, 2, 12, 15)Move it to GPIO23
Device drops offline repeatedlydelay() in loop(), weak Wi-Fi, poor USB powerKeep loop() to Blynk.run(); use a good cable/supply
Token leakedPosted publiclyDelete 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

Official references: Blynk documentation and manual device activation.

Continue learning

Related articles

All articles

Signal In

Built from what makers search for

The lookups piling up in SolderHub's search bar every day shape what we publish next — new component pages, board guides, and firmware notes, sent out as they go live.

By subscribing you agree to our Privacy Policy. Unsubscribe anytime.