Skip to content
cropped-image.webp

cropped-banner-promo-full-yellow.jpg

Connect with Us

  • Facebook
  • Twitter
  • Linkedin
  • VK
  • Youtube
  • Instagram
Primary Menu
  • Home
  • Blog
Light/Dark Button
Watch Video
  • Home
  • The Lab
  • ESP8266 Home Automation Relay with Blynk App
  • The Lab

ESP8266 Home Automation Relay with Blynk App

Friday February 19, 2026 (Last updated: February 20, 2026) 4 minutes read

Difficulty: Beginner
Time Required: 1 hour
Cost: $8-12
ESP Board: ESP8266 (NodeMCU)

What You’ll Need

Component Approximate Cost Where to Buy
NodeMCU ESP8266 $4-6 Amazon / AliExpress
5V Relay Module $2-4 Amazon
Jumper Wires $2 Amazon
Breadboard $2 Amazon

Circuit Diagram

NodeMCU Pin Component Notes
3.3V Relay VCC Power
GND Relay GND Ground
D1 (GPIO 5) Relay IN Control signal
Vin (5V) Device to control AC device

Step 1: Install Blynk Library

Open Arduino IDE and install:

  • Blynk Library – Official Docs
  • ESP8266 Board Package – Installation Guide

Step 2: Create Blynk App

  1. Download Blynk App from Play Store/App Store
  2. Create new project
  3. Select ESP8266 as hardware
  4. Add Button Widget
  5. Set button to Digital Pin D1
  6. Copy Auth Token (sent to email)

Step 3: The Complete Code

/*********************************************************************
 * ESP8266 Home Automation Relay with Blynk App
 * 
 * Control any AC device from your phone
 * Hardware: NodeMCU ESP8266, 5V Relay
 * 
 * Libraries Required:
 * - Blynk (install from Library Manager)
 * - ESP8266 WiFi (built-in)
 * 
 * Pin: D1 (GPIO 5) for relay control
 *********************************************************************/

#define BLYNK_TEMPLATE_ID "YOUR_TEMPLATE_ID"
#define BLYNK_TEMPLATE_NAME "Home Automation"
#define BLYNK_AUTH_TOKEN "YOUR_AUTH_TOKEN"

#include 
#include 

// ============== WIFI CONFIGURATION ==============
const char* wifi_ssid = "YOUR_WIFI_NAME";
const char* wifi_password = "YOUR_WIFI_PASSWORD";

// ============== RELAY PIN ==============
#define RELAY_PIN D1  // GPIO 5
#define LED_PIN D4    // Built-in LED (GPIO 2)

// ============== STATE VARIABLES ==============
bool relayState = false;
bool wifiConnected = false;

// ============== SETUP ==============
void setup() {
  Serial.begin(115200);
  Serial.println(F("\n======================================"));
  Serial.println(F("ESP8266 Home Automation Starting..."));
  Serial.println(F("======================================"));
  
  // Configure pins
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  
  // Initial state - relay OFF
  digitalWrite(RELAY_PIN, HIGH);  // Relay is active LOW
  digitalWrite(LED_PIN, HIGH);   // LED OFF
  
  // Connect to WiFi
  connectToWiFi();
  
  // Initialize Blynk
  Blynk.begin(BLYNK_AUTH_TOKEN, wifi_ssid, wifi_password);
  
  Serial.println(F("Setup complete!"));
  Serial.println(F("Use Blynk app to control the relay."));
}

// ============== MAIN LOOP ==============
void loop() {
  // Run Blynk
  Blynk.run();
  
  // Check WiFi connection
  if (WiFi.status() != WL_CONNECTED) {
    wifiConnected = false;
    digitalWrite(LED_PIN, LOW);  // LED ON when disconnected
  } else {
    wifiConnected = true;
  }
}

// ============== BLYNK CONNECTED ==============
BLYNK_CONNECTED() {
  Serial.println(F("Blynk connected!"));
  Blynk.syncVirtual(V0);  // Sync relay state
}

// ============== VIRTUAL PIN V0 - RELAY CONTROL ==============
BLYNK_WRITE(V0) {
  int pinValue = param.asInt();
  
  if (pinValue == 1) {
    digitalWrite(RELAY_PIN, LOW);   // Turn ON
    relayState = true;
    digitalWrite(LED_PIN, LOW);    // LED ON
    Serial.println(F("Relay: ON"));
  } else {
    digitalWrite(RELAY_PIN, HIGH);  // Turn OFF
    relayState = false;
    digitalWrite(LED_PIN, HIGH);   // LED OFF
    Serial.println(F("Relay: OFF"));
  }
}

// ============== VIRTUAL PIN V1 - TOGGLE BUTTON ==============
BLYNK_WRITE(V1) {
  // Toggle relay
  relayState = !relayState;
  digitalWrite(RELAY_PIN, relayState ? LOW : HIGH);
  digitalWrite(LED_PIN, relayState ? LOW : HIGH);
  
  // Update Blynk
  Blynk.virtualWrite(V0, relayState ? 1 : 0);
  
  Serial.print(F("Toggle: "));
  Serial.println(relayState ? F("ON") : F("OFF"));
}

