Voice-Controlled Home Automation: Control Your Lights with ESP32 and Google AssistantVoice-Controlled Home Automation: Control Your Lights with ESP32 and Google Assistant

The “Wait, Did I Just Say That?” Moment
I still remember the first time I said:
“Hey Google, turn on the desk LED.”
And the light actually turned on.
I sat there for a second, staring at the bulb, half expecting it to be a coincidence. It wasn’t. My ESP32 had heard me. Google Assistant had processed my voice. And together, they made a 220V light bulb obey.
That feeling? It never gets old.
At Roborear, we talk a lot about robotics—soccer bots, ESP32-CAM security systems, soldering tutorials. But there’s something special about home automation. You build it once, and suddenly your room feels like the future.
This project is my step-by-step guide to building your own voice-controlled smart light using an ESP32, a relay module, and Google Assistant. No expensive smart bulbs. No cloud subscriptions. Just pure DIY satisfaction.
What You’ll Build
| Component | What It Does |
|---|---|
| ESP32 | Connects to Wi-Fi, listens for commands |
| Relay Module | Safely switches the AC light on/off |
| Sinric Pro | Bridges ESP32 and Google Assistant |
| Google Assistant | Your voice command center |
The flow:
*You speak → Google Assistant → Sinric Pro cloud → ESP32 → Relay → Light turns on/off*

Before We Start: A Note on Safety ⚠️
This project involves 220V AC power. That’s the same as your wall outlets. It can hurt you. It can start a fire. Respect it.
| ✅ DO | ❌ DON’T |
|---|---|
| Unplug everything while wiring | Work on live circuits |
| Insulate all exposed wires | Leave bare copper showing |
| Double-check connections before powering on | Rush through the AC wiring |
| Use a plastic enclosure for the relay | Touch the relay terminals while powered |
I’m a BUET mechanical engineering student—not an electrician. But I’ve learned to respect high voltage. If you’re unsure, ask someone with experience. Safety first, then cool projects.
What You’ll Need (Parts List)
Electronics (Low Voltage Side)
| Component | Specs / Notes | Approx Price (BDT) |
|---|---|---|
| ESP32 Development Board | Any version works (I used Type-C) | 600-800 |
| Relay Module | 1-channel, 5V (can use 2/4/8 channel) | 50-100 |
| Female-to-Female Jumper Wires | At least 3 | 30-50 |
| USB Cable | Data-capable, for programming | 100-200 |
Electrical (High Voltage Side)
| Component | Notes |
|---|---|
| LED Bulb + Holder | Standard household bulb |
| AC Power Plug | 2-pin or 3-pin, with wire |
| Electrical Wire | For connecting plug to bulb |
| Wire Strippers / Screwdriver | For relay terminals |
| Soldering Iron | Optional, for secure connections |

