How to build a simple but cool IR (Infra Red) receiver.

The software for Linux: Lirc

If you have a Linux box Lirc is the software you want to install. It's rathar easy to setup, the following instructions will give some hints.
[-] First download the software from the lirc website. I strongly recommend not to use any .deb or .rpm package as they tend to make everything more complicated.
Go to the Lirc page and download the most recent package. Untar it with the command:

tar jxvf lirc-0.6.6.tar.bz2

and start the semi-graphical setup:

./setup



Setup window of Lirc

You should only select your serial port and leave all the other settings. Select the 3rd menu entry, "Save configuration and run configure", wait until it has finished, then give (as root):

make
make install

[-] Once Lirc is compiled and installed, set the serial port, load the lirc kernel module, and start the lirc daemon (lircd):

setserial /dev/ttySx uart none
depmod -a
modprobe lirc_serial
lircd

If everything has gone well, we can test the actual receiving hardware. Take a remote control and start the "xmode2" program (if you don't use X start the character application, "mode2"); press then some buttons on the remote. You should see something like this:

Graphical representation of the IR pulses

Alternatively, if you are using the character version of this program, you should see a list of numbers, spaces, and pulses. What is this all about? It's the graphical representation of the IR pulses, a sort of IR oscilloscope. If you can see the pulses when you press the remote control buttons, you can be sure the hardware is almost basically working. Each button should generate a different "wave" from the others, but always the same if you press it more times.
[-] It's now time to configure your remote(s), that is, give a "name" to each button:

irrecord /etc/lircd.conf

The programm will ask you to press the buttons on you remote control, first in a random fashion and then one by one, asking each time the name of the button you're now configuring. If you have any problem in this step, for example you get a "Something went wrong" message, try to use the raw learning mode, starting irrecord with the "-f" option:

irrecord -f /etc/lircd.conf

You can repeat this step many times, for many remote controls. The name you give to each button is important, because the applications will later receive ths name as the even from the lirc daemon. Once the learning phase it's finished, you can test your configuration with "irw". You have first to restart lircd to let it read the new configuration file. After this, run "irw" and press the buttons on your remote: irw will show the *name* of each button when it's pressed.
[-] You can now configure the application level of the lirc system. Basically with lirc you can do the following things: The first approach is the simplest. It allows you to run a program when a button of the remote is pressed. The configuration is done with the ~/.lircrc file:
begin
	remote = <your remote>
	button = <your button>
	prog   = irexec
	repeat = 0
	config = /usr/local/bin/mozilla -mail
end
This example shows how to start the mozilla mail program when you press a button on your remote. The second approach, the use of lirc clients, is an extension of this methodology; in the latter example we can see the line "prog = irexec". "irexec" is a particular lirc client that is used to run programs or commands. There are many other lirc clients: for example, MPlayer or VDR. The first uses the traditional ~/.lircrc setup, the second uses an interactive configuration. Let's talk about MPlayer; we can set several entries in the ~/.lirrc file each for every command we want to give to MPlayer. Take a look at the next example:
begin
     button = VOLUME_PLUS
     prog = mplayer
     config = volume 1
     repeat = 1
end

begin
    button = VOLUME_MINUS
    prog = mplayer
    config = volume -1
    repeat = 1
end

begin
    button = RIGHT_ARROW
    prog = mplayer
    config = seek 30 0
    repeat = 1
end

begin
    button = LEFT_ARROW
    prog = mplayer
    config = seek -30 0
    repeat = 1
end

begin
    button = PAUSE
    prog = mplayer
    config = pause
    repeat = 0
end
The first section controls the volume: the "prog" line is set to mplayer; the "config" line is the message that is sent to the mplayer program. In this case we tell mplayer to increase the volume by 1 unit. The "repeat" line is set to 1, so the message will be sent multiple times if the button is kept pressed. The following sections are similar, decrease the volume ("volume -1"), seek by 30 seconds, and the pause functrion. Note the pause function has "repeat" set to 0, because it doesn't make sense to continuosly switch between pause and play mode when we keep that button pressed! For a complete list of the commands, see the mplayer documentation.
The third approach is very interesting and you will be able to set a new pointer in your X11 or gpm configuration; lirc mouse emulation supports even the mouse wheel used to scroll documents! Follow the lircmd instructions for a detailed setup.
The fourth mode is quite technical and I redirect you to the relevant section of the lirc documentation: irpty allows you to feed programs with keystrokes depending on which button you pressed on the remote. irxevent sends mouse clicks and key presses (in other words, X11 events) to X applications.