Quick answer: to use a NodeMCU ESP8266 with Blynk IoT (Blynk 2.0), create a free account at blynk.cloud, make a template with a datastream on virtual pin V0 (integer, 0–1), add a Switch widget, then create a device to get its Template ID, Template Name and Auth Token. In the Arduino IDE install the ESP8266 board package and the Blynk library, paste those three lines at the top of the sketch below, and handle the switch in BLYNK_WRITE(V0) with digitalWrite(). Upload, open the Serial Monitor at 115200 baud, and the device shows Online in the console. Flip the switch and the LED follows.
Blynk gives you a phone app and web dashboard without writing any app code: the NodeMCU keeps a connection to the Blynk cloud, and widgets talk to it through virtual pins (V0, V1 …) that you map to real GPIOs in your sketch. This guide gets the first LED working, then adds the two things most tutorials skip: syncing the state after a reboot and sending data back to the dashboard.
Blynk 2.0 vs Blynk Legacy: the old Blynk app (with "energy" points and a QR-code auth token) has been retired. Old tutorials that use only
Blynk.begin(auth, ssid, pass)with no Template ID will not work with the current platform. Everything here uses the current Blynk IoT platform.
| What you need | Notes |
|---|---|
| NodeMCU ESP8266 (v2/v3) | Wemos D1 mini works the same |
| LED + 220–330 Ω resistor, breadboard, jumpers | Or use the onboard LED on GPIO2 (active-low) |
| Micro-USB data cable | Charge-only cables power the board but won't upload |
| Arduino IDE 2.x | With the ESP8266 board package |
| Blynk account (free plan) and the Blynk IoT phone app | Check current plan limits at blynk.io |
| 2.4 GHz Wi-Fi with internet | The ESP8266 has no 5 GHz radio |
Wiring
| NodeMCU pin | GPIO | Connects to |
|---|---|---|
| D5 | GPIO14 | 330 Ω resistor → LED anode (long leg) |
| GND | – | LED cathode (short leg) |
D5 is used because it plays no role at boot. Avoid D3 (GPIO0), D4 (GPIO2) and D8 (GPIO15) for external loads: they are boot-strapping pins and the wrong load can stop the board starting. At 3.3 V, 330 Ω keeps a red LED around 4 mA. Full pin details: NodeMCU ESP8266 pinout.
1. Set up Blynk (template, datastream, widget, device)
Blynk's structure is: Template (the blueprint) → Datastreams (the data channels) → Dashboard widgets → Devices created from the template. If those terms are new, read What is Blynk 2.0? first.
- Log in to blynk.cloud → Developer Zone → My Templates → New Template. Name it
NodeMCU LED, hardware ESP8266, connection WiFi. - Datastreams → New Datastream → Virtual Pin. Create:
| Name | Pin | Data type | Min | Max | Default |
|---|---|---|---|---|---|
| LED | V0 | Integer | 0 | 1 | 0 |
| Uptime | V1 | Integer | 0 | 1000000 | 0 |
- Web Dashboard: drag in a Switch and link it to LED (V0); drag in a Label and link it to Uptime (V1). Click Save.
- Devices → New Device → From template → NodeMCU LED. Blynk shows three lines:
BLYNK_TEMPLATE_ID,BLYNK_TEMPLATE_NAMEandBLYNK_AUTH_TOKEN. Copy them. - On your phone, open the Blynk IoT app, sign in with the same account, open the device and add a Button widget on V0 (mobile dashboards are set up separately from the web dashboard).
Treat the Auth Token like a password: don't paste it into public repos, forum posts or screenshots. Blynk also supports provisioning Wi-Fi from the app with Blynk.Edgent, but the manual token method below is the easiest way to learn.
2. Upload the sketch
- Arduino IDE → Library Manager → search Blynk → install the library by Volodymyr Shymanskyy (version 1.x).
- Select NodeMCU 1.0 (ESP-12E Module) and the right COM port. If no port appears, install the CH340 or CP2102 USB driver that matches your board.
- Replace the three
BLYNK_lines with the ones from your device, add your Wi-Fi name and password, and upload.
The three #define lines must stay above the #include lines, or the library won't see them.
// Paste the three lines from Blynk.Console (Device Info) here. Keep them ABOVE the includes.
#define BLYNK_TEMPLATE_ID "TMPLxxxxxxxxx"
#define BLYNK_TEMPLATE_NAME "NodeMCU LED"
#define BLYNK_AUTH_TOKEN "REPLACE_WITH_DEVICE_AUTH_TOKEN"
#define BLYNK_PRINT Serial // prints connection status to the Serial Monitor
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char ssid[] = "REPLACE_WITH_WIFI_NAME";
char pass[] = "REPLACE_WITH_WIFI_PASSWORD";
const uint8_t LED_PIN = D5; // GPIO14
BlynkTimer timer;
// Runs whenever the V0 switch changes (and after syncVirtual below)
BLYNK_WRITE(V0) {
int value = param.asInt(); // 0 or 1
digitalWrite(LED_PIN, value ? HIGH : LOW);
Serial.printf("V0 = %d\n", value);
}
// Runs every time the board (re)connects to Blynk
BLYNK_CONNECTED() {
Blynk.syncVirtual(V0); // ask the server for the last switch value
}
// Sends uptime in seconds to V1 every 5 s
void sendUptime() {
Blynk.virtualWrite(V1, millis() / 1000);
}
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass); // connects Wi-Fi + Blynk (blocks until connected)
timer.setInterval(5000L, sendUptime);
}
void loop() {
Blynk.run(); // keep this fast: no delay() in loop()
timer.run();
}How it works
| Piece | What it does |
|---|---|
BLYNK_WRITE(V0) | Called when the V0 value changes on the server; param.asInt() gives 0 or 1 |
BLYNK_CONNECTED() + Blynk.syncVirtual(V0) | After a reboot or Wi-Fi drop, fetches the last switch value so the LED matches the app |
Blynk.virtualWrite(V1, …) | Sends data from the board to a widget (sensor readings, status, uptime) |
BlynkTimer | Runs functions on an interval without delay(), which would break the cloud connection |
Blynk.begin() | Simple, but waits until it connects. For a device that must keep working offline, use Blynk.config() + Blynk.connect() and handle Wi-Fi yourself |
Blynk limits how often a device may send data, so push sensor values on a timer (every second or slower is a good start), never on every pass through loop().
3. Test it
- Open the Serial Monitor at 115200 baud. You should see the Blynk logo in ASCII art, then
Connecting to <your Wi-Fi>,Connected to WiFi, andReady (ping: …ms). - In Blynk.Console the device shows a green Online badge, and the Uptime label starts counting.
- Flip the V0 switch on the web or phone dashboard: the LED turns on and the Serial Monitor prints
V0 = 1. - Turn the switch on, press the NodeMCU's RST button, and watch: after it reconnects the LED comes back on by itself. That is
syncVirtualat work.
If the switch moves but nothing prints, the widget is probably linked to a different datastream; if V0 = 1 prints but the LED stays dark, it's wiring.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
'BLYNK_TEMPLATE_ID' was not declared or "Please specify template" | #define lines below the includes, or missing | Put all three BLYNK_ defines at the very top |
Serial shows Invalid auth token | Token from a different device or mistyped | Copy it again from Device Info |
Stuck at Connecting to … | Wrong password, 5 GHz network, or weak signal | Use a 2.4 GHz network; move closer to the router |
| Connected to Wi-Fi, device stays Offline | Old Blynk library, or network blocks outgoing connections | Update the Blynk library; try a phone hotspot to rule out the router |
| Switch moves, nothing in Serial Monitor | Widget linked to the wrong datastream, or device is a different one | Check the widget's datastream and the device name |
V0 = 1 prints but LED stays off | LED reversed, wrong pin, missing GND | Long leg to the resistor/D5 side |
| Onboard LED works inverted | GPIO2 LED is active-low | Write value ? LOW : HIGH |
| Device keeps going offline after a while | delay() in loop(), or too many virtualWrite calls | Use BlynkTimer; send data no faster than about once a second |
| Upload fails / no COM port | Charge-only cable, missing CH340/CP2102 driver, or a load on boot pins | Try another cable, install the driver, unplug wiring on D3/D4/D8 |
| Token was exposed | It was posted publicly | Delete the device (or generate a new token) in Blynk.Console and update the sketch |
FAQ
Is Blynk free for the NodeMCU ESP8266? Yes, Blynk has a free plan suitable for learning and small personal projects, with limits on devices and features. Check blynk.io/pricing for the current limits.
Does Blynk 2.0 still support the ESP8266?
Yes. Use the ESP8266 board package with BlynkSimpleEsp8266.h. New designs are often built on the ESP32, which has more memory, but the ESP8266 works well for switches and simple sensors.
What is a virtual pin? A numbered data channel (V0–V255) between the app and your sketch. It isn't a physical pin: your code decides what V0 does, which might be switching a GPIO, setting a PWM value or sending a sensor reading.
Can I control a relay instead of an LED? Yes. Same code, with a relay module on the GPIO. Many relay modules are active-low (LOW = on), so invert the logic and choose a startup state that keeps the load off. Never wire mains on a breadboard. See ESP32 Blynk relay control with state sync.
Why does my LED turn off after the board restarts?
Without Blynk.syncVirtual(V0) in BLYNK_CONNECTED(), the board starts with the LED off and doesn't ask the server for the last value.
Blynk or MQTT? Blynk gives you a ready-made phone app and cloud. MQTT keeps everything on your own network and works with Node-RED and Home Assistant. Compare them in Blynk vs Node-RED vs Home Assistant, or try the ESP8266 MQTT LED tutorial.
Next steps
- Blynk 2.0 complete guide for ESP32 and ESP8266: every widget and feature in one place.
- Show sensor data with a gauge and history chart: the next step after
virtualWrite. - Blynk automations and schedules: switch the LED on a timetable.
- PIR motion alerts with Blynk events: push notifications to your phone.
- Install ESP8266 in the Arduino IDE, if the board package isn't set up yet.
Official reference: Blynk documentation.




