Skip to content

Guide

Blynk 2.0 Complete Guide for ESP32 and ESP8266 (Blynk IoT)

Everything you need for Blynk 2.0 on ESP32 and ESP8266: the template/datastream model, a starter sketch, a library cheat sheet, HTTP API, notifications and fixes.

  • 6 min read
  • Updated November 2, 2026
Blynk 2.0 Complete Guide for ESP32 and ESP8266 (Blynk IoT)

Quick answer: Blynk 2.0 (Blynk IoT) lets an ESP32 or ESP8266 talk to a ready-made phone app and web dashboard through Blynk.Cloud. The workflow is always the same. Create a template in Blynk.Console, add datastreams (virtual pins V0, V1…), put widgets on the dashboards, create a device to get its Template ID, Template Name and Auth Token, and paste those three lines into a sketch that uses the Blynk Arduino library. In code, BLYNK_WRITE(Vx) receives values from the app, Blynk.virtualWrite(Vx, value) sends values to it, BlynkTimer schedules work without delay(), and Blynk.logEvent() triggers notifications. This guide gives the complete map, a starter sketch for both boards, an API cheat sheet and links to step-by-step projects.

Blynk 2.0 vs Blynk Legacy: the old Blynk app (energy points, QR-code tokens, Blynk.begin(auth, ssid, pass) with no Template ID) has been retired. Tutorials written for it won't work with the current platform. Everything here is for the current Blynk IoT platform.

1. The Blynk model in one table

ConceptWhat it isExample
TemplateThe blueprint for a type of device: datastreams, dashboards, events, automations"Greenhouse node"
DatastreamA named data channel with a type and range, usually on a virtual pinV0 Pump (integer 0–1), V1 Temperature (double, °C)
Virtual pinChannel number V0–V255. Not a GPIO: your code maps it to hardwareV0 → GPIO26 relay
WidgetDashboard control or display linked to a datastreamSwitch on V0, Gauge on V1, Chart on V1
DeviceOne real board created from a template, with its own Auth Token"Greenhouse #1"
EventNamed occurrence the device can log; can trigger push, email or SMS notificationshigh_temp
AutomationCloud rule: Schedule, Sunrise/Sunset, Device State or Scene → actionPump ON at 07:00

Web dashboards (Blynk.Console) and mobile dashboards (Blynk IoT app) are designed separately but use the same datastreams. Full explanation: What is Blynk 2.0?

2. First connection in five steps

  1. Sign up at blynk.cloud and install the Blynk IoT phone app (same login).
  2. Developer Zone → My Templates → New Template: hardware ESP32 or ESP8266, connection WiFi.
  3. Add datastreams and widgets (V0 switch for an LED is the classic first test).
  4. Devices → New Device → From template: copy the three BLYNK_ lines from Device Info.
  5. Install the Blynk library (Volodymyr Shymanskyy) in the Arduino IDE, paste the starter sketch below, add your Wi-Fi details and upload. The device turns Online in the app.

Step-by-step with screenshots: Getting started with Blynk 2.0 on ESP32 or, for NodeMCU, NodeMCU ESP8266 Blynk tutorial.

Manual token or Blynk.Edgent? The manual method (token in the sketch) is best for learning and your own devices. Blynk.Edgent is Blynk's firmware framework that lets users enter their Wi-Fi from the app (provisioning), assigns tokens automatically and supports over-the-air updates. Use it when you build devices for other people. Its example sketches are included with the Blynk library.

Treat the Auth Token like a password: never commit it to a public repo, post it in a forum or show it in a screenshot.

3. Starter sketch (ESP32 or ESP8266)

One switch (V0) controls an LED, and the board sends its uptime to V1 every 5 seconds. It's the skeleton almost every Blynk project grows from.

sketch.ino
#define BLYNK_TEMPLATE_ID   "TMPLxxxxxxxxx"
#define BLYNK_TEMPLATE_NAME "My Device"
#define BLYNK_AUTH_TOKEN    "REPLACE_WITH_DEVICE_AUTH_TOKEN"
#define BLYNK_PRINT Serial                 // connection log in the Serial Monitor

