If you want to use the current Blynk IoT platform, use:
#define BLYNK_TEMPLATE_ID "YourTemplateID" #define BLYNK_DEVICE_NAME "YourDeviceName" #define BLYNK_AUTH_TOKEN "YourAuthToken"
#include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h>
The new library is available through Library Manager in Arduino IDE (search "Blynk").
Even with the ZIP file installed, users often face these errors:
Error: 'BlynkSimpleEsp8266.h: No such file or directory'
Error: exit status 1 or Error compiling for board NodeMCU 1.0
Connection Issues (Device keeps connecting/disconnecting)
Here is a minimal working example once the zip is installed correctly. This code connects your ESP8266 to WiFi and Blynk.
// Ensure you have the correct board selected: Tools > Board > ESP8266 > NodeMCU 1.0 #define BLYNK_PRINT Serial // Enables debug output#include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h>
// You should get these from the Blynk app or local server char auth[] = "YourAuthTokenHere"; char ssid[] = "YourWiFiSSID"; char pass[] = "YourWiFiPassword";
void setup() Serial.begin(9600); Blynk.begin(auth, ssid, pass); // For Blynk Legacy local server, use: // Blynk.begin(auth, ssid, pass, "192.168.1.100", 8080);
void loop() Blynk.run(); // This function must be called continuously
// Handle a button on Virtual Pin V1 BLYNK_WRITE(V1) int buttonState = param.asInt(); if(buttonState == 1) // Turn on an LED connected to GPIO 2 digitalWrite(2, HIGH); else digitalWrite(2, LOW);