Ayan Biswas
Published © GPL3+

Voice Controlled Switching Operations Using Amazon Echo Dot

This project enables the ease of access to use the electronic appliances of home like TV, Microwave oven etc just by voice command

IntermediateFull instructions provided5 hours1,194

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
Echo Dot
Amazon Alexa Echo Dot
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
LED (generic)
LED (generic)
×1

Software apps and online services

Amazon Alexa Official Arduino Skill
Amazon Alexa Official Arduino Skill

Story

Read more

Schematics

Schematics Design File | Fritzing

Code

Arduino Code for the Project

Arduino
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "fauxmoESP.h"

#define SERIAL_BAUDRATE     115200 //Serial baudrate

fauxmoESP fauxmo; //Declare fauxmoESP object

// Name virtual devices
const char* deviceZero="Hallway Light";

int ledPin = 13 ; //GPIO13 --- D7 of NodeMCU

#define WIFI_SSID "ANJALI VILLA NET" //Wifi SSID
#define WIFI_PASS "AYAN@445bi" //Wifi Password

void setup()
{

    // Init serial port
    Serial.begin(SERIAL_BAUDRATE);
    Serial.println();
    Serial.println();

    pinMode(ledPin,OUTPUT);
    digitalWrite(ledPin,LOW);
    
    Serial.println("Setting up wifi!");
    wifiSetup(); //Set up wifi

    //Setup fauxmo
    fauxmo.createServer(true); // not needed, this is the default value
    fauxmo.setPort(80); // This is required for gen3 devices
    fauxmo.enable(true);
    
    // Add virtual devices
    fauxmo.addDevice(deviceZero); //Add deviceZero
    fauxmo.onSetState(callback); //What function to execute when message is received
}

// Main Loop
void loop()
{
    // fauxmoESP uses an async TCP server but a sync UDP server
    // Therefore, we have to manually poll for UDP packets
    fauxmo.handle();
    delay(500);
}

// Device Callback
void callback(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);
    Serial.println(device_name);
    if (strcmp(device_name, deviceZero)==0)
    {
      if (state==1) //Turn LED on
      {
        digitalWrite(ledPin,HIGH);
        Serial.println("LED Turned on");
      }
      else //Turn LED off
      {
        digitalWrite(ledPin,LOW);
        Serial.println("LED Turned off");
      }
    }
    
}

//Pause Function
void pause(int pauseTime)
{
  Serial.println("Entering pause function!");
  unsigned long currentMillis = millis();
  long previousMillis = currentMillis;
  while ((currentMillis-previousMillis)<pauseTime/2)
  {
    //Serial.println("In pause loop!");
    currentMillis=millis();
  }
  ESP.wdtFeed();
  currentMillis = millis();
  previousMillis = currentMillis;
  while ((currentMillis-previousMillis)<pauseTime/2)
  {
    //Serial.println("In pause loop!");
    currentMillis=millis();
  }
  Serial.println("Exiting pause function!");
}

//Wifi Setup
void wifiSetup() 
{
    WiFi.mode(WIFI_STA); 
    wifi_set_sleep_type(LIGHT_SLEEP_T);

    // 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.print("Connected!");
    Serial.println();

    // Connected!
    Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
    Serial.println();

}

Credits

Ayan Biswas

Ayan Biswas

3 projects • 9 followers
Now I am a student of Jadavpur University,Kolkata in the Dept of Electronics and Telecommunication Engineering

Comments