loading
Picture of Control Any Circuit With a TV Remote (and an Arduino)

Most of the buttons on a remote control are never used. So why not use them to control appliances and other electronics around your house. In this project, I am going to show you how to use an Arduino to decode the signal from your remote and use it to make an outlet switch that can turn your electronics on and off.

When you are done, you will be able to control lights, fans and even your coffee maker with your TV remote.
 
Remove these adsRemove these ads by Signing Up

Step 1: Materials

Picture of Materials
Here are the materials and tools that you will need for this project:

Materials:
Arduino Microcontroller
AC Power Adapter For the Arduino
38 kHz Infrared Receiver Module  (Radio Shack part# 276-640)
Red LED
Green LED
Momentary Pushbutton Switch
Two 100 ohm Resistors
10 kohm Resistor
Diode
5V Relay or Relay Shield
Printed Circuit Board
Plastic Project Housing
Extension Cord

Tools:
Wire Strippers
Soldering Iron and Solder
Drill and Bit Set
Sharp Knife
Hot Glue Gun

Step 2: Download and Install the IR Remote Library

Picture of Download and Install the IR Remote Library
Image2.jpg
Image3.jpg
Image1.jpg

This project uses an IR remote library that was developed by Ken Shirriff. This library lets you decode the signal coming from your remote. You can check out his original project and setup here: http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html

The first thing that you need to do for this project is download the library zip file. You can find it here: https://github.com/shirriff/Arduino-IRremote

Click "Download ZIP" on the right side of the page and save the zip file. Then unzip it. Rename the folder "IRRemote" (unless that name is already being used).

Then copy the folder into your libraries directory. The libraries directory should contain the folder "IRremote." If for some reason you already have a folder with this name, then you may need to rename it. The IRremote folder should contain the files. A lot of problems experienced when uploaded in the code, are caused be the library not being loaded in the correct location.

UPDATE: In version 1.5.8 of the Arduino software, several of the default libraries were changed. This created duplicate IRremote libraries. So if you encounter errors, this is likely the source. I have attached a copy of the library with the file names changed to avoid the conflict. Just unzip it. Then copy the "Arduino-IRremote-master2" folder into the libraries folder in the Arduino program folder.

Step 3: The Arduino Code

Picture of The Arduino Code
// Upload this code to your Arduino

#include <IRremote.h>

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long CurrentValue = 0;
unsigned long StoredCode = 0;
const int buttonPin = 6;     // the number of the pushbutton pin
const int ledPin =  4;      // the number of the LED pin
const int outputPin =  3;      // the number of the output LED pin
const int relayPin =  2;      // the number of the relay pin
int buttonState = 0;         // variable for reading the pushbutton status
int RecordState = 0;         //is the reciever in record mode
int outputState = 1;         //is the output on or off

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver

    // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);    
  // initialize the pushbutton pin as an input:
  pinMode(outputPin, OUTPUT);    
  // initialize the pushbutton pin as an input:  pinMode(buttonPin, INPUT);   
  pinMode(relayPin, OUTPUT);    
  // initialize the pushbutton pin as an input:  pinMode(buttonPin, INPUT);   

}


void loop() {

   // read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

   // if a signal is detected, store the value
if (irrecv.decode(&results)) {
  CurrentValue = (results.value);

   // if the recieved value equals the programed value, then toggle the output state
  if(CurrentValue == StoredCode) {
      outputState = !outputState;
   }

   // if the record mode is activated store the current value as the programed value
  if (RecordState == 1) {
    StoredCode = CurrentValue;
    RecordState = 0;
    digitalWrite(ledPin, LOW);  
    Serial.println(StoredCode);  //displays stored code for reference
   }

   // Receive the next value
  irrecv.resume();
}

else //if no signal is detected, then the current value is 0
{
  CurrentValue = 0;
}

  // check if the record button is pressed.
  // if it is, the buttonState is HIGH:
if (buttonState == HIGH) {   

  //wait for the button to be released
  while (buttonState == HIGH) {
    buttonState = digitalRead(buttonPin);
  }

   //turn on the LED to indicate that record mode is on
    digitalWrite(ledPin, HIGH); 
    RecordState = 1;
}

   //set the appropriate output state
if(outputState == 1) {

      digitalWrite(outputPin, HIGH);
      digitalWrite(relayPin, HIGH);
}
else {
        digitalWrite(outputPin, LOW);
        digitalWrite(relayPin, LOW);
}

}

Step 4: The Circuit

Picture of The Circuit
Img_1686b.jpg
This circuit uses a 38 kHz Infrared Receiver Module to detect the signal from the remote. The right pin of this connected to 5V. The middle pin is connected to GND. The Left pin connects to digital pin 11 on the board.

The circuit also has two indicator LEDs. One indicates that the receiver is in programming mode and the other indicates whether the output is on or off. One end of each LED is connected to GND. The other end is connected to a 100 ohm series resistor. The resistors are then connected to digital pins 3 and 4.

A momentary switch is used to set programming mode. One end of the switch is connected to 5V. The other end of the switch is connected to digital pin 6 and a 10 kohm resistor. The other end of the resistor is connected to GND. 

