Things used in this project

Code

AmazonEcho_Home_Automation_NodeMCUArduino
Upload the sketch to any NodeMCU and get started.. Make sure to download all the libraries that are required.
/**********************************************************************************
  * Code for controlling multiple devices connected to one NodeMCU using Amazon Echo
  * 
  * Written by Sid for Sid's E Classroom
  * 
  * https://www.youtube.com/c/SidsEClassroom
  *********************************************************************************/
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "fauxmoESP.h"

#define WIFI_SSID "**********"//change your Wifi name
#define WIFI_PASS "*********"//Change your Wifi Password
#define SERIAL_BAUDRATE                 115200

fauxmoESP fauxmo;
//declare switching pins
//Change pins according to your NodeMCU pinouts
#define Kitchen D1
#define Bedroom D2
#define Living D3
// -----------------------------------------------------------------------------
// Wifi Setup
// -----------------------------------------------------------------------------

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());
}
// -----------------------------------------------------------------------------
// Device Callback
// -----------------------------------------------------------------------------
void callback(uint8_t device_id, const char * device_name, bool state) {
  Serial.print("Device "); Serial.print(device_name); 
  Serial.print(" state: ");
  if (state) {
    Serial.println("ON");
  } else {
    Serial.println("OFF");
  }
  //Switching action on detection of device name
  if ( (strcmp(device_name, "Kitchen Lights") == 0) ) {
    // adjust the relay immediately!
    if (state) {
      digitalWrite(Kitchen, HIGH);
    } else {
      digitalWrite(Kitchen, LOW);
    }
  }
  if ( (strcmp(device_name, "Bedroom Lights") == 0) ) {
    // adjust the relay immediately!
    if (state) {
      digitalWrite(Bedroom, HIGH);
    } else {
      digitalWrite(Bedroom, LOW);
    }
  }
  if ( (strcmp(device_name, "Living Room Lights") == 0) ) {
    // adjust the relay immediately!
    if (state) {
      digitalWrite(Living, HIGH);
    } else {
      digitalWrite(Living, LOW);
    }
  }
}

void setup() {
    //Initialize pins to Low on device start
    pinMode(Kitchen, OUTPUT);
    digitalWrite(Kitchen, LOW);
    pinMode(Bedroom, OUTPUT);
    digitalWrite(Bedroom, LOW);
    pinMode(Living, OUTPUT);
    digitalWrite(Living, LOW);
    
    // Init serial port and clean garbage
    Serial.begin(SERIAL_BAUDRATE);
    Serial.println("FauxMo demo sketch");
    Serial.println("After connection, ask Alexa/Echo to 'turn <devicename> on' or 'off'");

    // Wifi
    wifiSetup();

    // Device Names for Simulated Wemo switches
    fauxmo.addDevice("Living Room Lights");
    fauxmo.addDevice("Kitchen Lights");
    fauxmo.addDevice("Bedroom Lights");
    fauxmo.onMessage(callback);
}

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

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

How to Add Alexa to a Raspberry Pi
Easy
  • 2,044
  • 20

Full instructions

Solution that allows turning any Linux-based device into an Amazon Echo.

Send e-mail - NodeMCU with Mikroelektronika Clicks
Easy
  • 134
  • 2

Full instructions

We read the data with the ambient click and in case the values become small, an e-mail message is sent.

Arduino-Controlled Wall-E Head
Easy
  • 604
  • 8

Full instructions

In this project I'll show you how to control a servo remotely from a regular web page without needing a web server in your Arduino board.

NodeMCU Webserver with Class-Based 60-Second Temp Average
Easy
  • 307
  • 2

Protip

Averaging temperatures over 60 seconds smooths some of the sensor limitations, allowing for a smoother graphic.

BLYNKING webpage data using ThingSpeak and NodeMcu
Easy
  • 291
  • 3

Protip

A simple project to display a particular webpage data in blynk app via bluetooth module and using thingspeak platform.

Add WiFi to Arduino UNO
Easy
  • 1,016
  • 3

Protip

Connect your mincrocontroller to the internet by adding ESP8266 WiFi Module!

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login