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
| Concept | What it is | Example |
|---|---|---|
| Template | The blueprint for a type of device: datastreams, dashboards, events, automations | "Greenhouse node" |
| Datastream | A named data channel with a type and range, usually on a virtual pin | V0 Pump (integer 0–1), V1 Temperature (double, °C) |
| Virtual pin | Channel number V0–V255. Not a GPIO: your code maps it to hardware | V0 → GPIO26 relay |
| Widget | Dashboard control or display linked to a datastream | Switch on V0, Gauge on V1, Chart on V1 |
| Device | One real board created from a template, with its own Auth Token | "Greenhouse #1" |
| Event | Named occurrence the device can log; can trigger push, email or SMS notifications | high_temp |
| Automation | Cloud rule: Schedule, Sunrise/Sunset, Device State or Scene → action | Pump 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
- Sign up at blynk.cloud and install the Blynk IoT phone app (same login).
- Developer Zone → My Templates → New Template: hardware ESP32 or ESP8266, connection WiFi.
- Add datastreams and widgets (V0 switch for an LED is the classic first test).
- Devices → New Device → From template: copy the three
BLYNK_lines from Device Info. - 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.
#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
| Code | Direction | Use |
|---|---|---|
BLYNK_WRITE(V0) { param.asInt(); } | App → device | React to a switch, slider, button. Also asFloat(), asStr() |
Blynk.virtualWrite(V1, value) | Device → app | Send a sensor reading or state to a widget |
Blynk.syncVirtual(V0) | Server → device | Re-run BLYNK_WRITE(V0) with the last stored value |
BLYNK_CONNECTED() { } | Event | Runs after every (re)connection: sync, publish current state |
Blynk.logEvent("code", "text") | Device → cloud | Log an event; triggers its configured notifications |
BlynkTimer timer; timer.setInterval(ms, fn) | Local | Periodic tasks without delay() |
Blynk.begin(token, ssid, pass) | Setup | Connects Wi-Fi + cloud; blocks until connected |
Blynk.config(token) + Blynk.connect(ms) | Setup | Non-blocking: your code runs even when offline |
Blynk.connected() | Check | Is the cloud link up? |
BLYNK_WRITE_DEFAULT() + request.pin | App → device | One 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()beforeBlynk.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
syncVirtualonly for harmless loads. - Local control: a physical button that works with no internet, using
Blynk.config()+Blynk.connect()instead of the blockingBlynk.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
| Goal | Blynk feature | Guide |
|---|---|---|
| Phone alert on motion | Events + logEvent() with a cooldown | Blynk PIR motion notifications |
| Lights at sunset, pump at 7 am | Automations (Schedule, Sunrise/Sunset, Device State) | Blynk automations and schedules |
| Live sensor gauges and history | Gauge + Chart widgets, virtualWrite on a timer | DHT11 gauge and chart |
| Automatic plant watering | Sensor datastream + pump relay + safety timer | ESP32 plant watering with Blynk |
| Camera snapshots on your phone | Image widget + ESP32-CAM | ESP32-CAM Blynk IoT camera dashboard |
| Remote security system | Events, camera, PIR | ESP32-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:
| Action | Request |
|---|---|
| Read a datastream | GET https://blynk.cloud/external/api/get?token=TOKEN&v1 |
| Write a datastream | GET 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:
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
| Symptom | Likely cause | Fix |
|---|---|---|
BLYNK_TEMPLATE_ID errors when compiling | Defines missing or below the includes | Put the three BLYNK_ lines at the very top |
Invalid auth token in Serial Monitor | Token mistyped, or from another device | Copy it again from Device Info |
Stuck at Connecting to … | Wrong Wi-Fi password, or 5 GHz-only network | ESP32/ESP8266 need 2.4 GHz |
| Device online but widget does nothing | Widget linked to another datastream or device | Check the widget's datastream and the device selected |
| Device drops offline repeatedly | delay() in loop(), flooding virtualWrite, weak power | Use BlynkTimer; send every few seconds; good USB supply |
| Notifications stopped | Daily event limit reached, or notifications off for the event | Send events on change with a cooldown; enable notifications |
| Chart is empty | Datastream type/range wrong, or no data sent yet | Check min/max and that virtualWrite uses that pin |
| App shows ON after a reboot but the relay is OFF | No state sync | Use syncVirtual (safe loads) or publish real state in BLYNK_CONNECTED() |
| Old tutorial code won't connect | It's written for Blynk Legacy | Use 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
| Tool | Best fit | Main trade-off |
|---|---|---|
| Blynk | Fast phone app and dashboard for your own devices, remote access built in | Needs internet; plan limits |
| MQTT | Local device-to-device messaging | No app or logic by itself |
| Node-RED | Custom logic, APIs, local dashboards | You host and secure it |
| Home Assistant | Whole smart home with many brands | More setup |
Detailed comparison with a decision flowchart: Blynk vs Node-RED vs Home Assistant vs MQTT.
11. The SolderHub Blynk learning path
Beginner
- What is Blynk 2.0? Templates, datastreams, devices and dashboards
- Getting started with Blynk 2.0 on ESP32
- Control an ESP32 LED from the Blynk app
- NodeMCU ESP8266 with Blynk
Intermediate
- DHT11 gauge and history chart with Blynk
- Blynk relay control with state sync
- PIR motion notifications with Blynk events
- Blynk automations and schedules
- ESP32 plant watering with Blynk
Projects
- ESP32-CAM Blynk IoT camera dashboard
- ESP32-CAM Blynk sensor monitoring
- ESP32-CAM Blynk remote security system
Official references
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.




