const int TVpin = 3;
char byteIn;
const int power[] = {224, 224, 64, 191};
const int vol_up[] = {224, 224, 224, 31};
const int vol_down[] = {224, 224, 208, 47};
const int ch_up[] = {224, 224, 72, 183};
const int ch_down[] = {224, 224, 8, 247};
const int tv_menu[] = {224, 224, 88, 167};
const int LEADER_PULSE=4400;
const int PERIOD=26;
const int WAIT_TIME=11;
const int PULSE_BIT=600;
const int PULSE_ONE=1600;
const int PULSE_ZERO=500;
void blastON(const int time, const int pin) {
int scratch = time;
while(scratch > PERIOD)
{
digitalWrite(pin, HIGH);
delayMicroseconds(WAIT_TIME);
digitalWrite(pin, LOW);
delayMicroseconds(WAIT_TIME);
scratch = scratch - PERIOD;
}
}
void blastOFF(int time) {
delayMicroseconds(time);
}
void blastByte(const int code, const int pin) {
int i;
for(i = 7; i > -1; i--)
{
if(1 << i & code) //check if the significant bit is 1
{
blastON(PULSE_BIT, pin);
//Serial.print("1");
blastOFF(PULSE_ONE);
}
else
{
blastON(PULSE_BIT, pin);
//Serial.print("0");
blastOFF(PULSE_ZERO);
}
}
//Serial.print("\n");
}
void command(const int irCode[], const int pin)
{
int i;
blastON(LEADER_PULSE-200, pin);
blastOFF(LEADER_PULSE);
for(i = 0; i < 4; i++)
{
blastByte(irCode[i], pin);
}
blastON(PULSE_BIT,pin);
//blastOFF(LEADER_PULSE);
delay(47);
}
void setup() {
Serial.begin(9600);
Serial.print("Welcome to Arduino. Enjoy your stay.\n");
Serial.print("Poor Man's Remote: Menu\n1) TV Power\n2) TV Volume Up\n3) TV Volume Down\n4) TV Channel Up\n5) TV Channel Down\n6) TV Menu\n");
pinMode(TVpin, OUTPUT);
}
void loop() {
while( Serial.available() > 0)
{
byteIn = Serial.read();
switch(byteIn)
{
case '1':
Serial.print("Sending TV Power...\n");
for(int i = 0; i < 4; i++)
{
command(power, TVpin);
}
Serial.print("Sent.\n");
break;
case '2':
Serial.print("Sending TV Volume Up...\n");
for(int i = 0; i < 4; i++)
{
command(vol_up, TVpin);
}
Serial.print("Sent.\n");
break;
case '3':
Serial.print("Sending TV Volume Down...\n");
command(vol_down, TVpin);
Serial.print("Sent.\n");
break;
case '4':
Serial.print("Sending TV Channel Up...\n");
command(ch_up, TVpin);
Serial.print("Sent.\n");
break;
case '5':
Serial.print("Sending TV Channel Down...\n");
command(ch_down, TVpin);
Serial.print("Sent.\n");
break;
case '6':
Serial.print("Sending TV Menu...\n");
command(tv_menu, TVpin);
Serial.print("Sent.\n");
break;
default:
Serial.print("Hey! Listen to directions, idiot.\n");
}
Serial.print("Poor Man's Remote: Menu\n1) TV Power\n2) TV Volume Up\n3) TV Volume Down\n4) TV Channel Up\n5) TV Channel Down\n6) TV Menu\n");
}
}
All credit for this sketch comes from this thread:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1270451288
I just figured out what he did and replicated it.
Okay so I'm going to try and explain this:
This is the Power Command for a Samsung tv:
0000 006d 0022 0003 00a9 00a8 0015 003f 0015 003f 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 003f 0015 003f 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0040 0015 0015 0015 003f 0015 003f 0015 003f 0015 003f 0015 003f 0015 003f 0015 0702 00a9 00a8 0015 0015 0015 0e6e
0000 006d 0022 0003 00a9 00a8 This is the header for "learned" IR commands, the lead in bit, the frequency and all of that other stuff.
0015 003f this is a bit for a "1"
0015 0015 this is a bit for a "0"
0015 0702 00a9 00a8 0015 0015 0015 0e6e this is the rest of the header, leadin, lead out, etc stuff.
All you need (according to that sketch I found (and edited) all you need is the 1's and 0's from the 0015 003f and 0015 0015 bits. So for example the power command I showed you earlier would convert to binary like this:
11100000111000000100000010111111
You convert this binary number into decimal (I use http://home2.paulschou.net/tools/xlate/) and you get this number:
224 224 64 191
Which is our power command.
An easy way that I've found to do the hex codes to binary is copy them all in wordpad, separate the leadin headers, search for 0015 0015 and replace them with 0's, search for 0015 003f and replace them with 1's, finally replace " " (space) with "" (nothing) and you should end up with a binary number with no spaces. Put that binary number in the site and click convert, copy down the dec numbers, plug them into the sketch and you're done.
Video of it working:
Thank you for all of your help. I know this works for Samsung but is there any way to make a truly universal remote? Should I make a library?