#if defined(ESP32)
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
const int LED_PIN = 23;                  // ESP32: GPIO23
#else
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
const int LED_PIN = D5;                  // NodeMCU: D5 = GPIO14
#endif

char ssid[] = "REPLACE_WITH_WIFI";
char pass[] = "REPLACE_WITH_WIFI_PASSWORD";
BlynkTimer timer;

BLYNK_WRITE(V0) {                          // app → device
  digitalWrite(LED_PIN, param.asInt() ? HIGH : LOW);
}

BLYNK_CONNECTED() {                        // after every (re)connect
  Blynk.syncVirtual(V0);                   // restore the switch state
}

void sendUptime() {                        // device → app
  Blynk.virtualWrite(V1, millis() / 1000);
}

void setup() {
  Serial.begin(115200);
  pinMode(LED_PIN, OUTPUT);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(5000L, sendUptime);
}

void loop() {
  Blynk.run();                             // never block this with delay()
  timer.run();
}

The three #define BLYNK_… lines must come before the includes. Detailed versions: ESP32 LED with Blynk (with a PWM slider and state feedback).

4. Blynk library cheat sheet

CodeDirectionUse
BLYNK_WRITE(V0) { param.asInt(); }App → deviceReact to a switch, slider, button. Also asFloat(), asStr()
Blynk.virtualWrite(V1, value)Device → appSend a sensor reading or state to a widget
Blynk.syncVirtual(V0)Server → deviceRe-run BLYNK_WRITE(V0) with the last stored value
BLYNK_CONNECTED() { }EventRuns after every (re)connection: sync, publish current state
Blynk.logEvent("code", "text")Device → cloudLog an event; triggers its configured notifications
BlynkTimer timer; timer.setInterval(ms, fn)LocalPeriodic tasks without delay()
Blynk.begin(token, ssid, pass)SetupConnects Wi-Fi + cloud; blocks until connected
Blynk.config(token) + Blynk.connect(ms)SetupNon-blocking: your code runs even when offline
Blynk.connected()CheckIs the cloud link up?
BLYNK_WRITE_DEFAULT() + request.pinApp → deviceOne handler for many virtual pins

Sending sensor data the right way: read the sensor in a BlynkTimer function every 2–10 seconds and virtualWrite the result. Writing on every loop() pass floods the cloud, and Blynk rate-limits or disconnects devices that send too often. Example project: DHT11 gauge and history chart with Blynk.

Datastream settings matter: set the right data type (integer, double, string), min/max and units. A Chart widget only shows history for datastreams where history is kept (on by default for most types), and values outside min/max are clamped.

5. Relays, state and safety

For anything beyond an LED:

  • Boot safe: set relay pins OFF in setup() before Blynk.begin(), so nothing switches on during a reboot.
  • Report the real state on a separate datastream (V1 = state, V0 = command), so the app shows what the board actually did.
  • Don't blindly restore a heater or pump after a power cut. Use syncVirtual only for harmless loads.
  • Local control: a physical button that works with no internet, using Blynk.config() + Blynk.connect() instead of the blocking Blynk.begin().
  • Many relay boards are active-low (LOW = ON), and their inputs may not fully release at 3.3 V logic unless wired correctly.

Complete code with all of this: Blynk relay control with ESP32: safe boot, state sync and manual button.

6. Notifications, automations and projects

GoalBlynk featureGuide
Phone alert on motionEvents + logEvent() with a cooldownBlynk PIR motion notifications
Lights at sunset, pump at 7 amAutomations (Schedule, Sunrise/Sunset, Device State)Blynk automations and schedules
Live sensor gauges and historyGauge + Chart widgets, virtualWrite on a timerDHT11 gauge and chart
Automatic plant wateringSensor datastream + pump relay + safety timerESP32 plant watering with Blynk
Camera snapshots on your phoneImage widget + ESP32-CAMESP32-CAM Blynk IoT camera dashboard
Remote security systemEvents, camera, PIRESP32-CAM Blynk remote security system

Event notifications are limited per device per day, so always send events on a state change with a cooldown, never in a loop.

7. HTTP API: control devices without the library

Blynk.Cloud has a simple HTTPS API, handy for scripts, other servers or Home Assistant. Every call uses the device's Auth Token:

