Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home Home Automation & Smart Devices

Smart Home DIY India: ESP32 WiFi Switches Under ₹500 Each

Smart Home DIY India: ESP32 WiFi Switches Under ₹500 Each

April 1, 2026 /Posted by / 0

Building a smart home in India does not have to be expensive. With an ESP32 development board and a relay module, you can build smart WiFi switches for under ₹500 each — significantly cheaper than commercial options like Sonoff, Wipro Smart, or Philips Hue switches that cost ₹1,000–₹3,000 per switch. The best part? Your DIY ESP32 smart switches are fully customisable and do not depend on any company’s cloud servers.

In this guide, we will show you how to build affordable WiFi-controlled switches that work with your existing Indian switchboards and 230V AC appliances.

Table of Contents

  • Why Build DIY Smart Switches?
  • Cost Breakdown: Under ₹500 Per Switch
  • Components and Tools Needed
  • Building the ESP32 Web-Controlled Switch
  • Adding a Physical Button Override
  • Controlling Multiple Switches from One Dashboard
  • Fitting Inside an Indian Switchboard
  • Frequently Asked Questions
  • Conclusion

Why Build DIY Smart Switches?

Commercial smart switches in India come with several limitations that DIY ESP32 switches do not have:

  • Cost: A single Sonoff Basic costs ₹800–₹1,200. A Wipro Smart switch costs ₹1,500+. Your DIY switch costs under ₹500.
  • Cloud dependency: Most commercial switches require the manufacturer’s cloud server. If the company shuts down or their servers go offline, your switches stop working. DIY switches work entirely on your local network.
  • Customisation: You control the firmware. Add features like scheduling, power monitoring, or integration with any platform you like.
  • Privacy: No data leaves your home network. Commercial switches often send usage data to Chinese or American cloud servers.
  • Learning: Building your own smart switches teaches you about electronics, networking, and programming — skills that are increasingly valuable.

Cost Breakdown: Under ₹500 Per Switch

Here is the actual cost of building one smart WiFi switch in India (prices as of 2026):

Component Approximate Price (₹)
ESP32 Development Board ₹250–₹350
1-Channel 5V Relay Module ₹35–₹60
Hi-Link HLK-PM01 (AC to 5V DC converter) ₹80–₹120
Wires, connectors, push button ₹30–₹50
Total ₹395–₹480

Compare this to a single Sonoff Basic R4 at ₹999 or a Wipro Smart Switch at ₹1,499. You save 50–70% per switch, and those savings multiply when you are automating your entire house.

Components and Tools Needed

🛒 Recommended: ESP32 Development Board CP2102 (38 Pin) — The ideal board for smart home switches with built-in WiFi and Bluetooth. Plenty of GPIO pins for multi-channel control.
🛒 Recommended: 1 Channel 5V 10A Relay Module with Optocoupler — Compact single-channel relay perfect for fitting inside a switchboard. 10A rating handles lights and fans easily.

You will also need:

  • A soldering iron and solder wire
  • Heat-shrink tubing for insulating connections
  • A small push button (for manual override)
  • A micro USB cable for initial programming
  • Arduino IDE installed on your computer

Building the ESP32 Web-Controlled Switch

Our smart switch will host a tiny web server on your home WiFi network. You open a browser on your phone, type the switch’s IP address, and get a simple ON/OFF toggle button. No app installation required — it works on any device with a web browser.

Wiring Diagram

Hi-Link PM01 Input  → 230V AC Live and Neutral
Hi-Link PM01 Output → 5V DC to ESP32 VIN and Relay VCC
ESP32 GPIO 26       → Relay IN1
ESP32 GPIO 27       → Push Button (other leg to GND)
ESP32 GND           → Relay GND, Button GND
Relay COM           → 230V AC Live (from mains)
Relay NO            → Appliance Live wire
230V AC Neutral     → Direct to appliance (not through relay)

Complete ESP32 Smart Switch Code

#include <WiFi.h>
#include <WebServer.h>
#include <Preferences.h>

// WiFi credentials
const char* ssid = "Your_WiFi_SSID";
const char* password = "Your_WiFi_Password";

// Pin definitions
#define RELAY_PIN 26
#define BUTTON_PIN 27

WebServer server(80);
Preferences prefs;
bool relayState = false;
bool lastButtonState = HIGH;
unsigned long lastDebounce = 0;

void setup() {
  Serial.begin(115200);
  
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  
  // Restore last state from flash memory
  prefs.begin("switch", false);
  relayState = prefs.getBool("state", false);
  digitalWrite(RELAY_PIN, relayState ? LOW : HIGH);
  
  // Connect to WiFi
  WiFi.begin(ssid, password);
  WiFi.setAutoReconnect(true);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  
  Serial.print("
IP Address: ");
  Serial.println(WiFi.localIP());
  
  // Web server routes
  server.on("/", handleRoot);
  server.on("/toggle", handleToggle);
  server.on("/status", handleStatus);
  server.begin();
}

void handleRoot() {
  String page = R"rawliteral(
  <!DOCTYPE html><html><head>
  <meta name='viewport' content='width=device-width,initial-scale=1'>
  <title>Smart Switch</title>
  <style>
    body{font-family:Arial;text-align:center;padding:40px;background:#1a1a2e;color:white;}
    .switch-btn{width:120px;height:120px;border-radius:50%;border:4px solid white;
      font-size:20px;font-weight:bold;cursor:pointer;transition:all 0.3s;}
    .on{background:#00b894;box-shadow:0 0 30px #00b894;}
    .off{background:#d63031;box-shadow:0 0 30px #d63031;}
    h1{margin-bottom:30px;}
  </style>
  </head><body>
  <h1>Smart Switch</h1>
  <button class='switch-btn )rawliteral";
  
  page += relayState ? "on" : "off";
  page += "' onclick='fetch("/toggle").then(()=>location.reload())'>";
  page += relayState ? "ON" : "OFF";
  page += "";
  
  server.send(200, "text/html", page);
}

void handleToggle() {
  relayState = !relayState;
  digitalWrite(RELAY_PIN, relayState ? LOW : HIGH);
  prefs.putBool("state", relayState);
  server.send(200, "text/plain", relayState ? "ON" : "OFF");
}

void handleStatus() {
  server.send(200, "text/plain", relayState ? "ON" : "OFF");
}

void loop() {
  server.handleClient();
  
  // Physical button handling with debounce
  bool reading = digitalRead(BUTTON_PIN);
  if (reading != lastButtonState && (millis() - lastDebounce) > 50) {
    lastDebounce = millis();
    if (reading == LOW) { // Button pressed
      relayState = !relayState;
      digitalWrite(RELAY_PIN, relayState ? LOW : HIGH);
      prefs.putBool("state", relayState);
    }
  }
  lastButtonState = reading;
}

This code includes several smart features:

  • State persistence: Uses ESP32’s flash memory to remember the last state across power cuts
  • Physical button: The wall switch still works even if WiFi is down
  • Auto-reconnect: Automatically reconnects to WiFi if the connection drops
  • Responsive web UI: Works perfectly on mobile phones

Adding a Physical Button Override

One of the most important features for a practical smart switch is the physical button override. Your family members should be able to use the switch normally without needing a phone. The code above already handles this — GPIO 27 is configured as a button input with debouncing.

For the physical button, you have two options:

  • Existing wall switch: Wire your existing modular switch in parallel with the relay, using the ESP32 to detect switch state changes
  • Dedicated push button: Mount a small tactile push button on the switchboard cover
🛒 Recommended: 12mm Momentary Tactile Push Button Module — Easy to mount on switchboard panels, with a clean look and satisfying click feel.

Controlling Multiple Switches from One Dashboard

When you have multiple ESP32 switches around your house, you will want a single dashboard to control them all. There are two approaches:

Option 1: mDNS Discovery

Give each ESP32 a unique hostname (e.g., bedroom-light.local, kitchen-fan.local) using the ESPmDNS library. Then create a master dashboard on one ESP32 that queries all other switches.

Option 2: Home Assistant Integration

Install Home Assistant on a Raspberry Pi or old laptop, and configure each ESP32 switch as an MQTT device. This gives you a professional-grade dashboard, automation rules, and voice control through Google Home or Alexa.

We cover the MQTT approach in detail in our MQTT for Home Automation guide.

Fitting Inside an Indian Switchboard

Indian modular switchboards (Anchor Roma, Legrand, Havells) have limited space behind the plate. Here are tips for fitting your ESP32 switch inside:

  • Use an ESP32 Mini: Smaller form factor boards like the ESP32-C3 or Wemos D1 Mini ESP32 fit more easily
  • Mount vertically: Stack the relay module behind the ESP32 with double-sided tape
  • Use a deeper back box: If your wall allows, switch to a deeper back box (available at any electrical shop for ₹30–₹50)
  • External mounting: For older homes with round back boxes, mount the ESP32 setup inside a small plastic junction box beside the switchboard
  • Heat management: Drill small ventilation holes in the enclosure. The ESP32 generates minimal heat, but the Hi-Link power supply can get warm
⚠️ Important: Always ensure proper insulation between the 230V AC side and the 5V DC side. Use heat-shrink tubing on all exposed connections and maintain at least 5mm clearance between AC and DC wiring.

Frequently Asked Questions

Can I use ESP32 with a ceiling fan regulator?

A relay gives you only ON/OFF control. For speed control, you need a TRIAC-based dimmer module (like the BTA16 or RobotDyn AC dimmer). These can be controlled via ESP32 PWM to adjust fan speed in steps.

Will the switch work during internet outages?

Yes. The ESP32 web server runs on your local WiFi network. As long as your router is on (even without internet), you can control the switch from your phone. Only cloud-based features (like Google Home integration) require internet.

How much electricity does the ESP32 switch consume?

An ESP32 in active WiFi mode draws about 80–160mA at 3.3V, which translates to roughly 0.5W. Running 24/7, that is about 0.36 kWh per month — costing less than ₹3/month on most Indian electricity tariffs.

Can I use this with a 3-phase AC supply?

Each relay can switch one phase independently. For 3-phase appliances, you would need 3 relays — one for each phase — triggered simultaneously. However, for most home appliances in India, single-phase switching is sufficient.

What if my WiFi router is far from the switchboard?

The ESP32 has a decent WiFi range (about 10–15 metres through walls). If your router is far away, either use a WiFi repeater or set up an ESP-NOW mesh network between ESP32 devices, with one acting as a gateway near the router.

Conclusion

Building smart WiFi switches with ESP32 is one of the most cost-effective ways to start your smart home journey in India. At under ₹500 per switch, you can automate your entire house for less than the cost of a single commercial smart home kit. The ESP32’s built-in WiFi and Bluetooth, combined with its powerful dual-core processor, make it the ideal brain for your DIY smart home.

Start with one switch — perhaps your bedroom light — and expand from there. Once you experience the convenience of controlling your home from your phone, you will want to automate everything.

Get all the components you need at Zbotic.in — India’s largest electronics component store with fast shipping and genuine products. Browse our relay modules and ESP32 boards to get started today.

Tags: DIY, ESP32, India, smart home, WiFi
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
Electric Vehicle Components In...
blog electric vehicle components india motor controller bms guide 612430
blog best 3d printers under %e2%82%b920000 india 2026 612433
Best 3D Printers Under ₹20,000...

Related posts

Svg%3E
Read more

MQTT for Home Automation: ESP32 + Mosquitto + Home Assistant

April 1, 2026 0
MQTT is the backbone protocol of professional home automation systems. If you are building a smart home with multiple ESP32... Continue reading
Svg%3E
Read more

Curtain and Blind Automation: Stepper Motor Controller

April 1, 2026 0
Curtain automation is one of the most satisfying smart home upgrades you can build. Imagine your curtains opening automatically at... Continue reading
Svg%3E
Read more

Smart Doorbell with Camera: ESP32-CAM Video Intercom

April 1, 2026 0
A smart doorbell with a camera lets you see who is at your door from your phone, even when you... Continue reading
Svg%3E
Read more

Blynk IoT Platform: Control Arduino and ESP32 from Mobile

April 1, 2026 0
The Blynk IoT platform is the fastest way to control your Arduino and ESP32 projects from your mobile phone. Instead... Continue reading
Svg%3E
Read more

PIR Sensor Automatic Light: Save Electricity with Motion Detection

April 1, 2026 0
PIR sensor automatic lights are the simplest and most effective way to save electricity in Indian homes. By automatically turning... Continue reading

Add comment Cancel reply

Your email address will not be published. Required fields are marked

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now