// ============== HELPER FUNCTION ==============
void connectToWiFi() {
  Serial.print(F("Connecting to WiFi"));
  WiFi.begin(wifi_ssid, wifi_password);
  
  int attempts = 0;
  while (WiFi.status() != WL_CONNECTED && attempts < 20) {
    delay(500);
    Serial.print(F("."));
    attempts++;
  }
  
  if (WiFi.status() == WL_CONNECTED) {
    Serial.println(F(" Connected!"));
    Serial.print(F("IP Address: "));
    Serial.println(WiFi.localIP());
    wifiConnected = true;
  } else {
    Serial.println(F(" Connection failed!"));
  }
}

// ============== END OF CODE ==============

Step 4: Configure Blynk App

  1. Open Blynk app
  2. Add Button Widget → Set to Virtual Pin V0
  3. Add Button Widget → Set to Virtual Pin V1 → Mode: Switch
  4. Add LED Widget → Set to Virtual Pin V2
  5. Set button ON/OFF labels

Step 5: Upload and Test

  1. Connect NodeMCU via USB
  2. Select Tools → Board → NodeMCU 1.0
  3. Select correct port
  4. Click Upload
  5. Open Serial Monitor
  6. Check connection status
  7. Control relay from Blynk app

Troubleshooting

Problem Solution
Blynk not connecting Check Auth Token; ensure WiFi is 2.4GHz only
Relay always ON Relay is active LOW; use digitalWrite(HIGH) to turn OFF
NodeMCU not detected Install CH340 drivers
WiFi connection failed Verify SSID/password; check signal strength
Relay clicking but no power Check device wiring; ensure AC device is plugged in

Official Documentation

  • Blynk Getting Started - Official guide
  • Blynk GitHub - Library source
  • ESP8266 Arduino Documentation - Official reference

Enhancement Ideas

  • Add multiple relays for whole-home control
  • Integrate with Home Assistant
  • Add MQTT for voice assistants
  • Add timer/schedule functionality in Blynk

Frequently Asked Questions

Q: Can I control 220V devices?

A: Yes, but use proper isolation. The relay handles up to 250V AC/10A. Always use caution with AC voltage.

Q: Does Blynk have a monthly fee?

A: The original Blynk has subscription tiers. Blynk IoT offers a generous free tier for personal projects.

Q: Can I use ESP32 instead?

A: Yes. Use the same code with BlynkSimpleEsp32.h library.

Q: How do I add multiple relays?

A: Use different pins (D2, D3, etc.) and create additional virtual pins in Blynk.

Q: Is this secure?

A: For home use, it's reasonably secure. For public networks, consider adding authentication.

About The Author

Friday

See author's posts

Post navigation

Previous: ESP32-CAM Smart Doorbell with Camera & Notifications
Next: ESP32 Air Quality Monitor with MQ Sensors

Related Stories

  • The Lab

Raspberry Pi Pico vs ESP32: Which Should You Choose? 2026

Friday March 4, 2026
  • The Lab

ESP32-C3 vs ESP32-S3: Detailed Comparison 2026

Friday March 4, 2026
  • The Lab

STM32 vs ESP32: Battle of the Microcontrollers 2026

Friday March 3, 2026

Connect with Us

  • Facebook
  • Twitter
  • Linkedin
  • VK
  • Youtube
  • Instagram

Trending News

7 Best Shopify Alternatives for Dropshipping in 2026 1
  • Latest News

7 Best Shopify Alternatives for Dropshipping in 2026

Friday March 4, 2026
ESP32-C3 vs ESP32-S3: Detailed Comparison 2026 2
  • The Lab

ESP32-C3 vs ESP32-S3: Detailed Comparison 2026

Friday March 4, 2026
Raspberry Pi Pico vs ESP32: Which Should You Choose? 2026 3
  • The Lab

Raspberry Pi Pico vs ESP32: Which Should You Choose? 2026

Friday March 4, 2026
STM32 vs ESP32: Battle of the Microcontrollers 2026 4
  • The Lab

STM32 vs ESP32: Battle of the Microcontrollers 2026

Friday March 3, 2026
Arduino Mega vs ESP32: Processing Power Face-off 2026 5
  • The Lab

Arduino Mega vs ESP32: Processing Power Face-off 2026

Friday March 3, 2026

You May Have Missed

  • Latest News

7 Best Shopify Alternatives for Dropshipping in 2026

Friday March 4, 2026
  • The Lab

ESP32-C3 vs ESP32-S3: Detailed Comparison 2026

Friday March 4, 2026
  • The Lab

Raspberry Pi Pico vs ESP32: Which Should You Choose? 2026

Friday March 4, 2026
  • The Lab

STM32 vs ESP32: Battle of the Microcontrollers 2026

Friday March 3, 2026
CoreEcom provides honest, research-backed reviews and essential guides. We filter the noise to help global consumers find quality products that deliver real value, ensuring every purchase is a smart investment.

Categories

Buyer's Manuals Deep Reviews Editor's Choice Latest News Setup Guides The Lab

Quick Links

  • About
  • Editorial Standards
  • Privacy
  • Impressum
  • Contact
  • Facebook
  • Twitter
  • Linkedin
  • VK
  • Youtube
  • Instagram
Copyright © Growthscout 2026 All rights reserved. | ReviewNews by AF themes.