Build your own smart switch: an ESP8266 hosts a tiny web server so you can toggle a relay — and whatever is connected to it — from any phone or laptop on your network.
What you’ll build
A WiFi-controlled switch. The ESP8266 NodeMCU connects to your home WiFi and exposes simple /on and /off web endpoints that switch the 5V relay module, letting you control a connected appliance remotely.
Components you’ll need
Step-by-step guide
- Mount the ESP8266 NodeMCU on the breadboard and power the rails from its 3V3 and GND pins.
- Connect the relay module: VCC to Vin (5V), GND to GND, and IN to GPIO5 (D1).
- Keep the mains/appliance wiring for later — first test the relay with just the low-voltage side.
- In the Arduino IDE, install the ESP8266 board package and select NodeMCU 1.0 as the board.
- Edit the sketch with your WiFi name and password, then upload it.
- Open the Serial Monitor to find the ESP8266 IP address, then visit http://THAT-IP/on and /off from your phone to switch the relay.
The code
This sketch connects to WiFi and serves two endpoints that switch the relay on and off.
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
const char* ssid="YOUR_WIFI"; const char* pass="YOUR_PASS";
ESP8266WebServer server(80); const int relay=5;
void setup(){ pinMode(relay,OUTPUT); WiFi.begin(ssid,pass);
server.on("/on",[](){digitalWrite(relay,HIGH);server.send(200,"text/plain","ON");});
server.on("/off",[](){digitalWrite(relay,LOW);server.send(200,"text/plain","OFF");});
server.begin(); }
void loop(){ server.handleClient(); }Build this project
Add all 4 required components to your cart in one click — total ₹396.
Add all components to cart