Introduction:
This post is about Voice Based Home Automation with NodeMCU & Alexa using fauxmoESP. This IOT Project tutorial is based on the great open source lib & example developed by Xosé Perez (Tinkerman).
fauxmoESP is a library for ESP8266-based devices that emulates a Belkin WeMo device and thus allows you to control them using this protocol, in particular from Alexa-powered devices like the Amazon Echo or the Dot. You may use the Alexa with Espalexa library for more enhanced Home Automation Project.
But before that, you can check some of our Home Automation Projects made using ESP8266 or ESP32:
1. Home Automation with Arduino IoT Cloud using ESP32
2. Home Automation using NodeMCU & Android
3. Home Automation using ESP8266 WebServer
4. Home Automation using Blynk & NodeMCU
5. Home Automation using Google Firebase & NodeMCU
6. Industrial Automation using ESP8266 & AWS IoT Core
Alexa & Echo Dot
What is Alexa?
Alexa is capable of voice interaction, music playback, making to-do lists, setting alarms, streaming podcasts, playing audiobooks, and providing weather, traffic, and other real-time information. Alexa can also control several smart devices using itself as a home automation hub. We will use this project, the “Echo-Dot”, that allows users to activate the device using a wake-word, such as “Alexa” or “Computer”, as in “Star Trek!.
In the home automation space, Alexa can interact with several different devices as Philips Hue, Belkin Wemo, SmartThings, etc.
What is Echo Dot?
Echo Dot is a voice-controlled speaker that uses Alexa to play music, control smart home devices, make calls, answer questions, set timers and alarms, and more.
Features
1. Play music from Amazon Music, Spotify, Pandora, iHeartRadio, TuneIn, and SiriusXM
2. Call or message family and friends hands-free, or drop in from the Alexa App to your Echo device
3. Controls lights, locks, thermostats, and more with compatible connected devices
4. Use the built-in speaker, or for bigger sound, connect to speakers through Bluetooth or audio cable
Components Required for this Project:
The following are the list of components for designing Voice Based Home Automation with NodeMCU & Alexa Echo Dot.
- NodeMCU ESP8266-12E
- Echo Dot (2nd Generation)
- 2 X Mini BreadBoard
- 4-Channel Relay Module
- Male-Female Dupont Cables
- External 5V power supply or Battery
Block Diagram:
The below block diagram shows what will be developed in this project:
Circuit: Voice Based Home Automation with NodeMCU & Alexa
Assemble the hardware as shown in the figure below on your breadboard for Voice-Based Home Automation with NodeMCU & Alexa using fauxmoESP.
Setup for uploading Code & Libraries:
Step 1: Setup Arduino Preference for NodeMCU
Go to the file of Arduino IDE and select Preferences. Then add the following link in the “Additional Boards Manager URLs”, as shown in the figure below:
|
1 |
http://arduino.esp8266.com/stable/package_esp8266com_index.json |
Step 2: NodeMCU Board Installation
Go to Board Manager and Instal NodeMCU Board version 2.3.0 It’s very important otherwise Alexa doesn’t discover devices.
Step 3: Board Selection
Select Your NodeMCU board with the correct model as shown in the figure:
Step 4: Adding Libraries
You need to download 3 different libraries and add them to Arduino IDE Library. The libraries are:
1. fauxmoESP Library
2. ESPAsync TCP Library
3. ESPAsync Web Server Library
Video Tutorial & Explanation:
Source Code/Program:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
#include <Arduino.h> #ifdef ESP32 #include <WiFi.h> #else #include <ESP8266WiFi.h> #endif #include "fauxmoESP.h" #define WIFI_SSID "..your wifi name.." #define WIFI_PASS "..your wifi password.." #define SERIAL_BAUDRATE 115200 #define LED 2 /* Set Relay Pins */ #define RELAY_1 D5 #define RELAY_2 D6 #define RELAY_3 D7 #define RELAY_4 D8 fauxmoESP fauxmo; // ----------------------------------------------------------------------------- // Wifi // ----------------------------------------------------------------------------- void wifiSetup() { // Set WIFI module to STA mode WiFi.mode(WIFI_STA); // Connect Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID); WiFi.begin(WIFI_SSID, WIFI_PASS); // Wait while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(100); } Serial.println(); // Connected! Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str()); } void setup() { Serial.begin(SERIAL_BAUDRATE); //setup and wifi connection wifiSetup(); //Set relay pins to outputs pinMode(RELAY_1, OUTPUT); pinMode(RELAY_2, OUTPUT); pinMode(RELAY_3, OUTPUT); pinMode(RELAY_4, OUTPUT); //Set each relay pin to HIGH ====== NOTE THAT THE RELAYS USE INVERSE LOGIC ===== digitalWrite(RELAY_1, HIGH); delay(500); digitalWrite(RELAY_2, HIGH); delay(500); digitalWrite(RELAY_3, HIGH); delay(500); digitalWrite(RELAY_4, HIGH); delay(500); // You have to call enable(true) once you have a WiFi connection // You can enable or disable the library at any moment // Disabling it will prevent the devices from being discovered and switched fauxmo.enable(true); fauxmo.enable(false); fauxmo.enable(true); // Device Names for Simulated Wemo switches fauxmo.addDevice("Light One"); fauxmo.addDevice("Light Two"); fauxmo.addDevice("Outlet One"); fauxmo.addDevice("Outlet Two"); fauxmo.addDevice("Bed Room"); fauxmo.addDevice("Living Room"); fauxmo.addDevice("All Devices"); // fauxmoESP 2.0.0 has changed the callback signature to add the device_id, // this way it's easier to match devices to action without having to compare strings. fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) { Serial.printf("[MAIN] Device #%d (%s) state: %s value: %d\n", device_id, device_name, state ? "ON" : "OFF", value); digitalWrite(LED, !state); //Switching action on detection of device name if ( (strcmp(device_name, "Light One") == 0) ) { if (!state) { digitalWrite(RELAY_1, HIGH); } else { digitalWrite(RELAY_1, LOW); } } if ( (strcmp(device_name, "Light Two") == 0) ) { if (!state) { digitalWrite(RELAY_3, HIGH); } else { digitalWrite(RELAY_3, LOW); } } if ( (strcmp(device_name, "Outlet One") == 0) ) { if (!state) { digitalWrite(RELAY_2, HIGH); } else { digitalWrite(RELAY_2, LOW); } } if ( (strcmp(device_name, "Outlet Two") == 0) ) { if (!state) { digitalWrite(RELAY_4, HIGH); } else { digitalWrite(RELAY_4, LOW); } } if ( (strcmp(device_name, "Bed Room") == 0) ) { if (!state) { digitalWrite(RELAY_3, HIGH); digitalWrite(RELAY_4, HIGH); } else { digitalWrite(RELAY_3, LOW); digitalWrite(RELAY_4, LOW); } } if ( (strcmp(device_name, "Living Room") == 0) ) { if (!state) { digitalWrite(RELAY_1, HIGH); digitalWrite(RELAY_2, HIGH); } else { digitalWrite(RELAY_1, LOW); digitalWrite(RELAY_2, LOW); } } if ( (strcmp(device_name, "All Devices") == 0) ) { if (!state) { digitalWrite(RELAY_1, HIGH); digitalWrite(RELAY_2, HIGH); digitalWrite(RELAY_3, HIGH); digitalWrite(RELAY_4, HIGH); } else { digitalWrite(RELAY_1, LOW); digitalWrite(RELAY_2, LOW); digitalWrite(RELAY_3, LOW); digitalWrite(RELAY_4, LOW); } } }); } void loop() { // Since fauxmoESP 2.0 the library uses the "compatibility" mode by // default, this means that it uses WiFiUdp class instead of AsyncUDP. // The later requires the Arduino Core for ESP8266 staging version // whilst the former works fine with current stable 2.3.0 version. // But, since it's not "async" anymore we have to manually poll for UDP // packets fauxmo.handle(); static unsigned long last = millis(); if (millis() - last > 5000) { last = millis(); Serial.printf("[MAIN] Free heap: %d bytes\n", ESP.getFreeHeap()); } } |













