LIMPINGLIM
Published © GPL3+

Amazon Echo (IR) TV Remote

Acquire the ability to switch ON/OFF (and mute) TV by voice command via Amazon Echo.

BeginnerShowcase (no instructions)4,115
Amazon Echo (IR) TV Remote

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Wemos D1 Mini
Espressif Wemos D1 Mini
×1
IR Emitter Module
×1
IR receiver (generic)
×1
Plastic Enclosure
×1

Hand tools and fabrication machines

Portable Drill and Bits

Story

Read more

Schematics

Wiring Diagram

1. connecting the IR reader to the Arduino Nano to read the IR codes from remote controllers.
2. connecting the Wemos D1 mini and the IR emitter to the Arduino Nano to send the IR codes to the selected devices.

Code

Combined Sketch (PART 1. IR Reader; PART 2. IR Emitter; & PART 3. Wemos D1 Mini)

Arduino
1. Wire up the IR Receiver to the Nano and load PART 1 of the combined sketch into the Nano. Copy the IR codes that you want to use later.
2. Load PART 3 of the combined sketch into the Wemos D1 mini. Remember to key in your wifi details before loading. Use Amazon Alexa App to add the device(s) into the Home Automation list & test voice commands.
3. Wire up the IR Emitter to the Nano and load PART 2 of the combined sketch into the Nano.
4. Wire the Wemos D1 Mini with the Nano & IR Emitter.
Refer to Grensom's video on Youtube for deeper understanding.
//PART 1. IR receiver Sketch to read IR codes from a remote controller. The codes are needed in the IR Emitter Sketch.

#include <IRremote.h>

int receiverpin = 3;

IRrecv irrecv(receiverpin);
decode_results results;

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

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


//PART 2. IR Emitter Sketch to send the appropriate IR code when trigger by the Wemos D1 Mini.Pls note that the code 0xFD708F & 0xFDB04F below are from my TV remote controller. You would have gotten yours from above sketch.

#include <IRremote.h>
#include <IRremoteInt.h>

IRsend irsend;

int TVpower = 9;          //pin for ON/OFF signal
int TVmute = 8;         //pin for Volume signal
int IRpower = 2;          //power to IR LED

int TVpowerState = 0;       //default states
int lastTVpowerState = 0;
int TVmuteState = 0;
int lastTVmuteState = 0;

void setup() {
  Serial.begin(9600);
  pinMode(TVpower, INPUT);
  pinMode(TVmute, INPUT);
  pinMode(IRpower, OUTPUT);
  digitalWrite(IRpower, HIGH);
}

void loop() {
  delay(3000);
  TVmuteState = digitalRead(TVmute);
  if (TVmuteState != lastTVmuteState){
    irsend.sendNEC(0xFD708F, 32);   //TV remote Volume-Mute Code
    Serial.println("Volume Mute");
    delay(50);
    lastTVmuteState = TVmuteState;
    }else{
      TVpowerState = digitalRead(TVpower);
      if (TVpowerState != lastTVpowerState){
        irsend.sendNEC(0xFDB04F, 32);     //TV remote ON/OFF Code
        Serial.println("TV ON");
        delay(50);
        lastTVpowerState = TVpowerState;
        }else{
          }
      }
  }  

  

//PART 3. This Sketch is for the Wemos D1 Mini to work with Amazon Alexa to turn the digital output pins HIGH and LOW. Remember to key in your Wifi details before loading the sketch into the Wemos D1 Mini.


#include <ESP8266WiFi.h>
#include "WemoSwitch.h"
#include "WemoManager.h"
#include "CallbackFunction.h"

// prototypes
boolean connectWifi();

//Callbacks
void TVOn();
void TVOff();
void MuteOn();
void MuteOff();

//------- Replace the following! ------
char ssid[] = "YOUR WIFI NAME";       // your network SSID
char password[] = "YOUR WIFI PASSWORD";  // your network key

WemoManager wemoManager;
WemoSwitch *TV = NULL;
WemoSwitch *Mute = NULL;

const int TVpowerPin = D4;
const int MutePin = D3;

void setup()
{
  Serial.begin(115200);

  // Set WiFi to station mode and disconnect from an AP if it was Previously
  // connected
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);

  // Attempt to connect to Wifi network:
  Serial.print("Connecting Wifi: ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  IPAddress ip = WiFi.localIP();
  Serial.println(ip);

  wemoManager.begin();
  // Format: Alexa invocation name, local port no, on callback, off callback
  TV = new WemoSwitch("TV", 80, TVOn, TVOff);
  wemoManager.addDevice(*TV);
  Mute = new WemoSwitch("Mute", 81, MuteOn, MuteOff);
  wemoManager.addDevice(*Mute);
  
  pinMode(TVpowerPin, OUTPUT); // initialize digital D0 as an output.
  pinMode(MutePin, OUTPUT); // initialize digital D5 as an output.
  delay(10);
  digitalWrite(TVpowerPin, LOW);
  digitalWrite(MutePin, LOW);
}

void loop()
{
  wemoManager.serverLoop();
}

void TVOn() {
    Serial.print("Turn ON TV...");
    digitalWrite(TVpowerPin, HIGH);
}
void TVOff() {
    Serial.print("Turn OFF TV...");
    digitalWrite(TVpowerPin, LOW);
}

void MuteOn() {
    Serial.print("Volume Mute ON...");
    digitalWrite(MutePin, HIGH);
}
void MuteOff() {
    Serial.print("Volume Mute OFF...");
    digitalWrite(MutePin, LOW);
}

Credits

LIMPINGLIM

LIMPINGLIM

2 projects • 28 followers

Comments