Smart Home With Google Assistant & Alexa Using NodeMCU ESP8266 - IotCircuitHub
Smart Home With Google Assistant & Alexa Using NodeMCU ESP8266 - IotCircuitHub
In this IoT project, I have explained how to make Smart Home with Google
Assistant and Alexa using NodeMCU ESP8266 and Sinric Pro. With this
NodeMCU ESP8266 project, you can control 3 home appliances with
Google Assistant, Alexa, and manual switches. You can also control the
relays from Google Home and Amazon Alexa App from anywhere in the
world. You can control the relay module from the manual switches if there
is no internet available.
And you don’t need any Google Nest or Amazon Echo Dot devices for
this voice control home automation project.
With this home automation project, you can control & monitor the real-
time feedback of the relays in the Google Home and Alexa App from
anywhere in the world. If the WiFi is available, the NodeMCU will
automatically connect with the Wi-Fi.
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 1/19
8/3/23, 3:18 PM Smart Home with Google Assistant & Alexa using NodeMCU ESP8266 - IotCircuitHub
For this project, I have used all the FREE tools. So if you follow all steps,
you can easily make this Smart Home System with Google Home and
Amazon Alexa to control the appliances with voice commands.
Table of Contents
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 2/19
8/3/23, 3:18 PM Smart Home with Google Assistant & Alexa using NodeMCU ESP8266 - IotCircuitHub
The circuit is very simple, I have used D1, D2, D5 & D6 GPIO to control
the 4-channel relay module.
And the GPIO SD3, D3, D7 & RX are connected with manual switches to
control the relay module manually.
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 3/19
8/3/23, 3:18 PM Smart Home with Google Assistant & Alexa using NodeMCU ESP8266 - IotCircuitHub
As per the source code, when the control pins of the relay module receive
the LOW signal the respective relay will turn on and the relay will turn off
for the HIGH signal in the control pin.
**The Boot will fail if SD3 and D3 are grounded during the Boot
process. So manual switch-S1 and switch-S2 must be OFF during
NodeMCU Boot.
Now, if you want to use pushbuttons then just connect the pushbuttons
across the GPIO pins and GND pin instead of switches.
1. NodeMCU
2. 4-channel 5V SPDT Relay Module
3. Manual Switches or Pushbuttons
4. Amazon Echo Dot (optional)
5. Google Nest Mini (optional)
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 4/19
8/3/23, 3:18 PM Smart Home with Google Assistant & Alexa using NodeMCU ESP8266 - IotCircuitHub
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 5/19
8/3/23, 3:18 PM Smart Home with Google Assistant & Alexa using NodeMCU ESP8266 - IotCircuitHub
I have already explained, how to set up and add devices to Sinric Pro in
the following article.
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 6/19
8/3/23, 3:18 PM Smart Home with Google Assistant & Alexa using NodeMCU ESP8266 - IotCircuitHub
Click Here to visit the GitHub page of Sinric Pro for more details.
**Please download the latest version of the libraries from the given links.
Then install the libraries at Arduino IDE – Sketch – Include Library – Add
Zip Library.
Code_NodeMCU_Google_Alexa_SinricPro_4Relay_Switch.ino
#ifdef ENABLE_DEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#endif
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "SinricPro.h"
#include "SinricProSwitch.h"
#include <map>
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 7/19
8/3/23, 3:18 PM Smart Home with Google Assistant & Alexa using NodeMCU ESP8266 - IotCircuitHub
void setupRelays() {
for (auto &device : devices) { // for each device (relay,
int relayPIN = device.second.relayPIN; // get the relay pin
pinMode(relayPIN, OUTPUT); // set relay pin to OUTPUT
digitalWrite(relayPIN, HIGH);
}
}
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 8/19
8/3/23, 3:18 PM Smart Home with Google Assistant & Alexa using NodeMCU ESP8266 - IotCircuitHub
void setupFlipSwitches() {
for (auto &device : devices) { // for each devi
flipSwitchConfig_t flipSwitchConfig; // create a new
void handleFlipSwitches() {
unsigned long actualMillis = millis();
for (auto &flipSwitch : flipSwitches) {
unsigned long lastFlipSwitchChange = flipSwitch.second.lastFlipSwi
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 9/19
8/3/23, 3:18 PM Smart Home with Google Assistant & Alexa using NodeMCU ESP8266 - IotCircuitHub
void setupWiFi()
{
Serial.printf("\r\n[Wifi]: Connecting");
WiFi.begin(WIFI_SSID, WIFI_PASS);
void setupSinricPro()
{
for (auto &device : devices)
{
const char *deviceId = device.first.c_str();
SinricProSwitch &mySwitch = SinricPro[deviceId];
mySwitch.onPowerState(onPowerState);
}
SinricPro.begin(APP_KEY, APP_SECRET);
SinricPro.restoreDeviceStates(true);
}
void setup()
{
Serial.begin(BAUD_RATE);
pinMode(wifiLed, OUTPUT);
digitalWrite(wifiLed, HIGH);
setupRelays();
setupFlipSwitches();
setupWiFi();
setupSinricPro();
}
void loop()
{
SinricPro.handle();
handleFlipSwitches();
}
Enter the APP KEY and APP SECRET with Wi-Fi name and Wi-Fi password
in the code.
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 10/19
8/3/23, 3:18 PM Smart Home with Google Assistant & Alexa using NodeMCU ESP8266 - IotCircuitHub
You can get the APP KEY and APP SECRET under the Credentials menu
in Sinric Pro
Also, enter the device id in the code. You will find the Device ID from the
Devices menu.
As I have used the free Sinric pro account, so I have entered the 3-device
IDs. (Sinric Pro gives 3 devices for FREE)
//#define TACTILE_BUTTON 1
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 11/19
8/3/23, 3:18 PM Smart Home with Google Assistant & Alexa using NodeMCU ESP8266 - IotCircuitHub
After doing all these steps, now you control the appliances with Google
Assistant and Alexa.
If the NodeMCU is connected with WiFi, then you can ask Alexa, to turn
on the light [“Alexa, Turn ON Room Light“]. Thus, you can control the
appliances like light, fan, etc with voice commands using Amazon Alexa
App, and also monitor the current status of the switches from anywhere in
the world from the Alexa App.
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 12/19
8/3/23, 3:18 PM Smart Home with Google Assistant & Alexa using NodeMCU ESP8266 - IotCircuitHub
You can also ask Google Assistant, to turn on the light [“Hey Google,
Turn ON the Room Light“]. Thus, you can control the appliances like
light, fan, etc with voice commands using Google Assistant, and also
monitor the current status of the switches from anywhere in the world
from the Google Home App.
You can always control the appliances manually with switches or push
buttons. and if the NodeMCU is connected with the Wi-Fi, then you can
monitor the real-time status in Google Home and Alexa App.
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 13/19
8/3/23, 3:18 PM Smart Home with Google Assistant & Alexa using NodeMCU ESP8266 - IotCircuitHub
If you want, you can also use this PCB to make the circuit compact and
give the project a professional look.
I hope you like this Smart house IoT projects idea with the NodeMCU
ESP8266.
Please do share your feedback on this IoT project. Thank you for your
time.
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 14/19
8/3/23, 3:18 PM Smart Home with Google Assistant & Alexa using NodeMCU ESP8266 - IotCircuitHub
# Smart Home
PREVIOUS NEXT
Related Posts
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 15/19
8/3/23, 3:18 PM Smart Home with Google Assistant & Alexa using NodeMCU ESP8266 - IotCircuitHub
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 16/19
8/3/23, 3:18 PM Smart Home with Google Assistant & Alexa using NodeMCU ESP8266 - IotCircuitHub
Categories:
Translate:
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 17/19
8/3/23, 3:18 PM Smart Home with Google Assistant & Alexa using NodeMCU ESP8266 - IotCircuitHub
Tags:
Tasmota Telegram
Latest Posts:
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 18/19
8/3/23, 3:18 PM Smart Home with Google Assistant & Alexa using NodeMCU ESP8266 - IotCircuitHub
https://iotcircuithub.com/smart-home-with-google-assistant-alexa/ 19/19