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

A person holding a smartphone displaying the Google Home app interface, which shows a "Desk LED" is turned on. In the background, a bright LED bulb is illuminated on a wooden desk next to a laptop, a professional microphone, and a green cutting mat.

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

 
 
ComponentWhat It Does
ESP32Connects to Wi-Fi, listens for commands
Relay ModuleSafely switches the AC light on/off
Sinric ProBridges ESP32 and Google Assistant
Google AssistantYour voice command center

The flow:
*You speak → Google Assistant → Sinric Pro cloud → ESP32 → Relay → Light turns on/off*

A clean, minimalist block diagram showing the flow of a smart home system. From left to right: a Smartphone (Google Assistant) sends a "Voice command" to the Sinric Pro Cloud, which triggers an ESP32 microcontroller. The ESP32 controls a Relay module, which finally toggles a Light Bulb labeled "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 wiringWork on live circuits
Insulate all exposed wiresLeave bare copper showing
Double-check connections before powering onRush through the AC wiring
Use a plastic enclosure for the relayTouch 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)

 
 
ComponentSpecs / NotesApprox Price (BDT)
ESP32 Development BoardAny version works (I used Type-C)600-800
Relay Module1-channel, 5V (can use 2/4/8 channel)50-100
Female-to-Female Jumper WiresAt least 330-50
USB CableData-capable, for programming100-200

Electrical (High Voltage Side)

 
 
ComponentNotes
LED Bulb + HolderStandard household bulb
AC Power Plug2-pin or 3-pin, with wire
Electrical WireFor connecting plug to bulb
Wire Strippers / ScrewdriverFor relay terminals
Soldering IronOptional, for secure connections
Close-up of components for a DIY electronics project on a green cutting mat, including a white LED light bulb on a socket base, a blue 4-channel relay module, and a black ESP32 microcontroller development board. The word "Components" is visible in the top-right.
 
 
ComponentWhere to Find
ESP32 Development BoardAliExpress / Amazon
1-Channel Relay ModuleAliExpress
Jumper Wires (F-F)AliExpress
LED Bulb HolderAliExpress

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 PinRelay Module PinWire Color (Optional)
VIN (5V input)VCCRed
GNDGNDBlack
GPIO 26 (D26)IN1Yellow

*(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

 
 
TerminalMeaning
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:

  1. Tools → Manage Libraries

  2. Search and install:

    • Sinric Pro (by sinric.pro)

    • ArduinoJson (dependency, may install automatically)

Complete ESP32 Code

➕➕
filename.cpp
// 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 !state to state in the onPowerState function.

(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:

🌐
filename.html
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)

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

 
 
ProblemLikely CauseFix
ESP32 not connecting to Wi-FiWrong SSID/password, or 5GHz networkCheck credentials; ESP32 needs 2.4GHz
Sinric Pro shows offlineNetwork issue, or credentials wrongRecheck App Key/Secret in code
Relay clicks but light doesn’t turn onAC wiring issueCheck COM and NO connections; ensure bulb works
Light is always onRelay logic invertedIn code, change !state to state in onPowerState
Google Assistant doesn’t find deviceSinric Pro not linkedRe-link in Google Home app
ESP32 resets when relay triggersPower supply issueESP32 needs stable 5V; try different USB cable/power bank

How This Compares to Commercial Smart Bulbs

 
 
FeatureDIY ESP32 ProjectCommercial 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
ReliabilityGood (depends on network)Excellent
AestheticsVisible ESP32/relayInvisible (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:

 
 
UpgradeWhat You’ll Need
Control multiple lights2/4/8-channel relay module; modify code
Add manual switchToggle switch wired in parallel with relay
Voice + phone controlUse Sinric Pro dashboard on phone
Add sensor (light/motion)PIR sensor, LDR – trigger lights automatically
Make it portable18650 battery + TP4056 charger
Add enclosure3D 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!

Subscribe to The Newsletter

Join robotics enthusiasts getting weekly project ideas:

• 🔧 Under $50 projects

• ⚙️ Under $100 projects

• 🎥 New video tutorials

• 📝 Blog updates

We don’t spam! Read our privacy policy for more info.

Leave a Reply

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