Sameer Tuteja
Created November 27, 2019

Activated Devices with Voice

Controlling devices like AC, TV, Dish etc which work on IR technology using Voice.

IntermediateFull instructions provided15
Activated Devices with Voice

Things used in this project

Story

Read more

Schematics

Circuit Diagram

Process Flow

Code

Code

C/C++
#include <SoftwareSerial.h>
SoftwareSerial esp8266(3, 2); //RX pin = 3, TX pin = 2
int state = 5; //define initial (5 = stand-by)
#define DEBUG true //show messages between ESP8266 and Arduino in serial port

void setup() {
  esp8266.begin(9600);
  Serial.begin(9600);
  pinMode (10, OUTPUT); // LED attached here

  sendData("AT+RST\r\n", 2000, DEBUG); //reset module
  delay(1000);
  sendData("AT+CWMODE=1\r\n", 1000, DEBUG); //set station mode
  delay(1000);
  sendData("AT+CWJAP=\"WIFI_SSID\",\"WIFI_PASSWORD\"\r\n", 2000, DEBUG); //connect wi-fi network (replace WIFI_SSID by your Wi-Fi router SSID and WIFI_PASSWORD by its password
  sendData("AT+CIPMUX=1\r\n", 1000, DEBUG); //allow multiple connections
  delay(1000);
  sendData("AT+CIPSERVER=1,PORTNUMBER\r\n", 1000, DEBUG); // start web server on port PORTNUMBER
  delay(1000);
  sendData("AT+CIPSTO=30\r\n", 1000, DEBUG); // SET TIMEOUT TO 30
  delay(500);
}

void loop() {

  if (esp8266.available())  //verify incoming data
  {
    String msg;
    String i;
    if (esp8266.find("+IPD,")) //if there is a message
    {
      i = esp8266.readStringUntil(',');
      msg = esp8266.readString(); //read whole message
      if (msg.indexOf("on LED") >= 0) digitalWrite(10, HIGH);
      else if (msg.indexOf("off LED") >= 0) digitalWrite(10, LOW);
      String closeCommand = "AT+CIPCLOSE=";
      closeCommand += i; // append connection id
      closeCommand += "\r\n";
      sendData(closeCommand, 1000, DEBUG); // close connection
    }
  }
}

//*******************
//Auxiliary functions
//*******************
String sendData(String command, const int timeout, boolean debug)
{
  String response = "";
  esp8266.print(command);
  long int time = millis();
  while ( (time + timeout) > millis())
  {
    while (esp8266.available())
    {
      char c = esp8266.read();
      response += c;
    }
  }
  if (debug)
  {
    Serial.print(response);
  }
  return response;
}

Credits

Sameer Tuteja

Sameer Tuteja

3 projects • 2 followers

Comments