An optional relay/relay shield can be connected to digital pin 2 and GND.

You can add any additional outputs that you want. This can let you control multiple devices or multiple functions on the same device.

Step 5: Test the Circuit on a Breadboard

Picture of Test the Circuit on a Breadboard
Img_1681b.jpg
vlcsnap-2014-03-22-23h18m00s137.png
vlcsnap-2014-03-22-23h18m17s39.png
vlcsnap-2014-03-22-23h18m47s103.png
It is always a good idea to test your circuit on a breadboard before soldering it together.

When the Arduino is powered, the output indicator (green) LED should turn on. This indicates that the output at pin 2 is HIGH and can be used to activate another circuit. To program the receiver, press the button. When the button is released, the programming mode indicator (red) LED will turn on.

Now point your remote at the receiver module and press a button. If the Arduino registered the signal, the programming mode LED will turn off. The receiver is now programmed. Pressing this button on the remote again will cause the output at pin 2 to toggle between off and on. The output state is indicated by the LED.

You can use the signal from pin 2 to activates another circuit directly or you can use a relay/relay shield to turn an appliance on and off. 

If you connect the Arduino to your computer you can use the serial monitor function to observe the value for the signals that you are programming.

Step 6: Solder the Circuit Together on a Printed Circuit Board

Picture of Solder the Circuit Together on a Printed Circuit Board
Img_1728.jpg
After testing the circuit on a breadboard, you can solder it together on a printed circuit board. The IR receiver module, the switch and the LEDs would be mounted to the housing. So I connected them to the board with jumper wires.

I added a small relay that would be activated by the output of pin 2. In most cases you will want to connect a relay driver circuit. This is because the maximum output of an Arduino digital pin is 40 mA and most relays require more than this to operate. However, I found a relay that only required 25mA to operate. So I was able to connect it directly to the digital pin. It is always a good idea to attach a flyback diode across the terminals of the coil of a relay. This helps to protect against voltage spikes when the relay is turned off. 

The relay can act as a general switch and activate just about anything. In this case, I attached an extension cord. This will allow it to act as a remote controlled outlet. Always check to make sure that your relay is rated high enough for your intended load. 

Step 7: Mount the Circuit in an Insulated Housing

Picture of Mount the Circuit in an Insulated Housing
IMG_1695.JPG
IMG_1699.JPG
IMG_1701.JPG
IMG_1737.JPG
Now you need to find a good insulated housing to hold your project. I used a 6x3x2 plastic project housing from RadioShack. On one end, I drilled two holes from the LEDs, one hole for the IR receiver and one hole for the switch. Then I made holes in the opposite end for the Arduino power cord and the extension cord.

I used hot glue to secure the LEDs and the Receiver. The switch was held in place with its own nut and lock washer. You can also use hot glue to secure loose wires and to hold the boards in place.

Be very careful not to accidentally pull any wires out of the Arduino as you are fitting everything into the housing. 

Step 8: Use Your Remote Controlled Switch to Activate Appliances and Other Electronics

Plug in the power supply for the Arduino and it will automatically turn on. Then plug the male end of the extension cord into an outlet and plug the device that you want to control into the female end of the extension cord. The device should turn on. 

To program the receiver, press the red button. The red light will turn on. Then point your remote at the receiver and press a button. If the Arduino registered the signal, then the red light will turn off. Now you can use that button to turn the attached device on and off. 

You can use this to remotely control lights, fans or even your coffee maker. 

Step 9: Manually Insert IR Values into the Arduino Code (optional)

Picture of Manually Insert IR Values into the Arduino Code (optional)
If you plug the Arduino into your computer, you can use the Serial Monitor tool to view the value of the IR signals for the various buttons on your remote. This gives you the option of manually inserting these values into the code. By doing this you can program responses to multiple buttons. It also means that you will not have to reprogram the receiver whenever the power is disconnected.
1-40 of 110Next »
maitrteya5 days ago

For some unknown reason to me, it is trying to read from the RobotIRlibrary when i try and compile it. These are the errors I am getting:

Arduino: 1.6.5 (Windows 7), Board: "Arduino Uno"

Build options changed, rebuilding all

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp:5:1: error: missing terminating " character

int RECV_PIN = TDK2"; // the pin the IR receiver is connected to

^

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp:5:16: error: 'TDK2' was not declared in this scope

int RECV_PIN = TDK2"; // the pin the IR receiver is connected to

^

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp: In function 'void beginIRremote()':

sir the same problem is occuring to me

what to do please suggest

Use the library folder that I have attached in the the instructable.
maitrteya5 days ago

when i bulid the circuit and pressed the remote keys

nothing appears in the serial display on my pc

now what to do please suggest

makeosaurus11 days ago

For some unknown reason to me, it is trying to read from the RobotIRlibrary when i try and compile it. These are the errors I am getting:

Arduino: 1.6.5 (Windows 7), Board: "Arduino Uno"

Build options changed, rebuilding all

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp:5:1: error: missing terminating " character

int RECV_PIN = TDK2"; // the pin the IR receiver is connected to

