Introduction: How to Control Your TV With an Arduino!

Picture of How to Control Your TV With an Arduino!

So. This Instructable will show you how to control anything controllable by IR, or Infrared light.

This includes cameras, TV's, DVD players, VCR's, you get the point.

I will be showing you how to receive the codes, and then how to transmit them.

Objects required for this project:
1x Arduino (any kind as long as it has whats called "PWM" which I will explain)
1x IR LED (you can get these from any TV remote)
1x IR reciever (see picture)
1x USB A to B wire for programming the Arduino
1x Computer to program the Arduino with
1x Arduino software
and the .PDE files I will include

This website really helped me out a lot with this.

THIS IS NOT MY CODE, I DO NOT CLAIM OWNERSHIP. I merely copied and pasted the code and rewrote the instructions to make this easy to understand. 


Step 1: Preparing to Receive Signals

Picture of Preparing to Receive Signals

First you want to get the IR LED Receiver mentioned in the introduction.

You can get one here:
They cost $2 not including shipping and handling.

So you want to hook up the receiver according to the first picture.

I highly suggest putting both the IR Receiver and the remote in a shoe box or something that is dark (the same shoe  box of course). This will insure there will be the least amount of interference and to have clearer code so you don't have to program your Arduino 12 times for one simple task. Also, make sure you are out of the way of people watching TV.

And you want to download the file named IR_RECORD.PDE and open it into the Arduino program.

Plug your Arduino in with the USB cable I hope you have and proceed to step 2!

Step 2: Receiving the Signals

Picture of Receiving the Signals

So you want to upload the program to your Arduino you downloaded in the last step.

And you want to have the IR Receiver hooked up properly. 

Once everything is setup properly, and the Arduino is on and hooked up to the computer. Open up serial monitor by clicking on the button in the Arduino program that is the button circled in the picture.

Once that is up and running. You need to find a remote that you want to be able to use to control something with. What I mean by that is:

-find the remote for whatever you want to control
-point it at the reciever
-press the button you want to get the code for ONE TIME
-watch the Serial Monitor
-paste the entire code into notepad or wordpad
-proceed to step 3

Step 3: Interpreting the Signals

Picture of Interpreting the Signals

You will get a bunch of numbers followed by "usecs" or "usec".
Make sure you have copied the signal you want into a word pad for easier reference.

It will look something like this:
500 usec, 300 usec
600 usec, 1200 usec

But there will be a lot more numbers than that.

Now in the program you will see this quite a few times:

You want to take the first number and put it in the parentheses in delayMicroseconds("here"); value
And you want to take the second number from the same line as the one of the delayMicroseconds(); value and put it in the parentheses of pulseIR(); value. 


Say you get this on the serial monitor:
       OFF              ON
  1660 usec, 580 usec
  1640 usec, 560 usec

You want to put the corresponding values in their corresponding areas.
Such as:


It is pretty damn easy.

Once you get the codes you want, open the IR_SEND.pde file in the Arduino program and then put the values that you got from the serial monitor between the parentheses doing it the same way I showed you how to do it.

The next step will show an example of how I did this with a Comcast remote. 

Step 4: Sending the Signals

Picture of Sending the Signals

Now once you have the codes that you want, and have uploaded the program with the signal you want to send, all you have to do is hook up the IR LED to pin 13 and then to ground similar to the schematic in the picture. You don't need the resistor if you have a Duemilanove Arduino because it has a built in resistor for PIN 13 so you don't have to worry.

This can also be done with an ATTINY 8 pin microcontroller to cut down on size. I have one but I'm not sure how to use it yet.

Now I will be showing you a real-world example on how to do this.

AGAIN, THIS IS NOT MY CODE, I just copied and pasted to make it easier to understand.

So I got this code when I pressed the channel up button on my Comcast remote. This is the kind of remote that you will have if you have the small black boxes that use the small black remotes. They act as an analog to digital converter box that only can change channels.

Here is the Serial Monitor code:

36328 usec, 280 usec
820 usec, 300 usec
1580 usec, 320 usec
640 usec, 240 usec
2740 usec, 240 usec
1280 usec, 240 usec
1240 usec, 240 usec
1120 usec, 240 usec
2600 usec, 240 usec
12740 usec, 240 usec
840 usec, 240 usec
980 usec, 240 usec
700 usec, 240 usec
700 usec, 240 usec
720 usec, 240 usec
2460 usec, 260 usec
700 usec, 240 usec
700 usec, 240 usec
14904 usec, 260 usec
820 usec, 240 usec
1660 usec, 240 usec
700 usec, 260 usec
2740 usec, 240 usec
1240 usec, 240 usec
1260 usec, 240 usec
1100 usec, 240 usec
2620 usec, 240 usec
12720 usec, 260 usec
840 usec, 220 usec
2080 usec, 240 usec
1780 usec, 260 usec
700 usec, 240 usec
700 usec, 240 usec
2480 usec, 240 usec
700 usec, 240 usec
700 usec, 240 usec

