Step‑by‑Step Guide: Build a Voice‑Activated Light Switch for $25 and Cut Your Energy Bills
Read this article in clean Markdown format for LLMs and AI context.Ever walked into a room, fumbled for a switch, and thought “there’s got to be an easier way?” You’re not alone. At Smart Home Lab we love taking everyday annoyances and turning them into simple, cheap projects. Today I’m walking you through a voice‑activated light switch you can build for around $25. No soldering marathon, no fancy tools—just a few components, a little patience, and a lot of satisfaction when the lights turn on with a single “Hey Google.”
What You’ll Need
The cheap Wi‑Fi switch
A Sonoff Basic (or any $5‑$7 Wi‑Fi relay) is the heart of the project. It gives you a solid, internet‑ready relay that can be controlled via MQTT, HTTP, or the official eWeLink app.
The microphone module
A simple ESP‑32 board with a built‑in I2S microphone costs about $8. The ESP‑32 is powerful enough to run a tiny voice detection model locally, so you don’t have to rely on the cloud for every command.
Power supply
You’ll need a 5 V 2 A USB wall adapter (the kind you use for a phone charger) and a short piece of 22‑AWG wire to connect the ESP‑32 to the Sonoff.
Optional but handy
- A small project box (plastic, $2) to keep everything tidy.
- A pair of heat‑shrink tubes for neat connections.
All of these items add up to roughly $25, give or take a dollar depending on where you shop.
Wiring It Up
Safety first
Before you touch any wires, cut power at the breaker. This is a low‑voltage project, but you’ll be working inside the wall box where mains electricity lives. Double‑check with a non‑contact voltage tester.
Connect the relay
- Open the Sonoff case and locate the “Live” (L) and “Neutral” (N) terminals.
- Strip the ends of the existing switch wires and connect the live wire to the Sonoff’s L terminal.
- Connect the Sonoff’s output (O) to the fixture’s live wire.
- Tie the neutral wires together as they were before and leave them untouched.
Hook up the microphone
- Solder the ESP‑32’s 5 V and GND pins to the USB adapter’s output.
- Use a jumper wire to connect the ESP‑32’s GPIO pin (we’ll use GPIO 12) to the Sonoff’s control input (the “IN” pin).
- Place the ESP‑32 inside the project box, mount the microphone facing outward, and seal the box.
That’s it for the hardware. You now have a relay that can be toggled by the ESP‑32 whenever it hears the right phrase.
Adding Voice Control
Choose your platform
At Smart Home Lab we usually go with Home Assistant because it runs on a Raspberry Pi and plays nicely with MQTT. If you already have a Google Nest or Amazon Echo, you can still integrate the switch via Home Assistant’s cloud integration.
Quick script
- Flash the ESP‑32 with the Arduino IDE using the “ESP32 Dev Module” board definition.
- Install the Arduino-ESP32-MQTT library.
- Load this minimal sketch (replace
WIFI_SSID,WIFI_PASS, andMQTT_BROKERwith your own values):
#include <WiFi.h>
#include <PubSubClient.h>
#include "esp32_i2s.h" // hypothetical library for the mic
const char* ssid = "WIFI_SSID";
const char* password = "WIFI_PASS";
const char* mqtt_server = "MQTT_BROKER";
WiFiClient espClient;
PubSubClient client(espClient);
const int relayPin = 12; // GPIO12
void setup() {
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW);
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
client.setServer(mqtt_server, 1883);
initMic(); // start mic sampling
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
if (detectWakeWord()) { // returns true when "Hey Smart Home Lab" heard
client.publish("smarthomelab/light", "toggle");
digitalWrite(relayPin, !digitalRead(relayPin));
}
}
- In Home Assistant, add an MQTT switch:
switch:
- platform: mqtt
name: "Voice Light"
command_topic: "smarthomelab/light"
payload_on: "toggle"
optimistic: true
Now saying “Hey Smart Home Lab” (or any phrase you train the mic for) will publish the MQTT message, flipping the relay and turning the light on or off.
Test and Tweak
Fine‑tune sensitivity
The microphone module can be a bit noisy. If you notice false triggers, edit the detectWakeWord() function to require a higher confidence score, or add a short debounce (ignore triggers for 2‑3 seconds after a successful command).
Placement matters
Mount the project box near the ceiling or on the wall where your voice is most likely to be heard. Avoid placing it directly behind a heavy piece of furniture – the mic will struggle.
Energy Savings in Real Life
You might think a single switch won’t make a dent in your bill, but the numbers add up. A typical LED bulb draws about 10 W. Leaving it on for 4 extra hours a day costs roughly 1.2 kWh per month, or about $0.15 at the national average rate. Multiply that by a few rooms and you’re looking at $2‑$3 saved each month, completely offset by the $25 you spent on the project.
Beyond dollars, you get the convenience of never hunting for a switch in the dark, and the satisfaction of knowing you built it yourself. That’s the Smart Home Lab philosophy in a nutshell: small, affordable upgrades that make life easier and greener.
Wrap‑Up
Building a voice‑activated light switch doesn’t have to be a pricey, high‑tech nightmare. With a $5 Wi‑Fi relay, a $8 ESP‑32 mic board, and a few minutes of wiring, you have a functional, internet‑connected switch that responds to your voice. The project is a great introduction to MQTT, Home Assistant, and basic IoT hardware, and the energy savings are a nice bonus.
Give it a try, share your results on the Smart Home Lab community, and keep experimenting. The next step could be adding dimming control, integrating with motion sensors, or expanding to a whole room of voice‑controlled fixtures. The sky’s the limit, and the budget is still friendly.
Happy hacking!
- →
- →
- →
- →
- →