13 Comments
After complete uploading code how to connect alexa.
edit the code. set your wifi password and wifi ssid. then open serial monitor, alexa will automatically get conected.
no sir alexa is not connecting.. please help me….
not getting discovered on Echo Version 3,
on Serial output I am getting only this
[MAIN] Free heap: 50712 bytes
[MAIN] Free heap: 50712 bytes
[MAIN] Free heap: 50712 bytes
Alexa is not discovered my NODE MCU , plz help me , i used your code only…
Sir,
First of all thanks to you,because i try to run lot of node micro controller based project, out of these your project is running in first attempt.
I am very glad to run this project but last few days ago my node mcu device is not discovered by alexa.
Programme downloaded successfully.
i make lot of efforts to run this but still i am zero.
efforts by me are as:-
i reset the alexa dot 3rd generation.
i reinstall the alexa app.
using arduino ide 1.8.10 version.
now i m using esp8266 community 2.3.0 version.
Three libraries – ESPAsyncTCP-master,
ESPAsyncUDP-master,
xoseperez-fauxmoesp-f60c46d80f9b
At location-C:\Users\dharam\Documents\libraries
Serial monitor message is –
[MAIN] Free heap: 46512 bytes
[MAIN] Free heap: 46512 bytes
[MAIN] Free heap: 46512 bytes
[MAIN] Free heap: 46512 bytes
[MAIN] Free heap: 46512 bytes
Sir please help me to resolve this issue(Alexa does not discover any device )
Regards,
D.M.Pawar
sir still i am not receiving any response .
sir as i think your code for is not for your follower
you have made this only for your self
so can we run this project.
Hey, whatever device I make I post it on the website for the public. And definitely you can run the project.
Sir please help me to resolve this issue(Alexa does not discover any device )
Dear,
I follwed your instructions, but once the compiler loads the program in the NodeMCU, I see that it connects to the internet, gets an IP address, and then I only get ^MAIN] Free heap: 50640 bytes.
I tried to use the smartphone Alexa app to add devices, but although I’m on the same WiFi spot on my LAN, it cannot discover the NodeMCU (I tried with “other” at the very bottom of the list).
Any idea what I can check ?
Thks in advance for your support.
Not a single review show successful project. Sir could you please respond to that issue. There is nothing in description showing device authorization or account credentials. It does not connect to alexa. Keeps printing “[MAIN] Free heap: 50616 bytes
” How come it connect to Alexa automatically? To whose account it connects? Needs additional info here @Mr.Alam (Author.)
Buenas noches, problemas con su código, no genera paguina WEB ni se conecta con Alexa…… Alguna solución