Here is the code that I made from the raw data by putting the code in: 

// This sketch will change the channel every ten seconds so you can be doing other things
//while watching tv and not having to change the channel, like being on a laptop and having
//it cycle through the channels so you have free hands.
//We all know pressing a button is so hard, so why not make it automated?
int IRledPin =  13;    // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

void setup()   {               
  // initialize the IR digital pin as an output:
  pinMode(IRledPin, OUTPUT);     


void loop()                    

  delay(20*1000);  // wait twenty seconds (20 seconds * 1000 milliseconds) Change this value for different intervals.

// This procedure sends a 38KHz pulse to the IRledPin
// for a certain # of microseconds. We'll use this whenever we need to send codes
void pulseIR(long microsecs) {
  // we'll count down from the number of microseconds we are told to wait

  cli();  // this turns off any background interrupts

  while (microsecs > 0) {
    // 38 kHz is about 13 microseconds high and 13 microseconds low
   digitalWrite(IRledPin, HIGH);  // this takes about 3 microseconds to happen
   delayMicroseconds(10);         // hang out for 10 microseconds
   digitalWrite(IRledPin, LOW);   // this also takes about 3 microseconds
   delayMicroseconds(10);         // hang out for 10 microseconds

   // so 26 microseconds altogether
   microsecs -= 26;

  sei();  // this turns them back on

void SendChannelUpCode() {
  // This is the code for the CHANNEL + for the TV COMCAST
  delayMicroseconds(36328);      //Time off (LEFT column)       
  pulseIR(280);                               //Time on (RIGHT column)    <-------DO NOT MIX THESE UP


matt.e.jenkins (author)2011-12-15

You can get the IR Receiver from just about any old VCR, TV, DVD player, anything that had a normal IR remote. I have a hand full of those sensors that I took from all the old broken devices i have laying around. Thanks for the tutorial.

Wally_Z (author)matt.e.jenkins2011-12-15

You're welcome! Show this to your friends and see what they make!

bonnom (author)2015-12-30

I wrote a script in python to convert the output of the arduino into the delayMicroseconds en pulseIR code.
you have to rename 'path\filename.txt' in your own code. :)
Hopefully The code gets printed correct

file_object = open('path\filename.txt','r')
for f in file_object:

f = f.replace("usec","")
f = f.replace(" ,",'')
f= f.split()
print ("delayMicroseconds("+f[0]+");")

Hexadecimat0r (author)bonnom2017-11-29

You're awesome man thanks

JamesD437 (author)bonnom2017-10-17

I know its had probably been a long time since you wrote this code, but when I run it, it only returns the last value of the text file with the proper formatting. Is there something I can add to this to make it parse each line?

Hexadecimat0r (author)JamesD4372017-11-29

The 2 print statements need to be indented so that they are also inside the for-loop so that they are printed once for each for-loop iteration

JackANDJude made it! (author)2017-10-30

Thanks for breaking it down. Works great! I'll shrink it to an attiny85 when I get my hands on a crystal.

sagaraute (author)2015-10-06

how to connect IR transmitter to arduino uno....

useph.ellail (author)sagaraute2017-06-07

PWM ARDUINO PIN to the resistor _ resistor to led Emitter _ EMITTER TO arduino GND

TomG186 (author)2017-04-23

Thanks for posting - works great. I have an old Sharp that does not work with the IRremote library, but this code works like a charm!

Gökhan Türkeli (author)2017-01-08

It didn't work for my air conditioner. I receive the code which is much longer than a typical TV remote but I cannot send it.

ACs have a very different set of protocols for communication. I have written an instructable just about that. You can check it out on my user page..

LuisL161 (author)2017-01-08

My arduino uno does not work anymore after uploading ir send sketch. It seems bootloader was override

steveraffner (author)2017-01-03

Hello - do you think an Arduino could "listen" to VCR tv codes and trigger the TV accordingly ? my project idea is here :

steveraffner (author)2017-01-03

Hello - do you think an Arduino could "listen" to VCR tv codes and trigger the TV accordingly ? my project idea is here :

Tvixen (author)2016-12-15

This will work:

shashankvadalia (author)2016-06-09

This method does not work

try the method on this link

KarlL14 (author)2016-05-10

That's great, thanks Wally. I'm making a TV remote floor rug for my friend who has cerebral palsy and has very limited movement. This is very helpfull.

OmarA132 (author)2016-03-26

hey there nice project i did every thing above but the ir remote numbers keep changing it does not stay the same is that a proplem from my ir reciver or it is from the ir remote

do i have to change the ir remote or what


OmarA132 (author)2016-03-26

hey there nice project i did every thing above but the ir remote numbers keep changing it does not stay the same is that a proplem from my ir reciver or it is from the ir remote

do i have to change the ir remote or what


S0All (author)2016-02-19

It did not work for me. I was able to get the "raw data" but it does not work. I assume the code should be the same every time but instead I get different raw data when I press the same button. The code to send the raw data does not work I guess.

IstvánM7 (author)2016-02-02

Hi there!

I went through this instructable but unfortunatelly, i couldn't manage to make it work.
I used an Arduino Mega instead of Uno. To be more specific:

-I connected the IRReceiver Out pin to Arduino Mega digital Pin 2 (and of course the other two as its shown the picture above).
-I downloaded the IR_RECIEVE.pde then I uploaded it to my Arduino Mega.
-I opened the Serial Monitor. It wrote "Ready to decode IR!".
-I pushed the on/off button on my remote, but nothing happened in the Serial monitor.

Any guess what can be wrong?

Thank you in advance!

Soumojit (author)IstvánM72016-02-15

Same with me

dj038 (author)2015-11-26

I cannot download your files :(

Your also talking about IR_RECORD.PDE which is nowhere to find :S

What do I do wrong

NickH59 (author)dj0382015-12-23


/* Raw IR decoder sketch!

This sketch/program uses the Arduno and a PNA4602 to

decode IR received. This can be used to make a IR receiver

(by looking for a particular code)

or transmitter (by pulsing an IR LED at ~38KHz for the

durations detected

Code is public domain, check out and

for more tutorials!


// We need to use the 'raw' pin reading methods

// because timing is very important here and the digitalRead()

// procedure is slower!

//uint8_t IRpin = 2;

// Digital pin #2 is the same as Pin D2 see

// for the 'raw' pin mapping

#define IRpin_PIN PIND

#define IRpin 2

// the maximum pulse we'll listen for - 65 milliseconds is a long time

#define MAXPULSE 65000

// what our timing resolution should be, larger is better

// as its more 'precise' - but too large and you wont get

// accurate timing

#define RESOLUTION 20

// we will store up to 100 pulse pairs (this is -a lot-)

uint16_t pulses[100][2]; // pair is high and low pulse

uint8_t currentpulse = 0; // index for pulses we're storing

void setup(void) {


Serial.println("Ready to decode IR!");


void loop(void) {

uint16_t highpulse, lowpulse; // temporary storage timing

highpulse = lowpulse = 0; // start out with no pulse length

// while (digitalRead(IRpin)) { // this is too slow!

while (IRpin_PIN & (1 << IRpin)) {

// pin is still HIGH

// count off another few microseconds



// If the pulse is too long, we 'timed out' - either nothing

// was received or the code is finished, so print what

// we've grabbed so far, and then reset

if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {






// we didn't time out so lets stash the reading

pulses[currentpulse][0] = highpulse;

// same as above

while (! (IRpin_PIN & _BV(IRpin))) {

// pin is still LOW



if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {






pulses[currentpulse][1] = lowpulse;

// we read one high-low pulse successfully, continue!



void printpulses(void) {

Serial.println("\n\r\n\rReceived: \n\rOFF \tON");

for (uint8_t i = 0; i < currentpulse; i++) {

Serial.print(pulses[i][0] * RESOLUTION, DEC);

Serial.print(" usec, ");

Serial.print(pulses[i][1] * RESOLUTION, DEC);

Serial.println(" usec");



NickH59 (author)2015-12-23

Pretty cool i made it to where you can go to the serial monitor and type a command like channel up or channel down and it will work accordingly

erika123500312 (author)2015-11-17

I lost the remote to my tv and I'm trying to make an arduino remote to replace it. Can I get the tv specific codes if I don't have the original remote?

here is a database of remote control codes for an old program called LIRC which could help you:

KéziaC (author)2015-09-11

hi can u give me a help?actualy, Im trying to send an code for a setup box, from an arduino uno, but even the exemplo in the sketch is not working, and im connecting the ir transmissor in pin -3 ... in my roject im trying to receive an code from a conroler and transmiting the same code to a setup box... all the things in my project works, until the transmissor shines when i look by a camera, but is not sending anything. i dont have idea what i can try anymore.

KéziaC (author)2015-09-11

hi can u give me a help?actualy, Im trying to send an code for a setup box, from an arduino uno, but even the exemplo in the sketch is not working, and im connecting the ir transmissor in pin -3 ... in my roject im trying to receive an code from a conroler and transmiting the same code to a setup box... all the things in my project works, until the transmissor shines when i look by a camera, but is not sending anything. i dont have idea what i can try anymore.

ErdemŞ (author)2015-08-06

Hi everyone ,

I am working on ir transmission protocols . I did my ir system for samsung smart tv . I am curios on are there any command to shuw down the television (it is not matter television on which state (on,off))

thank you

maitrteya (author)2015-07-24

Arduino: 1.6.6 Hourly Build 2015/07/21 05:42 (Windows 7), Board: "Arduino Uno"

D:\maitreya\Arduino\arduino-nightly\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.

This report would have more information with

"Show verbose output during compilation"

enabled in File > Preferences.

what is the meaning of this?

braytonlarson (author)2015-07-19

You should really add a schematic for step 4. I don't know what value resistor to use with an Arduino UNO...

tachyon0118 (author)2015-06-30

Never, ever, EVER copy and paste the same line (or 2 lines) of code multiple times in the same program. Any time you see that, big alarm bells should be going off in your head. What you want is a for loop that goes through an array of values. There are some really good beginning guides to programming out there if you're looking to get started.

Also, I believe the arduino library has a "tone" function which will auto-magically generate a square wave at a given frequency a little more robustly than what you have here.

gcharai (author)2015-06-15

i seem to get errors in ir_send code:

ir_send_test_2.ino: In function 'void SendChannelUpCode()':

ir_send_test_2.ino:199:11: error: too few arguments to function 'void pulseIR(long int)'

ir_send_test_2.ino:27:8: note: declared here

Error compiling.

MariusA2 (author)2015-05-25

Thanks for the code it works great. I'm using it on a TV which I use as an extra monitor for my computer.
I've added some code so when I turn on my PC (and the USB ports come on) it sends the "power on" signal and I also hooked up the on/off and change input (TV, HDMI, VGA, etc.) to two push buttons.

Any ideas how I could get the arduino to turn the TV off when the computer turns off just before the USB ports lose power?

bsmith164 (author)MariusA22015-06-07

how do i download the files

MariusA2 (author)bsmith1642015-06-13

On the first page of the tutorial there are two files, you should be able to click on them to download them.

Or you could right click and "open in new tab" then copy and paste the text into the adruino software.

bsmith164 (author)2015-06-07

how do i download the files

MariusA2 (author)2015-05-25

nathanael.beall.3 (author)2015-05-19

no code is coming in at all

akki5230 (author)2015-04-01

Hi. I am receiving 7 digit hexadecimal code when i press a button from a remote. What to do with it if i want to control with arduino?

pinodaleppo (author)2013-07-05

I did everything as detailed but my IR LED will not go off. I received the code from a sony camera remote. Got the usec lists and then put it onto the SEND sketch. But My IR LED swill not go off. I looked at it with the iphone camera and there is no light. I substituted it with an ordinary LED and it does ligth up. what am I doing wrong?

narunkumar (author)pinodaleppo2014-03-21

i think we can't see IR rays through iphone camera..see through any other.For me it works

DrSo (author)narunkumar2015-02-09

It has been a while, but it might be worth confirming that cameras usually have an infrared filter that dim or stop infrared rays.

NarWhaLs15 (author)pinodaleppo2014-03-12

Mine does the same thing; I'm not sure what's wrong.

yhdesai (author)2015-02-01


Aravs7 (author)2014-08-12

Does not work with my Sony soundbar and I get new codes everytime I click on button.

travis.wayne.315 (author)Aravs72014-12-19

With my Sansui TV remote I was reading the codes and I would get about 24 lines of code that repeated. but every time the first line was different. but it stayed within a range, 0 - 65000. So basically you call the function multiple times with different values. (in a FOR or WHILE loop) for me what worked was cycling up 0-65000 in increments of 1000 and then back down. If I just cycled through once going up the TV would turn on and then turn right back off. Which is why I needed both loops. Maybe this will help! :)

ThomasY1 (author)2014-12-10

Would there be a way to, instead of repeating the signal, but to use it to say, turn on a motor or something?

About This Instructable




Bio: I like to tinker with electronics. I like to mod, hack, and learn how something works by taking it apart.
More by Wally_Z:Industrial-Grade GoPro Rollbar MountArduino Police Lights (ATMega 2650 Version) **New Flash Patterns!**How to control your TV with an Arduino!
Add instructable to: