I am trying to figure out how to read IR codes of a TV remote, so I can build my own web-based remote using a Raspberry Pi 3 with IR receiver and IR transmitter. I see a ton of articles online but could not find an article that articulates a DIY tutorial on just this part.

Ultimately, I want to map all the buttons on a TV remote, and then build a web based interface used to transmit the user selected IR codes to control a TV.

I have a RPi3 (second gen) kit with some basic accessories like breadboard, resistors, and jumper wires. IR receiver and transmitter components are confusing to choose, depending on which article I am reading.


2 Answers 2


While answers which are mostly links are discouraged, IR is NOT simple enough to explain in a few paragraphs.

You seem well informed already acknowledging that each button has its own code. That is a little bit over simplified (depending on the "codes" being used), but you at least have a good grasp of it and what you want to do.

The Pi has a great IR package called LIRC (think Linux Infrared Remote Control) which has a lot of documentation.

This link is pretty much exactly what you are looking for and it sounds like you have already looked at quite a few ideas.

This was built using a Pi Zero, just a stripped down Pi. Using LIRC really makes it slick!


  • I have the latest version of Raspbian Stretch April 2019 work kernel 4.19. lirc-pi seems to be replaced by gpio-ir. Also irrecord is unable to detect my Sony remote's IR signals, even though mode2 is detecting the pulses and spaces just fine. I read somewhere that Sony remotes use 40 khz instead of 38 khz. Is this behind the issues I am running into?
    – Web User
    Jun 11, 2019 at 6:47
  • Any 36 khz receiver will receive 38 and 40 khz. And any 38 khz will receive 36 and 40 khz. Their frequency "selection" is quite broad. In the equipment I worked with our 38 khz receivers worked fine with 25 khz IR remotes. I have read that LIRC was either dropped or replaced. I have not worked with it for a while...
    – Wendall
    Jun 11, 2019 at 13:21

You can use lirc to achieve what you want. When you have installed it you can use its diagnose tool mode2 to get low level information about the signals that are received from the remote control.

Then you need a configuration file that maps the lirc pulses to the buttons of your remote control. On the internet there is a database with many config files for remote controls. If you cannot find yours you have to training your remote control by yourself with:

rpi ~$ sudo irrecord -n -d /dev/lirc0 ~/lircd.conf

Next step is to use irw to check which button of your remote control has what action (volume up/down etc.).

Finally you can use irexec to map a script to each button on the remote control that is executed when the button is pressed. Within this script you can send commands through a web based interface to control a TV.

For details how to do all this using a Raspberry Pi you can look at Raspberry Pi 3 lirc running/working.

If you are looking for an alternative to lirc you can use direct kernel support with gpio-ir. Look at /boot/overlay/README. There you will find:

Name:   gpio-ir
Info:   Use GPIO pin as rc-core style infrared receiver input. The rc-core-
        based gpio_ir_recv driver maps received keys directly to a
        /dev/input/event* device, all decoding is done by the kernel - LIRC is
        not required! The key mapping and other decoding parameters can be
        configured by "ir-keytable" tool.
Load:   dtoverlay=gpio-ir,<param>=<val>
Params: gpio_pin                Input pin number. Default is 18.

        gpio_pull               Desired pull-up/down state (off, down, up)
                                Default is "up".

        rc-map-name             Default rc keymap (can also be changed by
                                ir-keytable), defaults to "rc-rc6-mce"

Name:   gpio-ir-tx
Info:   Use GPIO pin as bit-banged infrared transmitter output.
        This is an alternative to "pwm-ir-tx". gpio-ir-tx doesn't require
        a PWM so it can be used together with onboard analog audio.
Load:   dtoverlay=gpio-ir-tx,<param>=<val>
Params: gpio_pin                Output GPIO (default 18)

        invert                  "1" = invert the output (make it active-low).
                                Default is "0" (active-high).
  • I want to train my remote, this feels like a good start. Is the wiring in the article you linked something that you followed or vouch for?
    – Web User
    Jun 5, 2019 at 15:14
  • @WebUser The wiring at Raspberry Pi 3 not lirc not running/working isn't mine. It's shown by the asker. I cannot say anything about it. I used a soldered IR receiver on a D/A audio HAT.
    – Ingo
    Jun 5, 2019 at 15:24
  • What are the alternative for LIRC on the Raspberry Pi? Glad to hear that different khz can be handled by the 38khz receiver.
    – Web User
    Jun 11, 2019 at 13:25
  • @WebUser I have updated my answer at the end.
    – Ingo
    Jun 12, 2019 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.