ActionRequest
Read a datastreamGET https://blynk.cloud/external/api/get?token=TOKEN&v1
Write a datastreamGET https://blynk.cloud/external/api/update?token=TOKEN&v0=1
Is the device online?GET https://blynk.cloud/external/api/isHardwareConnected?token=TOKEN

Try it in a terminal:

terminal
curl "https://blynk.cloud/external/api/update?token=YOUR_TOKEN&v0=1"
curl "https://blynk.cloud/external/api/get?token=YOUR_TOKEN&v1"

Writing a datastream this way triggers BLYNK_WRITE on the device, just like a tap in the app. If your account lives on a regional server, use that host (shown in Blynk.Console) instead of blynk.cloud. The token is in the URL, so call the API from a server or script you control, never from a public web page. Full reference: Blynk device HTTPS API.

Over-the-air updates: Blynk.Air can push new firmware to Edgent-based devices from the console; availability depends on your plan. For your own devices you can also use ArduinoOTA locally (see the ESP8266 OTA guide).

8. Troubleshooting

SymptomLikely causeFix
BLYNK_TEMPLATE_ID errors when compilingDefines missing or below the includesPut the three BLYNK_ lines at the very top
Invalid auth token in Serial MonitorToken mistyped, or from another deviceCopy it again from Device Info
Stuck at Connecting to …Wrong Wi-Fi password, or 5 GHz-only networkESP32/ESP8266 need 2.4 GHz
Device online but widget does nothingWidget linked to another datastream or deviceCheck the widget's datastream and the device selected
Device drops offline repeatedlydelay() in loop(), flooding virtualWrite, weak powerUse BlynkTimer; send every few seconds; good USB supply
Notifications stoppedDaily event limit reached, or notifications off for the eventSend events on change with a cooldown; enable notifications
Chart is emptyDatastream type/range wrong, or no data sent yetCheck min/max and that virtualWrite uses that pin
App shows ON after a reboot but the relay is OFFNo state syncUse syncVirtual (safe loads) or publish real state in BLYNK_CONNECTED()
Old tutorial code won't connectIt's written for Blynk LegacyUse current examples with Template ID and Name

9. Security and reliability checklist

  • Keep Auth Tokens and Wi-Fi passwords out of public code, screenshots and forum posts; delete or re-create the device if a token leaks.
  • Send data on timers or on change, never every loop.
  • Validate every value from the app before it drives hardware (ranges, allowed values).
  • Define what the device does offline: local buttons and safety limits must not depend on the cloud.
  • A phone switch is not an emergency stop for mains or moving machinery.

10. Blynk vs MQTT vs Node-RED vs Home Assistant

ToolBest fitMain trade-off
BlynkFast phone app and dashboard for your own devices, remote access built inNeeds internet; plan limits
MQTTLocal device-to-device messagingNo app or logic by itself
Node-REDCustom logic, APIs, local dashboardsYou host and secure it
Home AssistantWhole smart home with many brandsMore setup

Detailed comparison with a decision flowchart: Blynk vs Node-RED vs Home Assistant vs MQTT.

Frequently asked questions

Is Blynk free? There's 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 work with the ESP8266 / NodeMCU? Yes: use BlynkSimpleEsp8266.h (the starter sketch above handles both boards).

Are virtual pins physical GPIO pins? No. A virtual pin is a data channel; your code decides which GPIO it controls.

Can Blynk work without internet? No. Every app command goes through Blynk.Cloud. Keep local buttons and safety logic in the firmware, or use MQTT with Node-RED/Home Assistant for local-only control.

Why does my old Blynk tutorial code not work? It was written for Blynk Legacy. Current sketches need BLYNK_TEMPLATE_ID and BLYNK_TEMPLATE_NAME and a token from Blynk.Console.

How often can I send data? Send on a timer (every few seconds) or when a value changes. Writing on every loop() pass will get the device rate-limited or disconnected.

Build deliberately, not just quickly

Start with one datastream and a reliable first connection. Add widgets only when you know what each value means, then make connection status, state sync and offline behaviour explicit. That's the difference between a demo that works once and a device you can trust.

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.