In the Arduino kit that I bought not long ago were an IR remote control and an IR receiver included. And I have found a really good library for Arduino that makes decoding the IR signals from the remote control really easy. So I have used this library and coded a short program to my Arduino card that reads the IR signals and then sends more logical signals to the computer through the USB cable.
Here is a link to the page where I found the library: http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
Here is code that I have written for my Arduino board:
#include <IRremote.h>
int RECV_PIN = 11;
String in;
String cur = "";
String cur2 = "";
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
in = String(int(results.value), HEX);
irrecv.resume(); // Receive the next value
cur2 = "";
if (in != "ffff") {
if (in == "a25d") { // ON/OFF
cur = "11";
}
else if (in == "629d") { // Mode
cur = "12";
}
else if (in == "e21d") { // Sound ON/OFF
cur = "13";
}
else if (in == "22dd") { // Play/Pause
cur = "21";
}
else if (in == "2fd") { // Back
cur = "22";
}
else if (in == "c23d") { // Forward
cur = "23";
}
else if (in == "e01f") { // EQ
cur = "31";
}
else if (in == "a857") { // VOL-
cur = "32";
}
else if (in == "906f") { // VOL+
cur = "33";
}
else if (in == "6897") { // 0
cur = "41";
}
else if (in == "9867") { // RPT
cur = "42";
}
else if (in == "b04f") { // U/SD
cur = "43";
}
else if (in == "30cf") { // 1
cur = "51";
}
else if (in == "18e7") { // 2
cur = "52";
}
else if (in == "7a85") { // 3
cur = "53";
}
else if (in == "10ef") { // 4
cur = "61";
}
else if (in == "38c7") { // 5
cur = "62";
}
else if (in == "5aa5") { // 6
cur = "63";
}
else if (in == "42bd") { // 7
cur = "71";
}
else if (in == "4ab5") { // 8
cur = "72";
}
else if (in == "52ad") { // 9
cur = "73";
}
}
if (in == "ffff") { // Presses down a button
Serial.println(cur + "d");
} else if (cur.length() == 2) {
Serial.println(cur + "0");
}
}
delay(100);
}
I’m not sure if this program is so easy to understand, but I hope that it’s at least little help if you are setting up your own program for reading IR signals (and later controlling your computer).
Basically will the loop decode a signal, convert it to HEX and then check what button was pressed down. If I press a button on my remote control it will send a normal, unique signal (which in hex is something like a25d or 629d). But if I keep it pressed down it will keep on sending ffff signals, regardless of what button is kept pressed down. Therefore I have to save what button that was initially pressed down, which I do in cur.
The normal signals will result in numbers like 11, 12, 33 and 72 are saved as cur, and behind that is a really simple system. The first digit is the button row of the remote control, and the second digit is the the column. So as you may understand, I have 3 x 7 buttons on my remote control.
Before sending the number 22, 33, or something similar, to the computer, is 0 added to the end if the button was just pressed down or d if it already was pressed down in the previous loop.
So if press the button on my remote control that says 8 (row 7, column 2) the program will in the first run through send the message 720 to the computer. If I keep it pressed down will the program keep on sending 72d to the computer. If I bring up the Serial Monitor in the Arduino software will the output be:
720
72d
72d
72d
72d
72d
72d
72d
I apologize for my crappy English. ^.^