Introduction: Control Any Circuit With a TV Remote (and an Arduino)

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.

Step 1: Materials

Picture of Materials

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

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

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

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:

The first thing that you need to do for this project is download the library zip file. You can find it here:

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

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

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

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

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

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

Picture of 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.


Rutviks (author)2017-12-01


Thank you for all this information. But i am getting this error. Please help me with that.

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

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


Error compiling.

I don't know. This is a really old project. The libraries might have changed in the mean time.

GustavoS116 (author)2017-05-23

Thank you, Could you explain how to connect the relay to the extension chord, please

Cut one of the two wires in the extension cord. Then solder each of the cut ends to the switch terminals of the relay.

ReXeR999 (author)2017-04-11

Thank you, all nice working with my arduino uno. But i hane and arduino nano and arduino pro mini, but with them doesn't work... Any button switch onn and switch off relay, but i that will not... Please help my :)

Sorry for my "Serbian" English... :D

I am not sure that I understand the problem that you are having, could you please try to give me a little more detail?

Harlov (author)2017-03-03

I thank you for this

can you explain in more detail how to put a permanent remote code in the sketch


camcknight14 (author)2017-01-05

Hi, I would like to make a setup where I have a stationary bike and when I stop pedaling, the TV would turn off. Any idea how to do this? I assume using a photoeye, and arduino, and a IR signal would work. Would just like it that if I stop pedaling an IR Signal would be sent to the TV to turn it off. Any ideas would be much appreciated.

I actually made a system with that in mind. Check out this instructable

natix2015 (author)2016-10-16

sir can i ask, in your schematic i tried to do the same project as you did, but i did not get any lights turned on, so my question is. Does the relay does not have any suppy? Like 5v from the arduino or from the battery? Hope you'ld answer, it'll be very much appreciated btw. My relay is 5VDC and 10 A 250 DC

First you want to test the part of the circuit that comes before the relay. You can do this by replacing the relay with an LED and a resistor. If the LED lights up, then you know that the rest of the circuit is working and the relay is getting power. If all that is working, then you want to make sure that the relay is getting enough power. Some relays require more current than the digital pins can output (about 20 mA). Then check all the connections with the appliance that you want to power.

thank you for answering sir, I tried what you said that I should try first an LED and a resistor and it did light up. But my problem is the relay the relay only requires only 5VDC input. The mA that the relay can handle printed in it is erased. My question is that, can i use a transistor for pin2 ? So that i could supply 5V to the relay to switch on? I'll connect 1 of the pins of transistor to 5V of the arduino, then GND for the other pin, and then i would connect the coils of the relay to the 5v and GND of the transistor. BTW im using a BC548 transistor. Hope you would answer. Very well appreciated your first answer sir thanks.

Yeah. You can use a transistor to activate the relay.

Kiddybrain (author)2016-10-12

hallo , ik am a beginner and am really interested in making this project .. u did amazing ! please can u help me get the links from where i can but all the tools please ? because i want to use exactly as the tools u used to avoid any problems or errors on the way . am from belgium by the way . hope to hear from u soon . thanks

Unfortunately, I don't know exact part numbers for most of the parts. I just used whatever spare parts that I had lying around my workshop. But they should be generic enough that you can use anything similar and it should work. The only thing that you probably want to look carefully for is the 38 kHz Infrared Receiver Module. I purchased it from Radio Shack (part# 276-640). But You should be able to get it from other online suppliers such as

priyambada sharma (author)2016-08-04

How much cost and time will it consume??

The most expensive part would be the Arduino. I couldn't give you a detailed list of part prices because I used parts that I already had. I built it in about 10 hours.

Sallam (author)2016-06-06

Many Thanks for this project< I really liked & i make one like this & it's work properly.

But I need some note how to store two button to used,

Please can you help me to do this.

Best Regards.

Mostly you just need another variable to store the second code. Add a second relay

Duplicate and sections of code that you want to reuse. Just be sure give all the new stuff unique variable names.

ericg203 (author)2016-06-06

Can you post a picture or schematic of how the extension cord is connected. Thanks great project

Take an extension cord. Cut and strip off the insulation of one wire. Connect one of the cut wires to the normally open terminal of the wire and the other cut wire to the common terminal of the relay.

