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:
- The user speaks a voice command (e.g., โTurn on the lightโ).
- The command is processed by Google Assistant or Alexa.
- The request is sent to the IoT cloud platform (like IFTTT or SinricPro).
- The NodeMCU (ESP8266) receives the command via Wi-Fi.
- The corresponding relay connected to the device is triggered ON/OFF.
- 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:
| Component | Quantity | Description |
|---|---|---|
| NodeMCU ESP8266 | 1 | The main Wi-Fi microcontroller board that connects to the internet and processes commands. |
| 4-Channel Relay Module | 1 | Used to switch ON/OFF appliances like lights, fans, etc. |
| Jumper Wires (Male to Female) | As required | For making all the necessary connections between NodeMCU and relay. |
| Breadboard | 1 | To easily prototype and test the circuit before soldering. |
| Power Supply (5V / USB) | 1 | Used to power NodeMCU and relay board. |
| Electrical Bulb / Fan / LED | 2โ4 | Load devices to be controlled. |
| Smartphone (Android/iOS) | 1 | To set up Google Home / Alexa apps. |
| Wi-Fi Network | 1 | Required 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 Pin | Relay Module Pin | Function |
|---|---|---|
| D1 (GPIO5) | IN1 | Controls Device 1 (Light) |
| D2 (GPIO4) | IN2 | Controls Device 2 (Fan) |
| D3 (GPIO0) | IN3 | Controls Device 3 |
| D4 (GPIO2) | IN4 | Controls Device 4 |
| VIN (5V) | VCC | Power to Relay Board |
| GND | GND | Common 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
- When the NodeMCU connects to Wi-Fi, it registers itself with the cloud server (SinricPro or IFTTT).
- When you give a voice command such as โAlexa, turn on the fanโ, the cloud platform sends a digital signal to the NodeMCU.
- The corresponding GPIO pin goes HIGH, activating the relay module, and the connected appliance turns ON.
- Similarly, when you say โTurn off the fanโ, the signal goes LOW, and the relay deactivates.
- 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.hWebSocketsClient.hArduinoJson.hSinricPro.hSinricProSwitch.h
To install libraries:
Go to โ Sketch โ Include Library โ Manage Libraries โ Search and Install.
๐น Step 2: Setup SinricPro Account
- Visit ๐ https://sinric.pro
- Create a free account and log in.
- Click โAdd Deviceโ โ Select โSwitchโ.
- Name your device (for example: Light 1 or Fan 1).
- Copy the Device ID for each device you create.
- 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
- Connect your NodeMCU to your PC via USB.
- Select the board: Tools โ Board โ NodeMCU 1.0 (ESP-12E Module)
- Choose the correct Port.
- Click on Upload.
- 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
| Sensor | Function | Example Use |
|---|---|---|
| DHT11 / DHT22 | Temperature & Humidity | Auto control fan or AC |
| LDR Sensor | Light Intensity | Turn ON lights at night |
| PIR Sensor | Motion Detection | Turn ON lights when movement is detected |
| Gas Sensor (MQ-2) | Gas Leakage Detection | Trigger buzzer & send alert |
| Relay with ACS712 | Power Monitoring | Measure energy usage |
โก 4. Safety and Circuit Protection
When working with AC appliances, safety is crucial.
Here are some important precautions:
- Use proper relay modules rated for 250V/10A or more.
- Always connect relays with a flyback diode if using bare modules.
- Use optocoupler-based relays for electrical isolation.
- Enclose the project in a plastic box to prevent electric shocks.
- 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:
- Power on NodeMCU and wait for WiFi connection.
- Say:
- โAlexa, turn on the room light.โ
- โHey Google, turn off the fan.โ
- Check the SinricPro dashboard โ it should show real-time updates.
- If sensors are added, verify that they trigger correctly.
- 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:
| Feature | Description |
|---|---|
| ESP32 Upgrade | Use ESP32 instead of NodeMCU for Bluetooth + Dual-core performance |
| Home Energy Meter | Add current sensors to monitor energy consumption |
| IFTTT Automation | Create custom triggers using webhooks and events |
| OLED Display | Show device status and temperature locally |
| Mobile App Integration | Build your own app using Flutter or MIT App Inventor |
| Security Lock System | Add 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
| Platform | Link | Purpose |
|---|---|---|
| Telegram Channel | t.me/YaranaIoTGuru | Project files, PDFs, updates |
| Telegram Group | t.me/YaranaIoTCommunity | Peer support, doubts |
| Discord Server | discord.gg/yarana-iot | Live voice help, coding rooms |
| WhatsApp Community | Join Here | Announcements & 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