Control Lights with TV Remotes

Our TV remotes control most of our entertainment like the TV, DVD player and Kodi box. We thought that it would be useful if the same TV remotes could also turn on powered devices like the lights so that we could get to the kitchen or bathroom while we’re watching a movie.

We setup our project to work with 2 different TV remotes, and we selected 2 push buttons on the remotes that we not being used in our home entertainment arrangement.

For this project we used 2 small Arduino programs. The first program we used to find TV remote IR codes and the second program used our codes to control the light switch.

The equipment we used:

Power Switch

The PowerTail II switch is an isolated DC-actuated power cord (NO or NC) for controlling power to 120VAC appliances with a 2 wire input.

ir_switch_powertail

An Arduino Power Relay module or Shield is much cheaper than a Power Switch and the code for this project will be identical. We used the Power Tail Switch because we have one and we didn’t want to cut up our power cords.

The Setup

The Setup is very straightforward (see code for pin outs), one data pin for the IR module and one digital output for the relay or Power Tail Switch.

ir_switch_nano

Finding TV Remote IR Codes

The simple code below is used to catch IR codes:

 /*
 
 IR TEST PROGRAM

PINOUTS:

lEFT = DATA PIN
MIDDLE = gnd
RIGHT = 3.3 volts

*/

#include 

int RECV_PIN = 11;  //11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  Serial.println("Setup Complete");
}

void loop()
{
  if (irrecv.decode(&results))
    {
     Serial.println(results.value, HEX);
     irrecv.resume(); // Receive the next value
     delay(500);
     
    }
}

Final Code

We used 2 remotes, a newer Samsung, and an old Philips. On the Samsung we used the A and B buttons to turn the lights on and off. On the Philips we used the sharp and natural buttons.

Below is our final code:

 /*
 
TV Remote Control of Switches and Powered Devices
PINOUTS:

lEFT = DATA PIN
MIDDLE = gnd
RIGHT = 3.3 volts

*/

#include <IRremote.h>

int RECV_PIN = 11;  //11;

IRrecv irrecv(RECV_PIN);

decode_results results;

int swtpin = 10;

void setup()
{
  Serial.begin(9600);
  pinMode(swtpin, OUTPUT);
  irrecv.enableIRIn(); // Start the receiver
  Serial.println("Setup Complete");
}

void loop()
{
  if (irrecv.decode(&results))
    {
      switch (results.value) {
     case 0x94CC5A5E: 
       Serial.println("A pushed - light on");
       digitalWrite(swtpin, HIGH);
       break;     
     case 0x23B1EF88:
       Serial.println("B pushed - light off");
       digitalWrite(swtpin, LOW);
       break;    
         case 0x16892E01: 
       Serial.println("natural pushed - light on");
       digitalWrite(swtpin, HIGH);
       break;     
     case 0xDAD07464:
       Serial.println("sharp pushed - light off");
       digitalWrite(swtpin, LOW);
       break;   
     default:
       Serial.println(results.value, HEX);
      }
      irrecv.resume();
     delay(500);
     
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s