Greg Ensom
Published © GPL3+

Use Alexa to Control Your TV!

You ever lose your clicker/remote and wish you could just talk to your TV? Well anything your clicker can do, your Alexa can do!

IntermediateFull instructions provided2 hours19,964
Use Alexa to Control Your TV!

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
This is Used with the IR Transmitting Diode to send the TV Commands to the Television
×1
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
This Component is the Wi-Fi Module that connects to the Amazon Alexa App as a "WEMO" device. Sends pulse for each device to Arduino UNO
×1
IR Transmitter/Receiver
This Component is used in series with a 100 Ohm Resistor to send IR Commands to the TV
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

NodeMCU to Arduino Schematic

This is the Final Schematic Connecting the Arduino the NodeMCU (Wi-Fi Module)

Code

ESP8266-Alexa.ino

C/C++
This is to be written to the NodeMCU Chip to Emulate a "WEMO" Device via Arduino IDE
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "fauxmoESP.h"

// -----------------------------------------------------------------------------
// Wifi Credentials
// -----------------------------------------------------------------------------

#define WIFI_SSID "linksys"
#define WIFI_PASS ""

#define SERIAL_BAUDRATE                 115200

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());
}

// -----------------------------------------------------------------------------
// Initilize Pins
// -----------------------------------------------------------------------------

#define RELAY_PIN1 13
#define RELAY_PIN2 2
#define RELAY_PIN3 14
#define RELAY_PIN4 15

void setup() {
  //initialize relay pins
  pinMode(RELAY_PIN1, OUTPUT);
  digitalWrite(RELAY_PIN1, LOW);
  pinMode(RELAY_PIN2, OUTPUT);
  digitalWrite(RELAY_PIN2, LOW);
  pinMode(RELAY_PIN3, OUTPUT);
  digitalWrite(RELAY_PIN3, LOW);
  pinMode(RELAY_PIN4, OUTPUT);
  digitalWrite(RELAY_PIN4, LOW);
  
    // Init serial port and clean garbage
    Serial.begin(SERIAL_BAUDRATE);
    Serial.println();
    Serial.println();
    Serial.println("FauxMo demo sketch");
    Serial.println("After connection, ask Alexa/Echo to 'turn pixels on' or 'off' or 'turn relay on' or 'off'");

  // Wifi
  wifiSetup();

// -----------------------------------------------------------------------------
// Alexa Device Names
// -----------------------------------------------------------------------------

  // Fauxmo
  fauxmo.addDevice("TV");
  fauxmo.addDevice("GregsNetflix");
  fauxmo.addDevice("Sleep");
  fauxmo.addDevice("Office");
  fauxmo.onMessage(callback);
}

// -----------------------------------------------------------------------------
// Alexa Operation Calls
// -----------------------------------------------------------------------------

void callback(uint8_t device_id, const char * device_name, bool state) {
  Serial.printf("[MAIN] %s state: %s\n", device_name, state ? "ON" : "OFF");
  
  if ( (strcmp(device_name, "TV") == 0) ) {
    // adjust the relay immediately!
    if (state) {
      digitalWrite(RELAY_PIN1, HIGH);
    } else {
      digitalWrite(RELAY_PIN1, HIGH);
    }
  }
  
  if ( (strcmp(device_name, "GregsNetflix") == 0) ) {
    // adjust the relay immediately!
    if (state) {
      digitalWrite(RELAY_PIN2, HIGH);
    } else {
      digitalWrite(RELAY_PIN2, LOW);
    }
  }
  
  if ( (strcmp(device_name, "Sleep") == 0) ) {
    // adjust the relay immediately!
    if (state) {
      digitalWrite(RELAY_PIN3, HIGH);
    } else {
      digitalWrite(RELAY_PIN3, LOW);
    }
  }

  if ( (strcmp(device_name, "Office") == 0) ) {
    // adjust the relay immediately!
    if (state) {
      digitalWrite(RELAY_PIN4, HIGH);
    } else {
      digitalWrite(RELAY_PIN4, LOW);
    }
  }
}