^

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp:5:16: error: 'TDK2' was not declared in this scope

int RECV_PIN = TDK2"; // the pin the IR receiver is connected to

^

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp: In function 'void beginIRremote()':

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp:10:2: error: 'irrecv' was not declared in this scope

irrecv.enableIRIn(); // Start the receiver

^

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp: In function 'bool IRrecived()':

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp:14:9: error: 'irrecv' was not declared in this scope

return irrecv.decode(&results);

^

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp: In function 'void resumeIRremote()':

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp:18:5: error: 'irrecv' was not declared in this scope

irrecv.resume(); // resume receiver

^

Error compiling.

This report would have more information with

"Show verbose output during compilation"

enabled in File > Preferences.

This problem is caused by there being two library files with the same name (see step 2). You can solve this by renaming one of the folders and changing the library call command. You can download the attached zip file for an example.

Thank you for your quick reply but what do you mean by changing the library call command?

Thanks,

Make-o-Saurus

This project uses the IR Remote library listed above. In a recent update to the Arduino software, they introduced different library with the same name. You can't have two libraries with the same name or you will have lots of problems when you try to use a library in a program. So you need to change the name of one of them so that they program can know which one to reference when you use the "include" command.

KiranR31 month ago

How can i use it for long time , i mean how to store the remote code permanently?

DIY Hacks and How Tos (author)  KiranR31 month ago
The easiest way to make the code permanent is to manually write it into the code. That way it will always be there even after the power is disconnected.

Is there is any other idea to store IR code in an EEPROM?

DIY Hacks and How Tos (author)  KiranR31 month ago

Sorry, but I don't really know how you would do that.

nikv11 month ago
How can I control multiple relays with multiple buttons? Also, how can I add a servo instead of a relay?
DIY Hacks and How Tos (author)  nikv11 month ago

You would need to change the code to set up a second array to store the second code. A servo could work just the same way. You just need to change the code to output a servo signal. You can find more information about that hereLhttp://www.arduino.cc/en/Reference/Servo

Thanks for such a quick reply, i guess i have some homework to do ;)

PiRaspBerry2 months ago
would it possible to have more outputs with more buttons on the remote?
Yes. You could set it to control as many appliances as you want.
thnx iam gonna make this tot control my hole room
midoaboud2 months ago

How can I simulate it on https://123d.circuits.io/ because i had some errors in code during simulation

DIY Hacks and How Tos (author)  midoaboud2 months ago
Sorry. I am not familiar with 123d circuits

may you give me a useful link or similar simulation program to use it for arduino because such programs needs licence and for VBB it is hard to find serial number?....thanks in advance

https://123d.circuits.io/circuits/822112-the-unnamed-circuit/edit#breadboard

zain siddiqui2 months ago
Sir what would be the output for appliance? THANKS for your help
zain siddiqui2 months ago
Sir could you guide me where to attach the extention cord? Thx

Take the extension cord. In the center cut the insulated strip that is holding the two wires together. Then cut one of the wires and strip the insulation off both of the cut ends. Solder these two wire ends to the relay on the circuit board. When the relay is turned on it will complete the circuit and turn on the appliance.

zain siddiqui2 months ago
Is relay necassary If i just use it for 1 appliance ? Thankyou

Yes The relay is necessary because you are switching an AC appliance on and off.
zain siddiqui2 months ago
Is relay necassary If i just use it for 1 appliance ? Thankyou

redatime3 months ago
In your picture with the breadboard which component is the black square at the top?
DIY Hacks and How Tos (author)  redatime3 months ago

That is a momentary switch. I use that switch with the breadboard because it was easier to connect that the switch that I used is the finished project.

redatime4 months ago

what arduino should be used?

DIY Hacks and How Tos (author)  redatime4 months ago
I used Arduino Uno but any board should work.

thanks a lot !

dath4 months ago

hii could you tell me how to connect the relay ,...

tanx,....:)

DIY Hacks and How Tos (author)  dath4 months ago

Take a power cord and cut one of the two wires. Strip the insulation on each side of the cut wire. Then connect these wires to relay's common and normally open terminals.

spike19984 months ago

This report would have more information with

"Show verbose output during compilation"

enabled in File > Preferences.

Arduino: 1.0.6 (Windows 7), Board: "Arduino Uno"

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\IRremoteTools.cpp:5: error: 'TKD2' was not declared in this scope

what do i need to do about it

DIY Hacks and How Tos (author)  spike19984 months ago
At the bottom of step 2, I describe how to rename the library if this error occurs.
Eloisa CamelM4 months ago

finally, it worked! :) thank you..

splendid874 months ago

I have pressed the receiver button, and release it.

Then the red led on.

And i press my tv remote button but red led still on and in serial monitor didn't receive any code too.

Kindly remedy the problem!

Thanks in advance

DIY Hacks and How Tos (author)  splendid874 months ago
For whatever reason, the arduino is not sensing the signal from the remote. There could be a problem with one of the components. Or maybe something isn't hooked up properly. Or there could be interference from the light in the room.
Eloisa CamelM5 months ago

Sir can i use a relay module shield without an optocoupler?

1-40 of 110Next »