Thanks for the quick reply, I appreciate it. I would still like a picture if you have the chance. Thanks in advance

robertodelle (author)2016-04-18

Thanks, your instructables is well explained.

EstebanB5 (author)2016-02-17

hello, what kind of diode you used, and how connected the relay, know very little electronica, why I ask the question

Almost any diode will work. It is connected to the relay with the anode connected to the coil pin that is also connected to ground.

Hi, can i use this?

That looks like a low power diode. You want you diode to be able to handle at least 0.5 amps.

KiranR3 (author)2015-06-28

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

The coding would be basically the same. You just need multiple variables for the different appliance codes.

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?

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

cyubahirokevin (author)2016-01-26

IN CIRCCUIT above if i want to add more appliance to be controlled by my remote but but with different buttons of remote what to do?

If you want to set up multiple appliances, you need to set up multiple variables to store the different IR code values. If you have a lot of appiances, I would recommend not using a programming button to store the signal values, but instead hard coding the values for each button on the remote.

can u provide programming to to set up multiple appliances..........

Athajanja Babaubaya (author)2016-01-09

It seems difficult for me to replace the switches with the remote controlled circuit, please can you show me a simple circuit that controls a curtain using remote control circuit described above. This is my college project, i designed a manual circuit and am failing to replace with a remote control circuit on the manual switches. please help me with your circuit to control curtain using a remote. thanks in advance.

Any time that you are having trouble with a project, the best thing to do is to break it down into steps. Your first step was getting it to work with manual switches. Next, set it up with relays so that the switch on the relay replaces the manual switch. Then once you are able to control the system with relays, then hook the relays up to an Arduino so that the Arduino controls the relays. Then once you have that working, you can connect the IR sensor and add the code for the IR receiver that I use in this project. This will allow you to control it with a remote.

Build everything one step at a time and get each subsection working before adding more.

The lecturer requires us not to use the micro controller

If you can't use a microcontroller, that makes it a little more difficult. In that case, my best suggestion would be to use two separate IR receivers to control the opening and closing. Put one receiver on the one side of the window and put the other receiver on the opposite side. Connect these to a transistor H-bridge.

For more information check out this article:

The transistors can act like switches. When the receiver detects a signal from the remote, it will activate two of the transistors and cause the motor to turn one way. Then you put the remote at the other receiver, it will activate the other two transistors and the motor will turn the opposite way.

Just remember to set it up so that you don't accidentally activate both receivers at the same time.

Robin844 (author)2016-01-11

Good day, I would like to ask if it is possible to create a TV remote out from an arduino?

Of course. Check out this project:

The author of the IRRemote library set up everything for working with remotes and arduinos.

Athajanja Babaubaya (author)2016-01-08

I need to control my curtain using a TV remote, I have a simple circuit that uses switches . I need to replace manual switch with a remote controlled switch. Suggest for me what do please

You could just use the circuit described in this Instructable and connect it to the switch with relays.

Thanks alot brother but still have a problem because my circuit has two switches, one switch turns the motor clockwise and the other switch turns the motor anticlockwise to control the curtain. So which switch should be replaced with the remote controlled circuit, or i request to suggest a circuit to control a curtain by a remote. Thanks in advance

This circuit is able to control multiple relays (each with a different signal). So use two relays. One relay will replace each switch. You will just have to adjust the code so that you have two IR signals.

kazim72 (author)2015-10-15

that was so cool and easy project for arduino beginners....

I am glad you liked it. I have a number of other beginner level Arduino projects that you can check out if you are interested.

arjiecarolino (author)2015-08-08

Sir Good day! Can i use any TV or DVD remote Control? Tnx in advance :)

Any system with a standard IR protocol should work.

yaser ha (author)2015-07-31

can i add more ? how can i do this?

About This Instructable




Bio: My name is Jason Poel Smith I am a Community Manager here at Instructables. In my free time, I am an Inventor, Maker, Hacker, Tinker ... More »
More by DIY Hacks and How Tos:36 Things to Cook in a Coffee MakerHow to Make a Festivus PoleAdd Wings to an Infant's Halloween Costume
Add instructable to: