Smart Home Automation with Google Assistant

Smart Home Automation with Google Assistant & Alexa using NodeMCU

IoT Projects Home Automation ESP8266 / NodeMCU Voice Controlled Systems Smart Home Technology

Welcome to another exciting IoT project from YaranaIoT Guru โ€” a complete Smart Home Automation System built using NodeMCU (ESP8266), Google Assistant, and Amazon Alexa.

This project allows you to control your home appliances using voice commands, such as turning on lights, fans, and other electronic devices from anywhere in the world ๐ŸŒ โ€” using just your voice or smartphone.

Whether you say โ€œHey Google, turn on the living room lightโ€ or โ€œAlexa, switch off the fanโ€, your NodeMCU will receive the command and activate or deactivate the relay connected to that appliance.

This project demonstrates real-time IoT communication, cloud integration, and voice-controlled automation โ€” all on a simple, low-cost hardware setup.


๐Ÿ”น Why Build This Project?

Home automation is one of the most trending applications of the Internet of Things (IoT). With platforms like Google Assistant and Alexa, itโ€™s now easier than ever to integrate voice control with microcontrollers like NodeMCU.

This project will teach you how to:

  • Interface NodeMCU (ESP8266) with Google Assistant and Alexa
  • Control home appliances using voice commands
  • Connect relays and sensors for automation
  • Use IFTTT, MQTT, or Sinric Pro for cloud communication
  • Build a low-cost home automation system with real-time control

๐Ÿ”น How It Works

Hereโ€™s the basic flow of communication:

  1. The user speaks a voice command (e.g., โ€œTurn on the lightโ€).
  2. The command is processed by Google Assistant or Alexa.
  3. The request is sent to the IoT cloud platform (like IFTTT or SinricPro).
  4. The NodeMCU (ESP8266) receives the command via Wi-Fi.
  5. The corresponding relay connected to the device is triggered ON/OFF.
  6. You can also monitor the state of each device through the app or dashboard.

This simple communication loop brings voice automation to life!


๐Ÿ”น Features

โœ… Works with Google Assistant and Alexa
โœ… Control devices from anywhere using Wi-Fi
โœ… Real-time voice and mobile app control
โœ… Compatible with NodeMCU (ESP8266) or ESP32
โœ… Supports multiple devices (lights, fans, etc.)
โœ… Low-cost and easy to assemble
โœ… Scalable for large home systems


๐Ÿ”น Applications

  • Smart home lighting control
  • IoT-enabled fans and appliances
  • Office or lab automation
  • Voice-controlled classroom systems
  • IoT workshops and student projects

๐Ÿ”น Tools and Platforms Used

  • Hardware: NodeMCU ESP8266, 4-channel relay module, jumper wires, breadboard
  • Software: Arduino IDE, Google Home app, Alexa app, IFTTT / Sinric Pro
  • Programming Language: C/C++ (Arduino)
  • Cloud Services: SinricPro (for Alexa & Google), or IFTTT Webhooks

๐Ÿ”น Components Required

Hereโ€™s a detailed list of all the components used in this project:

ComponentQuantityDescription
NodeMCU ESP82661The main Wi-Fi microcontroller board that connects to the internet and processes commands.
4-Channel Relay Module1Used to switch ON/OFF appliances like lights, fans, etc.
Jumper Wires (Male to Female)As requiredFor making all the necessary connections between NodeMCU and relay.
Breadboard1To easily prototype and test the circuit before soldering.
Power Supply (5V / USB)1Used to power NodeMCU and relay board.
Electrical Bulb / Fan / LED2โ€“4Load devices to be controlled.
Smartphone (Android/iOS)1To set up Google Home / Alexa apps.
Wi-Fi Network1Required for cloud connectivity (2.4GHz preferred).

๐Ÿ”น Circuit Diagram Explanation

The NodeMCU ESP8266 works as the brain of our home automation system. It connects to your Wi-Fi and receives ON/OFF commands from Google Assistant or Alexa through the cloud platform (like SinricPro or IFTTT).

Each relay module acts as an electronic switch, allowing the NodeMCU to control AC appliances safely.

Hereโ€™s how the connections are typically made:

NodeMCU PinRelay Module PinFunction
D1 (GPIO5)IN1Controls Device 1 (Light)
D2 (GPIO4)IN2Controls Device 2 (Fan)
D3 (GPIO0)IN3Controls Device 3
D4 (GPIO2)IN4Controls Device 4
VIN (5V)VCCPower to Relay Board
GNDGNDCommon Ground

๐Ÿ”น Connection Notes

  • The relay module requires a 5V supply, which can be taken from NodeMCUโ€™s VIN pin if powered via USB.
  • Each relay output terminal connects to one AC device (e.g., light or fan).
  • Use proper insulation and safety precautions when working with AC appliances.
  • You can also use a 2-channel or 8-channel relay depending on how many devices you want to control.

๐Ÿ”น How the Circuit Works

  1. When the NodeMCU connects to Wi-Fi, it registers itself with the cloud server (SinricPro or IFTTT).
  2. When you give a voice command such as โ€œAlexa, turn on the fanโ€, the cloud platform sends a digital signal to the NodeMCU.
  3. The corresponding GPIO pin goes HIGH, activating the relay module, and the connected appliance turns ON.
  4. Similarly, when you say โ€œTurn off the fanโ€, the signal goes LOW, and the relay deactivates.
  5. All this happens within seconds โ€” completely wirelessly! โšก

๐Ÿ”น Power Supply Considerations

  • NodeMCU runs on 3.3V logic, but its VIN pin accepts 5V (from USB or adapter).
  • The relay board works at 5V, so itโ€™s powered directly from NodeMCUโ€™s VIN.
  • Always use a separate power supply for larger setups to prevent voltage drops.

๐Ÿ”น Safety Tips

โš ๏ธ Caution:

  • When connecting AC appliances, make sure the power is OFF.
  • Use proper wire insulation and keep circuits away from water and heat.
  • For long-term use, mount the setup in a plastic enclosure to prevent shock hazards.

๐Ÿ”น Final Hardware Setup

After connecting all components:

  • Place your NodeMCU on a breadboard.
  • Connect the relay module inputs to D1โ€“D4.
  • Connect VIN and GND for power.
  • Plug your relay outputs to AC devices (like a bulb or fan).
  • Power up the NodeMCU โ€” the onboard blue LED should light up once connected to Wi-Fi.

At this stage, your hardware setup is complete โœ…

๐Ÿ”น Step 1: Install the Required Tools

Before writing the code, make sure you have these ready:

โœ… Software Required

  • Arduino IDE (latest version)
  • ESP8266 Board Package (installed via Board Manager)
  • Libraries:
    • ESP8266WiFi.h
    • WebSocketsClient.h
    • ArduinoJson.h
    • SinricPro.h
    • SinricProSwitch.h

To install libraries:
Go to โ†’ Sketch โ†’ Include Library โ†’ Manage Libraries โ†’ Search and Install.


๐Ÿ”น Step 2: Setup SinricPro Account

  1. Visit ๐Ÿ‘‰ https://sinric.pro
  2. Create a free account and log in.
  3. Click โ€œAdd Deviceโ€ โ†’ Select โ€œSwitchโ€.
  4. Name your device (for example: Light 1 or Fan 1).
  5. Copy the Device ID for each device you create.
  6. Go to the API Key section โ€” copy your App Key and App Secret.

Youโ€™ll use these credentials in your Arduino code.


๐Ÿ”น Step 3: Connect SinricPro to Alexa and Google Assistant

  • For Alexa:
    • Open the Alexa app โ†’ Go to โ€œSkills & Games.โ€
    • Search for SinricPro โ†’ Enable it โ†’ Log in using your SinricPro account.
    • Alexa will automatically detect all added devices (e.g., โ€œLight 1,โ€ โ€œFan 1โ€).
  • For Google Assistant:
    • Open Google Home โ†’ Add โ†’ โ€œWorks with Google.โ€
    • Search SinricPro โ†’ Link account โ†’ Grant permissions.
    • Google will sync all your devices to your home.

๐Ÿ”น Step 4: Arduino Code

Hereโ€™s a working example code for a 4-device control setup using NodeMCU and SinricPro:

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WebSocketsClient.h>
#include <ArduinoJson.h>
#include <SinricPro.h>
#include <SinricProSwitch.h>

#define WIFI_SSID         "YourWiFiName"
#define WIFI_PASS         "YourWiFiPassword"
#define APP_KEY           "Your_SinricPro_App_Key"
#define APP_SECRET        "Your_SinricPro_App_Secret"

#define SWITCH_ID_1       "Device_ID_1"
#define SWITCH_ID_2       "Device_ID_2"
#define SWITCH_ID_3       "Device_ID_3"
#define SWITCH_ID_4       "Device_ID_4"

#define RELAY_1 5   // D1
#define RELAY_2 4   // D2
#define RELAY_3 0   // D3
#define RELAY_4 2   // D4

void setupWiFi() {
  Serial.print("Connecting to WiFi...");
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println(" Connected!");
}

bool onPowerState(const String &deviceId, bool &state) {
  if (deviceId == SWITCH_ID_1) digitalWrite(RELAY_1, state);
  if (deviceId == SWITCH_ID_2) digitalWrite(RELAY_2, state);
  if (deviceId == SWITCH_ID_3) digitalWrite(RELAY_3, state);
  if (deviceId == SWITCH_ID_4) digitalWrite(RELAY_4, state);
  return true;
}

void setup() {
  Serial.begin(115200);
  for (int i = 0; i < 4; i++) pinMode(i + RELAY_1, OUTPUT);
  setupWiFi();
  
  SinricProSwitch &mySwitch1 = SinricPro[SWITCH_ID_1];
  SinricProSwitch &mySwitch2 = SinricPro[SWITCH_ID_2];
  SinricProSwitch &mySwitch3 = SinricPro[SWITCH_ID_3];
  SinricProSwitch &mySwitch4 = SinricPro[SWITCH_ID_4];
  
  mySwitch1.onPowerState(onPowerState);
  mySwitch2.onPowerState(onPowerState);
  mySwitch3.onPowerState(onPowerState);
  mySwitch4.onPowerState(onPowerState);

  SinricPro.begin(APP_KEY, APP_SECRET);
  SinricPro.restoreDeviceStates(true);
}

void loop() {
  SinricPro.handle();
}

๐Ÿ”น Step 5: Upload the Code

  1. Connect your NodeMCU to your PC via USB.
  2. Select the board: Tools โ†’ Board โ†’ NodeMCU 1.0 (ESP-12E Module)
  3. Choose the correct Port.
  4. Click on Upload.
  5. Open Serial Monitor (baud rate 115200) โ€” you should see โ€œConnected to WiFiโ€ and โ€œConnected to SinricPro Server.โ€

๐Ÿ”น Step 6: Testing the Setup

Now open the Alexa or Google Assistant app and say:

โ€œAlexa, turn on Light 1.โ€
โ€œHey Google, turn off Fan 1.โ€

Within seconds, the respective relay should switch ON or OFF โ€” giving you full voice control over your appliances ๐ŸŽคโšก

๐Ÿงญ 1. Creating a Smart Home Dashboard

Even though your devices can be controlled through voice commands, itโ€™s often convenient to have a web-based or mobile dashboard where you can monitor the live status of your devices.

You can use any of these platforms:

๐Ÿ”น (a) SinricPro Dashboard

  • Log in to your SinricPro account.
  • Youโ€™ll find all the devices listed under your account.
  • You can manually turn them ON/OFF from the dashboard itself โ€” no coding required.
  • It also updates the device status in real-time, synced with Alexa or Google Assistant.

๐Ÿ”น (b) Blynk IoT Dashboard (Optional Upgrade)

If you want to design a custom Android/iOS dashboard, Blynk is a great option.
You can connect NodeMCU with Blynk and create buttons, sliders, and gauges to control lights, fans, and even display temperature or humidity data.

Example add-on:

  • Add a DHT11 Sensor to monitor room temperature and humidity.
  • Display that data on the Blynk mobile dashboard.
  • Control lights and fans from the same interface.

๐Ÿง  2. Creating Custom Voice Routines

To make your home automation smarter, you can set up routines in Alexa or Google Home:

๐Ÿ”น Alexa Example:

  • โ€œAlexa, Iโ€™m homeโ€ โ†’ Turns ON all lights + Fan.
  • โ€œAlexa, good nightโ€ โ†’ Turns OFF all devices + activates Night Lamp.

๐Ÿ”น Google Home Example:

  • โ€œHey Google, Movie Timeโ€ โ†’ Turns OFF room lights + Turns ON LED strip.
  • โ€œHey Google, Study Modeโ€ โ†’ Turns ON table light + Fan.

These routines can be configured directly in the Alexa or Google Home apps, no extra coding required.


๐Ÿ’ก 3. Adding Sensors for Full Automation

Voice commands are great, but automation becomes more powerful when devices respond automatically to environmental conditions.
You can integrate additional sensors with NodeMCU to achieve that.

โœ… Common Add-ons

SensorFunctionExample Use
DHT11 / DHT22Temperature & HumidityAuto control fan or AC
LDR SensorLight IntensityTurn ON lights at night
PIR SensorMotion DetectionTurn ON lights when movement is detected
Gas Sensor (MQ-2)Gas Leakage DetectionTrigger buzzer & send alert
Relay with ACS712Power MonitoringMeasure energy usage

โšก 4. Safety and Circuit Protection

When working with AC appliances, safety is crucial.
Here are some important precautions:

  1. Use proper relay modules rated for 250V/10A or more.
  2. Always connect relays with a flyback diode if using bare modules.
  3. Use optocoupler-based relays for electrical isolation.
  4. Enclose the project in a plastic box to prevent electric shocks.
  5. Avoid powering NodeMCU directly from AC; use a regulated 5V power supply or phone charger.

๐Ÿ›œ 5. Enhancing WiFi Reliability

Smart home systems depend heavily on internet connectivity.
To ensure smooth operation:

  • Place the NodeMCU close to your WiFi router.
  • Use a static IP for your NodeMCU to avoid reconnection issues.
  • Add reconnect logic in your code:
if (WiFi.status() != WL_CONNECTED) {
  WiFi.begin(WIFI_SSID, WIFI_PASS);
}

This ensures your system reconnects automatically if the WiFi signal drops.


๐Ÿงฉ 6. Adding Local Control with Switches

You can make your smart home hybrid โ€” controllable both manually and via voice.

To do this:

  • Add push buttons or wall switches connected to NodeMCU input pins.
  • Update your code to toggle relays when the button is pressed.
  • This way, even if the internet is down, you can still control your appliances locally.

Example snippet:

#define SWITCH_PIN 12

void loop() {
  if (digitalRead(SWITCH_PIN) == LOW) {
    digitalWrite(RELAY_1, !digitalRead(RELAY_1)); // Toggle state
    delay(300);
  }
  SinricPro.handle();
}

๐Ÿ“Š 7. Integrating with Google Sheets or MQTT (Advanced)

For advanced IoT users, you can:

  • Use MQTT protocol (via platforms like HiveMQ or Mosquitto) to send data between multiple devices.
  • Log events (ON/OFF times, temperature data, etc.) to Google Sheets using Google Apps Script.

