How to Control Your TV With an Arduino!
by Wally_Z in Circuits > Arduino
373032 Views, 260 Favorites, 0 Comments
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. http://www.ladyada.net/learn/sensors/ir.html
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.
IF YOU DO ANYTHING ILLEGAL WITH THIS CODE I WILL NOT BE HELD RESPONSIBLE (which I think is probably not a problem).
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. http://www.ladyada.net/learn/sensors/ir.html
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.
IF YOU DO ANYTHING ILLEGAL WITH THIS CODE I WILL NOT BE HELD RESPONSIBLE (which I think is probably not a problem).
Preparing to Receive Signals
First you want to get the IR LED Receiver mentioned in the introduction.
You can get one here: http://www.adafruit.com/products/157
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!
You can get one here: http://www.adafruit.com/products/157
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!
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
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
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:
delayMicroseconds();
pulseIR();
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.
Example:
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:
delayMicroseconds(1660);
pulseIR(580);
delayMicroseconds(1640);
pulseIR(560);
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.
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:
delayMicroseconds();
pulseIR();
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.
Example:
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:
delayMicroseconds(1660);
pulseIR(580);
delayMicroseconds(1640);
pulseIR(560);
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.
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:
Received:
OFF ON
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);
Serial.begin(9600);
}
void loop()
{
SendChannelUpCode();
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
delayMicroseconds(820);
pulseIR(300);
delayMicroseconds(1580);
pulseIR(320);
delayMicroseconds(640);
pulseIR(240);
delayMicroseconds(1280);
pulseIR(240);
delayMicroseconds(1240);
pulseIR(240);
delayMicroseconds(1120);
pulseIR(240);
delayMicroseconds(2600);
pulseIR(240);
delayMicroseconds(12740);
pulseIR(240);
delayMicroseconds(840);
pulseIR(240);
delayMicroseconds(980);
pulseIR(240);
delayMicroseconds(700);
pulseIR(240);
delayMicroseconds(700);
pulseIR(240);
delayMicroseconds(720);
pulseIR(240);
delayMicroseconds(2460);
pulseIR(240);
delayMicroseconds(700);
pulseIR(240);
delayMicroseconds(700);
pulseIR(240);
delayMicroseconds(14904);
pulseIR(240);
delayMicroseconds(820);
pulseIR(240);
delayMicroseconds(1600);
pulseIR(240);
delayMicroseconds(700);
pulseIR(260);
delayMicroseconds(2740);
pulseIR(240);
delayMicroseconds(1240);
pulseIR(240);
delayMicroseconds(1260);
pulseIR(240);
delayMicroseconds(1100);
pulseIR(240);
delayMicroseconds(2620);
pulseIR(240);
delayMicroseconds(12720);
pulseIR(260);
delayMicroseconds(840);
pulseIR(220);
delayMicroseconds(2080);
pulseIR(240);
delayMicroseconds(1780);
pulseIR(260);
delayMicroseconds(700);
pulseIR(240);
delayMicroseconds(700);
pulseIR(240);
delayMicroseconds(2480);
pulseIR(240);
delayMicroseconds(700);
pulseIR(240);
delayMicroseconds(700);
pulseIR(240);
}
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:
Received:
OFF ON
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);
Serial.begin(9600);
}
void loop()
{
SendChannelUpCode();
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
delayMicroseconds(820);
pulseIR(300);
delayMicroseconds(1580);
pulseIR(320);
delayMicroseconds(640);
pulseIR(240);
delayMicroseconds(1280);
pulseIR(240);
delayMicroseconds(1240);
pulseIR(240);
delayMicroseconds(1120);
pulseIR(240);
delayMicroseconds(2600);
pulseIR(240);
delayMicroseconds(12740);
pulseIR(240);
delayMicroseconds(840);
pulseIR(240);
delayMicroseconds(980);
pulseIR(240);
delayMicroseconds(700);
pulseIR(240);
delayMicroseconds(700);
pulseIR(240);
delayMicroseconds(720);
pulseIR(240);
delayMicroseconds(2460);
pulseIR(240);
delayMicroseconds(700);
pulseIR(240);
delayMicroseconds(700);
pulseIR(240);
delayMicroseconds(14904);
pulseIR(240);
delayMicroseconds(820);
pulseIR(240);
delayMicroseconds(1600);
pulseIR(240);
delayMicroseconds(700);
pulseIR(260);
delayMicroseconds(2740);
pulseIR(240);
delayMicroseconds(1240);
pulseIR(240);
delayMicroseconds(1260);
pulseIR(240);
delayMicroseconds(1100);
pulseIR(240);
delayMicroseconds(2620);
pulseIR(240);
delayMicroseconds(12720);
pulseIR(260);
delayMicroseconds(840);
pulseIR(220);
delayMicroseconds(2080);
pulseIR(240);
delayMicroseconds(1780);
pulseIR(260);
delayMicroseconds(700);
pulseIR(240);
delayMicroseconds(700);
pulseIR(240);
delayMicroseconds(2480);
pulseIR(240);
delayMicroseconds(700);
pulseIR(240);
delayMicroseconds(700);
pulseIR(240);
}