Quick Buy Links (Affiliate)
| Component | Where to Find |
|---|---|
| ESP32 Development Board | AliExpress / Amazon |
| 1-Channel Relay Module | AliExpress |
| Jumper Wires (F-F) | AliExpress |
| LED Bulb Holder | AliExpress |
Step 1: Understanding the Hardware – ESP32 to Relay
The relay is the bridge between low-voltage logic and high-voltage power.
Why a Relay?
ESP32 works at 3.3V, 40mA max per pin
AC light needs 220V, hundreds of milliamps
Relay isolates them. Safe and reliable.
Connections (Low Voltage Side)
| ESP32 Pin | Relay Module Pin | Wire Color (Optional) |
|---|---|---|
| VIN (5V input) | VCC | Red |
| GND | GND | Black |
| GPIO 26 (D26) | IN1 | Yellow |
*(Photo: ESP32 and relay connected with jumper wires – clear, well-lit shot)*
Why GPIO 26? Any digital pin works. I chose 26 because it’s away from default SPI/UART pins. You can use 13, 14, 27, etc.
Step 2: High-Voltage Wiring (Read This Twice)
⚠️ UNPLUG EVERYTHING BEFORE WIRING. ⚠️
Relay Terminal Basics
| Terminal | Meaning |
|---|---|
| COM (Common) | Input from AC source |
| NO (Normally Open) | Output to light – circuit OPEN when relay off |
| NC (Normally Closed) | Output – circuit CLOSED when relay off (we won’t use this) |
When the ESP32 sends a HIGH signal to the relay, COM and NO connect → light turns on.
Wiring Step-by-Step
1. Prepare the AC Plug and Bulb Holder
Inside the wire, you’ll find two conductors. Usually:
Brown or Red = Phase (Live)
Blue or Black = Neutral
(Photo: Stripped wire showing phase and neutral)
2. Connect the Neutral Wire
Take the neutral wire from the AC plug. Connect it directly to the neutral wire of the bulb holder. Solder and insulate.
3. Connect the Phase Wire to Relay
Take the phase wire from the AC plug. Connect it to the COM terminal of the relay. Screw it tight.
4. Connect Relay to Bulb
Take another wire from the NO terminal of the relay. Connect it to the phase wire of the bulb holder.
5. Final Check
AC plug → Neutral → Bulb
AC plug → Phase → Relay COM
Relay NO → Bulb Phase
When relay clicks, COM connects to NO → circuit completes → light turns on.
(Photo: Relay with COM and NO clearly marked, wires connected)
(Diagram: Simple schematic showing AC plug → relay → bulb wiring)
Step 3: Setting Up Sinric Pro (The Cloud Bridge)
Sinric Pro is a free service that connects Google Assistant to your ESP32. It handles all the authentication and command routing.
Account Setup
1. Go to sinric.pro and create an account (free tier is plenty).
2. On the dashboard, click “Add Device”.
3. Fill in:
Device Name:
Desk LED(or whatever you want to call it)Device Type:
Switch
4. Save the device. You’ll get a Device ID.
5. Go to Credentials section. Copy your:
App Key
App Secret
Keep these three items safe. You’ll paste them into the code.
(Photo: Sinric Pro dashboard with Device ID, App Key, and Secret visible – blur sensitive info)
Step 3: Setting Up Sinric Pro (The Cloud Bridge)
Sinric Pro is a free service that connects Google Assistant to your ESP32. It handles all the authentication and command routing.
Account Setup
1. Go to sinric.pro and create an account (free tier is plenty).
2. On the dashboard, click “Add Device”.
3. Fill in:
Device Name:
Desk LED(or whatever you want to call it)Device Type:
Switch
4. Save the device. You’ll get a Device ID.
5. Go to Credentials section. Copy your:
App Key
App Secret
Keep these three items safe. You’ll paste them into the code.
(Photo: Sinric Pro dashboard with Device ID, App Key, and Secret visible – blur sensitive info)
Step 4: The Code (Arduino IDE)
Install Required Libraries
In Arduino IDE:
Tools → Manage Libraries
Search and install:
Sinric Pro (by sinric.pro)
ArduinoJson (dependency, may install automatically)
Complete ESP32 Code
// Voice-Controlled Light with ESP32 + Google Assistant
// Roborear – Shahrear Abedin Bhuiyan
#include <WiFi.h>
#include <SinricPro.h>
#include <SinricProSwitch.h>
// ---------- WiFi Credentials ----------
#define WIFI_SSID "Your_SSID" // Your home Wi-Fi name
#define WIFI_PASS "Your_Password" // Your Wi-Fi password
// ---------- Sinric Pro Credentials ----------
#define APP_KEY "your-app-key-here" // From Sinric Pro dashboard
#define APP_SECRET "your-app-secret-here" // From Sinric Pro dashboard
#define DEVICE_ID "your-device-id-here" // Your device ID
// ---------- Relay Pin ----------
#define RELAY_PIN 26
// ---------- LED State ----------
bool ledState = false;
// ---------- Power State Handler ----------
bool onPowerState(String deviceId, bool state) {
Serial.printf("Device: %s turned %s\r\n", deviceId.c_str(), state ? "ON" : "OFF");
ledState = state;
digitalWrite(RELAY_PIN, !state); // Note: HIGH = relay OFF (depending on your module)
return true;
}
// ---------- WiFi Event Handler ----------
void setupWiFi() {
WiFi.begin(WIFI_SSID, WIFI_PASS);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWi-Fi connected");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
}
// ---------- Sinric Pro Setup ----------
void setupSinricPro() {
SinricProSwitch &mySwitch = SinricPro[DEVICE_ID];
mySwitch.onPowerState(onPowerState);
SinricPro.begin(APP_KEY, APP_SECRET);
Serial.println("Sinric Pro connected");
}
// ---------- Setup ----------
void setup() {
Serial.begin(115200);
// Relay pin as output
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, HIGH); // Start with relay OFF
setupWiFi();
setupSinricPro();
}
// ---------- Loop ----------
void loop() {
SinricPro.handle();
}
⚠️ IMPORTANT: Different relay modules have different logic. Some turn ON with HIGH, others ON with LOW. Test yours:
If the relay clicks and light turns on when you upload the code, you’re fine.
If the light turns on immediately or never responds, change
!statetostatein theonPowerStatefunction.
(Photo: Arduino IDE with code open, showing Wi-Fi and Sinric Pro credentials)
Step 5: Upload and Test
1. Connect ESP32 to your computer via USB.
2. In Arduino IDE:
Tools → Board → ESP32 Dev Module
Tools → Port → (your COM port)
3. Click Upload (right arrow).
4. Open Serial Monitor (Tools → Serial Monitor, baud 115200). You should see:
Connecting to Wi-Fi....
Wi-Fi connected
IP Address: 192.168.x.x
Sinric Pro connected
If you see “Heartbeat” messages, the ESP32 is talking to the cloud. Good.
(Photo: Serial Monitor showing successful connection)
Step 6: Link Sinric Pro to Google Home
1. Open Google Home app on your phone.
2. Tap Devices → Add → Set up device.
3. Choose “Works with Google” (or “Have something already set up?”).
4. Search for “Sinric Pro” and log in with your Sinric credentials.
5. Authorize the connection. Your “Desk LED” should appear.
6. Assign it to a room (Living Room, Bedroom, etc.).
(Photo: Google Home app showing linked Sinric Pro and the Desk LED device)
Step 7: The Moment of Truth
Everything is plugged in. ESP32 powered. Bulb in the socket. Your phone ready.
Take a breath. Then:
“Hey Google, turn on the desk LED.”
Google Assistant chimes. And the light comes on.
“Hey Google, turn off the desk LED.”
And it goes off.
If it works: Congratulations. You just built a voice-controlled smart light from scratch.
If it doesn’t: Don’t panic. Check the troubleshooting section below.
*(Video clip: Your hand, Google Assistant voice, light turning on/off – 15 seconds)*
Troubleshooting
| Problem | Likely Cause | Fix |
|---|---|---|
| ESP32 not connecting to Wi-Fi | Wrong SSID/password, or 5GHz network | Check credentials; ESP32 needs 2.4GHz |
| Sinric Pro shows offline | Network issue, or credentials wrong | Recheck App Key/Secret in code |
| Relay clicks but light doesn’t turn on | AC wiring issue | Check COM and NO connections; ensure bulb works |
| Light is always on | Relay logic inverted | In code, change !state to state in onPowerState |
| Google Assistant doesn’t find device | Sinric Pro not linked | Re-link in Google Home app |
| ESP32 resets when relay triggers | Power supply issue | ESP32 needs stable 5V; try different USB cable/power bank |
How This Compares to Commercial Smart Bulbs
| Feature | DIY ESP32 Project | Commercial Smart Bulb |
|---|---|---|
| Price | ~800-1000 BDT (one-time) | 1500-3000 BDT per bulb |
| Voice Control | ✅ Yes (Google Assistant) | ✅ Yes |
| Internet Required | ✅ Yes (cloud) | ✅ Yes |
| Works with Existing Bulb | ✅ Yes (any bulb) | ❌ No (replaces bulb) |
| Learning Experience | ✅ Priceless | ❌ None |
| Reliability | Good (depends on network) | Excellent |
| Aesthetics | Visible ESP32/relay | Invisible (bulb only) |
For me, the learning experience alone makes the DIY route worth it. Plus, I can control any light—not just special smart bulbs.
What’s Next? Upgrades to Try
This is a foundation. Here’s how to level up:
| Upgrade | What You’ll Need |
|---|---|
| Control multiple lights | 2/4/8-channel relay module; modify code |
| Add manual switch | Toggle switch wired in parallel with relay |
| Voice + phone control | Use Sinric Pro dashboard on phone |
| Add sensor (light/motion) | PIR sensor, LDR – trigger lights automatically |
| Make it portable | 18650 battery + TP4056 charger |
| Add enclosure | 3D print a case for ESP32 + relay |
I’m planning to add a PIR motion sensor to my desk light. “Hey Google, turn on when I walk in” – one step closer to fully automated.
Affiliate Disclosure
Some links in this post are affiliate links. If you purchase through them, I may earn a small commission at no extra cost to you. This helps support Roborear. Thanks!
