Go Down

Topic: Interfacing Arduino with a IR to Linux (lirc) (Read 6817 times) previous topic - next topic


This is probably more of a question for a linux forum but they will probably say I need to post it in the arduino form, so here goes.

I've got IRremote working great on the arduino with a TSOP1138

I press a button on the remote and it prints out the hex key value. Fantastic.

Now I would to get this working under linux with lirc. Has anyone done this before and can point me in the right direction? Ive read up tons on lirc but cant seem to get it working.


What do you wanna achieve? Connecting the arduino to the linux box and send the received commands via the serial line? Or do you wanna use the remote to directly send the command to the linux box. If the later is true, where goes the Arduino into that equation so that you have to ask in this forum? I use remotes with both the Arduino and my linux boxes but both are quite separate things.

If you wanna use your Arduino as the IR device on linux, be prepared to do a bit more than just configuring LIRC. Probably the easiest way is to get an Arduino Leonardo and program it to emulate a keyboard, sending the keystrokes you like if the appropriate signals from the remote are received.


Thanks for the reply - I want to use the Arduino as the IR device under Linux.


If you must do it by lirc and the HID keyboard option I described is not a viable option, you may go one of two ways:

1. Send the received data by the standard serial interface to the PC and write a custom LIRC driver to receive that. (easy on the Arduino side, a bit more complex on the Linux side)

2. Emulate the behaviour of a device with an already existing driver for LIRC. (quite difficult on the Arduino side, no programming needed on the Linux side)

Which way you choose depends on your programming skills. If you're more experienced on the Linux side, write a new driver for LIRC. If you're experienced in Arduino, search for an easy to emulate device in the list of supported devices and get your Arduino doing like it.


So I finally found a solution that works. So I'm putting it here if anyone else need help fixing it.

Which basically says use irrecord -f -d /dev/lirc0 ~/test.conf in LIRC to decode the signal.
The use this script to convert the found data to a compatible format and then input it into your Arduino code.

Code: [Select]
$f = file("pmp2.lirc");
$mode = -1;
foreach ($f as $ff) {
$ff = trim(albosluklari($ff));
$ff = explode(" ",$ff);
switch ($mode) {
case -1:
if ($ff[0] == 'begin' && $ff[1] == 'raw_codes') {
case 0:
if ($ff[0] == 'name') {
$key = $ff[1];
} else {
foreach ($ff as $number) {
if (strlen($number)==0) continue;
if (!is_numeric($number)) continue;
$sequence[$key][] = $number;

foreach ($sequence as $key=>$seq) {
echo "prog_uint16_t cmd_".$key."[] PROGMEM = {\n";
$str  = "";
$cnt = 0;
foreach ($seq as $number) {
if ($cnt++%6==0) $str.="\n\t";
$str.= $number.", ";
$str = substr($str,0,-2);
echo $str."\n";
echo "};\n\n";

function albosluklari($str) {
$a = 1;
while ($a>0) {
$str = str_replace("  "," ",$str,$a);
return $str;

Go Up