ROBOREAR
← Back to all articles
Projects

Smart Home Automation Project: Control Your Lights with ESP32 and Google Assistant

This Smart Home Automation 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.

ShahrearApril 4, 202610 min read
Smart Home Automation Project: 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 Smart Home Automation 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.

This video is hosted by YouTube. It loads only when you press play, and YouTube may then set cookies. Watch on YouTube

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:

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 "Ligh

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

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.

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.

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.

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

Full code available on GitHub: [Link to your GitHub repository]

// 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.

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.

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.).

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.

This video is hosted by YouTube. It loads only when you press play, and YouTube may then set cookies. Watch on YouTube

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

Frequently Asked Questions

How long do I get support?

Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line

Do I need to renew my license?

Marks and devious Semikoli but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way.

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.

FAQs

Frequently Asked Questions

1. Why won't my ESP32 connect to WiFi? Or why is it constantly rebooting?

This is the most common issue, and it usually comes down to WiFi credentials or power. First, make absolutely sure you have entered your WiFi SSID (name) and password correctly in the code. The ESP32 is case-sensitive. Second, check that you are using a 2.4GHz WiFi network. The ESP32 cannot connect to 5GHz networks. Most modern routers broadcast both, but your phone or computer might be connected to 5GHz. You need to use the 2.4GHz band for initial setup. Third, the ESP32 draws a lot of power when connecting to WiFi. If you are powering it from your computer's USB port, try using a dedicated 5V phone charger (at least 1A). A weak power supply is a very common cause of random reboots, especially during WiFi connection.

2. The relay clicks but my light bulb doesn't turn on. What's wrong?

This means your ESP32 and code are working perfectly, but your AC wiring has an issue. The relay clicking tells you the low-voltage (3.3V) side is working. The problem is on the high-voltage (220V) side. Double-check your AC wiring: The "hot" (phase/live) wire from your wall plug must go to the relay's COM terminal. The wire going to your light bulb must be connected to the relay's NO (Normally Open) terminal. The neutral wire must be connected directly from the wall plug to the light bulb, bypassing the relay. When the relay clicks, it connects the COM and NO terminals, completing the circuit and turning the light on.

3. My ESP32 code uploads, but Google Home can't find the device. How do I fix this?

This is usually an account linking or device synchronization issue. Follow these steps in order: First, after uploading the code, open the Arduino IDE Serial Monitor (set to 115200 baud). You should see the ESP32 connect to WiFi and then a message like "Sinric Pro Connected". If you don't see this message, your device isn't reaching the Sinric Pro cloud server. Second, make sure you have correctly copied the Device ID, App Key, and App Secret from your Sinric Pro dashboard directly into your Arduino code. Even a missing character will prevent linking. Third, in the Google Home app, you need to manually sync your devices. Go to the "Devices" section, pull down from the top to refresh, or say "Hey Google, sync my devices." It can take up to 30 seconds for new devices to appear after linking.

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!

Tags

RoborearESP32 tutorialBUETESP32 beginner projectIoT projectsESP32 home automationGoogle Assistant ESP32voice controlled LEDSinric Pro tutorialsmart home DIYESP32 relay controlGoogle Home ESP32Arduino ESP32smart lightvoice controlESP32 WiFi controlGoogle Assistant smart homeDIY smart bulbcloud controlled LED
← More articlesThanks for reading Roborear.