void loop() {
  fauxmo.handle();
  delay(500);
  digitalWrite(RELAY_PIN1, LOW);
  digitalWrite(RELAY_PIN2, LOW);
  digitalWrite(RELAY_PIN3, LOW);
  digitalWrite(RELAY_PIN4, LOW);
}

IR-Alexa-Send.ino

C/C++
This is Uploaded to the Arduino UNO to read signals from NodeMCU and send out the appropriate IR Signals via the IR Transmitting Diode
#include <IRremote.h>

IRsend irsend;

#define a 4
#define b 5
#define c 6
#define d 7

void setup() {
  Serial.begin(9600);
  pinMode(a, INPUT);
  pinMode(b, INPUT);
  pinMode(c, INPUT);
  pinMode(d, INPUT);
}

void loop() {
  if (digitalRead(a) == HIGH) {
    irsend.sendNEC(0x57E3E817, 32); //Power Code
    Serial.println("TV");
    delay(500);
  }
  if (digitalRead(b) == HIGH) {
    irsend.sendNEC(0x57E354AB, 32); //Enter Key
    delay(2000);
    irsend.sendNEC(0x57E39867, 32); //Up Key
    delay(1000);
    irsend.sendNEC(0x57E39867, 32); //Up Key
    delay(1000);
    irsend.sendNEC(0x57E39867, 32); //Up Key
    delay(1000);
    irsend.sendNEC(0x57E3B44B, 32); //Right Key
    delay(1000);
    irsend.sendNEC(0x57E354AB, 32); //Enter
    delay(2000);
    irsend.sendNEC(0x57E354AB, 32); //Enter 
    Serial.println("The Office");
    delay(500);
  }
  if (digitalRead(c) == HIGH) {
    irsend.sendNEC(0x57E38679, 32); //Options Button
    delay(1500);
    irsend.sendNEC(0x57E3CC33, 32); //Down key
    delay(700);
    irsend.sendNEC(0x57E3CC33, 32); //Down key
    delay(700);
    irsend.sendNEC(0x57E3CC33, 32); //Down key
    delay(700);
    irsend.sendNEC(0x57E3CC33, 32); //Down key
    delay(700);
    irsend.sendNEC(0x57E3B44B, 32); //Right Key
    delay(700);
    irsend.sendNEC(0x57E3B44B, 32); //Right Key
    delay(900);
    irsend.sendNEC(0x57E38679, 32); //Options Button    
    Serial.println("Sleep Timer");
    delay(500);
  }
  if (digitalRead(d) == HIGH) {
    irsend.sendNEC(0x57E34AB5, 32); //Netflix Code
    Serial.println("Greg's Netflix");
    delay(500);
  }
}

IR_REMOTE_read.ino

C/C++
Use this Code on your Arduino to read the Clicker Hits coming from your Remote to the IR Receiver.
//2017.06.22

#include <IRremote.h>
#include <LiquidCrystal.h>

/* HOW TO WIRE UP LCD SCREEN LEFT TO RIGHT PIN WITH PINS ON TOP SIDE
 *  
 *  GND - VCC - POT MIDDLE - 12 - GND - 11 - NONE - NONE - NONE - NONE - 5 - 4 - 9 - 2 - VCC - GND
 *  
 *  POT MUST HAVE 5V AND GND ON IT AND CAN ROTATE THE KNOB TO CHANGE LCD CONTRAST
 */
 
LiquidCrystal lcd(12, 11, 5, 4, 9, 2); //9 instead of 3 (NEED FOR TRANSMITTER)

int receiverpin = 10;

IRrecv irrecv(receiverpin);
decode_results results;


void setup() {
  lcd.begin(16, 2);
  pinMode(receiverpin, INPUT);
  Serial.begin(9600);
  irrecv.enableIRIn();
}

void loop() {
  if (irrecv.decode(&results))
  {
    Serial.println(results.value, HEX);
    irrecv.resume();
    lcd.clear();
    lcd.print(results.value, HEX);
    delay(150);
  }
}

Credits

Greg Ensom

Greg Ensom

2 projects • 30 followers
GitHub: https://github.com/Grensom || YouTube: https://www.youtube.com/grensom || Facebook: https://www.facebook.com/greg.ensom

Comments