This turns your smart home into a data-driven system โ€” perfect for analysis or automation research.


๐Ÿš€ 8. Testing & Final Demonstration

After setup, test all functions step-by-step:

  1. Power on NodeMCU and wait for WiFi connection.
  2. Say:
    • โ€œAlexa, turn on the room light.โ€
    • โ€œHey Google, turn off the fan.โ€
  3. Check the SinricPro dashboard โ€” it should show real-time updates.
  4. If sensors are added, verify that they trigger correctly.
  5. Measure relay response โ€” it should activate within a second of your voice command.

๐ŸŽฅ Watch Full Tutorial on YaranaIoT Guru YouTube Channel
for live demonstration and code walkthrough.


๐Ÿง  9. Future Upgrades

Here are some advanced features you can implement:

FeatureDescription
ESP32 UpgradeUse ESP32 instead of NodeMCU for Bluetooth + Dual-core performance
Home Energy MeterAdd current sensors to monitor energy consumption
IFTTT AutomationCreate custom triggers using webhooks and events
OLED DisplayShow device status and temperature locally
Mobile App IntegrationBuild your own app using Flutter or MIT App Inventor
Security Lock SystemAdd RFID or Face Recognition for access control

๐Ÿ”š 10. Conclusion

With this Smart Home Automation using NodeMCU, youโ€™ve successfully built a modern IoT project that combines voice control, cloud integration, and wireless automation โ€” all in one setup.

This project is:

  • Affordable ๐Ÿ’ฐ
  • Scalable ๐Ÿ”„
  • Beginner-friendly ๐Ÿง 
  • And completely customizable โš™๏ธ

From switching lights to creating full smart home routines, this system lays the foundation for your next-level IoT innovations.

โœจ YaranaIoT Guru proudly presents this project as a hands-on introduction to real-world AIoT (Artificial Intelligence + IoT) systems.


โœ… Key Takeaways

  • NodeMCU enables smart control over WiFi.
  • SinricPro makes Alexa/Google integration easy.
  • Relays allow safe AC switching.
  • You can expand it with sensors, dashboards, and data logging.

๐Ÿ“ž Contact YaranaIoT Guru Empowering IoT Innovation | ESP32 | Home Automation | Smart Solutions | 50K+ Community

Weโ€™d love to hear from you! Whether itโ€™s IoT project queries, collaborations, tech support, custom PCB design, bulk orders, corporate training, college workshops, or freelance development โ€” weโ€™re just one message away.


โœ‰๏ธ Email (Official)

For detailed inquiries, project support, business collaboration, sponsorships, or documentation: ๐Ÿ“ฉ contact@yaranaiotguru.in ๐Ÿ“ง Alternate: support@yaranaiotguru.in โณ Response: Within 24 hours (Monโ€“Sat) ๐Ÿ’ก Best for attachments (code, schematics, logs, etc.)


๐Ÿ“ฑ Phone / WhatsApp (24ร—7 Support)

Instant live help, troubleshooting, project consultation, or order updates: ๐Ÿ“ž +91 70527 22734 ๐Ÿ’ฌ WhatsApp: Chat Now โฐ Call Hours: Monโ€“Sat, 10 AM โ€“ 7 PM IST ๐Ÿš€ Emergency? WhatsApp anytime โ€” reply within 1 hour


๐ŸŒ Official Website

Tutorials, code, PDFs, schematics, blogs, free tools & online store: ๐Ÿ”— www.yaranaiotguru.in ๐Ÿ›’ Shop: yaranaiotguru.in/shop (ESP32 DevKits, Sensors, Relays, Custom PCBs, Project Kits)


โ–ถ๏ธ YouTube Channel

