Need help with an order? Email technicaltriveniyt@gmail.com
IoT & Wireless

ESP32 Blynk IoT Smart Relay Switch

A Wi-Fi-enabled home automation switch using the ESP32 DevKit V1 and Blynk IoT cloud to safely control high-voltage AC appliances from a mobile device.

Intermediate2-3 hoursUpdated 18 Oct 2026
Safety first, read before building.

Safety notice

This project involves potentially lethal mains voltage. The ESP32 is a low-voltage device, and its GPIO must never be connected directly to 220V AC. Use a correctly rated relay, suitable isolation, a secure enclosure and appropriate electrical protection. Mains-side assembly and verification must be handled by a qualified electrician.

What you will build and learn

Interface an ESP32 microcontroller with the Blynk IoT cloud platform via Wi-Fi
Implement bidirectional communication using Blynk Virtual Pins and event handlers
Safely drive an optoisolated electromechanical relay module from 3.3V logic
Identify and prevent floating state and boot-glitch issues on ESP32 output GPIOs

Prerequisites

Arduino IDE configured with the ESP32 board package and Blynk library, Registered Blynk.Cloud developer account and mobile application, Basic understanding of AC mains electrical safety, fusing, and isolation

System Overview

This project implements an IoT power-switching node using an ESP32 DevKit V1 connected to the Blynk 2.0 Cloud platform. It enables real-time remote switching of AC mains loads (such as an LED bulb) via a smartphone interface.

Architecture & Operating Principle

The signal and power chain functions as follows:

[Blynk Mobile App] 
       │ (HTTPS/WebSockets)
       ▼
[Blynk Cloud Platform] 
       │ (Wi-Fi 802.11 b/g/n @ 2.4 GHz)
       ▼
[ESP32 DevKit V1] 
       │ (3.3V / 5V Logic GPIO)
       ▼
[Optoisolated Relay Module] 
       │ (Mechanical Dry Contacts: COM & NO)
       ▼
[220V AC Mains Load (Bulb)]
  1. Virtual Pin Mapping: The Blynk dashboard uses Virtual Pin V0 configured as an integer datastream (0 or 1). Actuating the mobile switch triggers an event pushed by Blynk Cloud to the ESP32.
  2. Firmware Handling: The ESP32 firmware intercepts state transitions using the BLYNK_WRITE(V0) macro. The incoming parameter integer (param.asInt()) is evaluated to drive the target output GPIO.
  3. Relay Isolation & Control: The GPIO drives an optocoupler on the relay module. When energized, the relay coil pulls the Normally Open (NO) contact to Common (COM), closing the live conductor of the 220V AC circuit.

Hardware Considerations & Mains Safety

  • Galvanic Isolation: The relay's optoisolator prevents high-voltage inductive spikes or ground faults from backfeeding into the ESP32.
  • Boot State Determinism: Use GPIO pins that do not emit boot glitches (e.g., GPIO 26, 27, or 33) to prevent the relay from momentarily clicking on power-up. This project uses GPIO 26 and 27.
  • AC Wiring: Always switch the Live (Hot) conductor through the relay contacts, leaving Neutral continuous to the load.

Files included in this pack

Esp32 Smart Switch Pack230 KB
Technical Triveni Nodemcu Blynk Relay4.8 KB
Esp32 Smart Switch Pack code5.1 KB
License: MIT

ESP32 Blynk IoT Smart Relay Switch

Intermediate2-3 hours

A Wi-Fi-enabled home automation switch using the ESP32 DevKit V1 and Blynk IoT cloud to safely control high-voltage AC appliances from a mobile device.

Safety first, read before building.

Safety notice

This project involves potentially lethal mains voltage. The ESP32 is a low-voltage device, and its GPIO must never be connected directly to 220V AC. Use a correctly rated relay, suitable isolation, a secure enclosure and appropriate electrical protection. Mains-side assembly and verification must be handled by a qualified electrician.

What you will build and learn

Interface an ESP32 microcontroller with the Blynk IoT cloud platform via Wi-Fi
Implement bidirectional communication using Blynk Virtual Pins and event handlers
Safely drive an optoisolated electromechanical relay module from 3.3V logic
Identify and prevent floating state and boot-glitch issues on ESP32 output GPIOs

Prerequisites

Arduino IDE configured with the ESP32 board package and Blynk library, Registered Blynk.Cloud developer account and mobile application, Basic understanding of AC mains electrical safety, fusing, and isolation

System Overview

This project implements an IoT power-switching node using an ESP32 DevKit V1 connected to the Blynk 2.0 Cloud platform. It enables real-time remote switching of AC mains loads (such as an LED bulb) via a smartphone interface.

Architecture & Operating Principle

The signal and power chain functions as follows:

[Blynk Mobile App] 
       │ (HTTPS/WebSockets)
       ▼
[Blynk Cloud Platform] 
       │ (Wi-Fi 802.11 b/g/n @ 2.4 GHz)
       ▼
[ESP32 DevKit V1] 
       │ (3.3V / 5V Logic GPIO)
       ▼
[Optoisolated Relay Module] 
       │ (Mechanical Dry Contacts: COM & NO)
       ▼
[220V AC Mains Load (Bulb)]
  1. Virtual Pin Mapping: The Blynk dashboard uses Virtual Pin V0 configured as an integer datastream (0 or 1). Actuating the mobile switch triggers an event pushed by Blynk Cloud to the ESP32.
  2. Firmware Handling: The ESP32 firmware intercepts state transitions using the BLYNK_WRITE(V0) macro. The incoming parameter integer (param.asInt()) is evaluated to drive the target output GPIO.
  3. Relay Isolation & Control: The GPIO drives an optocoupler on the relay module. When energized, the relay coil pulls the Normally Open (NO) contact to Common (COM), closing the live conductor of the 220V AC circuit.

Hardware Considerations & Mains Safety

  • Galvanic Isolation: The relay's optoisolator prevents high-voltage inductive spikes or ground faults from backfeeding into the ESP32.
  • Boot State Determinism: Use GPIO pins that do not emit boot glitches (e.g., GPIO 26, 27, or 33) to prevent the relay from momentarily clicking on power-up. This project uses GPIO 26 and 27.
  • AC Wiring: Always switch the Live (Hot) conductor through the relay contacts, leaving Neutral continuous to the load.
₹5.00One-time, instant access