Project showcase

Amazon Echo (IR) TV Remote © GPL3+

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

  • 997 views
  • 3 comments
  • 6 respects

Components and supplies

Necessary tools and machines

Portable Drill and Bits

About this project

After I bought an Amazon Echo Dot and managed to get some lights to be controlled through voice commands, I wanted to expand the capability to control other electronic devices so that I can do away with multiple remote controllers, or at least combine their basic functions into one single box. Going to expand control further to include an evaporative cooler and temperature sensing at a later stage.

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

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.
Wiring diagram aa9bg1pw9v

Comments

Author

Limpinglim
LIMPINGLIM
  • 4 projects
  • 2 followers

Additional contributors

  • Adapted from his project by Grensom

Published on

September 5, 2018

Members who respect this project

22539991 154705918462662 4263398914975069374 nDefaultPhoto

and 3 others

See similar projects
you might like

Similar projects you might like

Finding the IR Codes of Any IR Remote Using Arduino

Project tutorial by SHIVENDRA VATSA MISHRA

  • 713 views
  • 0 comments
  • 12 respects

Circuit Python IR Remote for Apple TV

Project tutorial by Liz - Blitz City DIY

  • 746 views
  • 0 comments
  • 6 respects

Pi Zero IR Blaster + Amazon Echo

Project in progress by Gowtham Gowda

  • 14,696 views
  • 3 comments
  • 16 respects

IR Remote Controlled Home Automation

Project tutorial by suhail jr

  • 9,835 views
  • 5 comments
  • 13 respects
Add projectSign up / Login