Step-by-step IoT builds, live coding, ESP32, Blynk, Node-RED, MQTT, Home Assistant & more: ๐Ÿ”— Yarana IoT Guru ๐Ÿ“บ 1,200+ Videos | 52K+ Subs | 5.5M+ Views | 4.8โ˜… Rating ๐ŸŽฅ New Video Every Week โ€” ๐Ÿ”” Subscribe & Turn On Notifications


๐Ÿ›  GitHub (100% Open Source)

All codes, Arduino sketches, PlatformIO projects, Node-RED flows, MQTT configs & docs: ๐Ÿ”— github.com/YaranaIotGuru โญ 50+ Repos | 10K+ Stars & Forks

๐Ÿ”ฅ Top Projects:

  • ESP32 WebSocket Real-Time Dashboard
  • Smart Home with Blynk & Alexa
  • IoT Irrigation System with Soil Moisture
  • MQTT + Node-RED + MySQL Logging
  • OLED Weather Station with API

๐Ÿ“ธ Instagram

Daily reels, quick tips, live builds, student showcases & giveaways: ๐Ÿ”— @YaranaIoTGuru ๐Ÿ“ฑ 10K+ Followers | Reels | Stories | Live Sessions


๐Ÿ’ผ LinkedIn (Professional Network)

B2B, IoT consulting, training, hiring & partnerships: ๐Ÿ”— Yarana IoT Guru

๐Ÿค Services Offered:

  • Custom IoT Product Development
  • Embedded Systems Training
  • College Workshops & FDPs
  • PCB Design & Prototyping

๐Ÿฆ Twitter / X

Real-time updates, polls, project launches & community Q&A: ๐Ÿ”— @YaranaIoTGuru ๐Ÿ“ข Follow for instant alerts


๐Ÿ›  Hackster.io (Project Showcases)

In-depth write-ups, circuits, BOM, code & ratings: ๐Ÿ”— hackster.io/yaranaiotguru ๐Ÿ† 50+ Projects | 100K+ Views | Top 5% Creator


๐Ÿ“ Instructables (DIY Guides)

Beginner-friendly step-by-step guides with templates & troubleshooting: ๐Ÿ”— instructables.com/member/YaranaIoTGuru

๐Ÿ›  Featured Guides:

  • Automatic Plant Watering System
  • Voice-Controlled Home Appliances
  • WiFi-enabled Temperature Monitor

๐Ÿ“š Medium Blog

Deep-dive articles, trends, tutorials & career tips in embedded systems: ๐Ÿ”— medium.com/@yaranaiotguru โœ๏ธ 50+ Articles | 15K+ Readers


๐Ÿ›’ Online Store & Kits

Ready-to-use IoT kits, custom PCBs, sensors & merch: ๐Ÿ”— yaranaiotguru.in/shop ๐Ÿ“ฆ Free Shipping in India above โ‚น999 ๐Ÿ’ณ Payment: UPI, Card, Wallet, COD


๐ŸŒŸ Community Platforms

PlatformLinkPurpose
Telegram Channelt.me/YaranaIoTGuruProject files, PDFs, updates
Telegram Groupt.me/YaranaIoTCommunityPeer support, doubts
Discord Serverdiscord.gg/yarana-iotLive voice help, coding rooms
WhatsApp CommunityJoin HereAnnouncements & polls

๐Ÿข Office & Studio Address

Yarana Studio & Software (Yarana IoT Guru HQ) ๐Ÿ“ Near Rookh Baba Mandir, Umariya Badal Urf Gainda, Allahabad (Prayagraj), Uttar Pradesh โ€“ 212507, India โญ Google Rating: 5.0 โ˜… (100+ Reviews)

๐Ÿ•’ Opening Hours: Monโ€“Sat: 10:00 AM โ€“ 5:00 PM Sunday: Closed

๐ŸŒ Associated Website: yaranawebtech.in ๐Ÿ—บ๏ธ View on Google Maps: Search “Yarana Studio & Software” ๐Ÿ“Œ Walk-ins welcome | Appointment recommended for project discussions

Leave a Reply

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