Transforming Raspberry Pi Into a Remote Control





Introduction: Transforming Raspberry Pi Into a Remote Control

In the era of Internet of Things (IoT) old electronic devices are outdated. In this tutorial you will learn how to bring back life to them using Raspberry Pi and the $9 add-on board from the IndieGoGo crowdfunding campaing of ANAVI Infrared pHAT.

This tutorial provides a video and step by step instructions for scanning remote control and sending IR commands from your Raspberry Pi using the free and open source software LIRC. In this particular case I am going to control my 20-year-old SONY GR7 mini HiFi system. you may use the same approach for any other HiFi system or TV.

Please note that remote controls of the air conditioners are more complex and will be covered in another tutorial. Subscribe to my YouTube channel to make sure you will not miss it.

ANAVI Infrared pHAT is an open source hardware add-on board compatible with all models and versions of Raspberry Pi with 40 pin header, including Raspberry Pi Zero, Zero W, 3, 2, B+ and A+.

Step 1: Getting Ready

For this tutorial you need the following hardware components:

  • ANAVI Infrared pHAT
  • Raspberry Pi (any model or version with 40 pin headers such Zero, Zero W, B+, 2 or 3)
  • microSD card with Raspian GNU/Linux distribution
  • USB power supply

Step 2: Assembling the Hardware

Getting started with ANAVI Infrared pHAT is super easy. You just need to plug it on top of the 40 pin header of your Raspberry Pi. It is like a child's play.

After that plug the microSD card with the Raspbian GNU/Linux distribution and turn on your Raspberry Pi.

Step 3: Installing the Software

Open a terminal on your Raspberry or just login via SSH and perform the following steps to enable the infrared receiver and transmitter:

  • Install LIRC
sudo apt-get update
sudo apt-get install -y lirc 
  • Edit /etc/modules and add the IR pins by adding the following line to the end of the file:
lirc_rpi gpio_in_pin=18 gpio_out_pin=17 
  • Configure /etc/lirc/hardware.conf in a way to match:
# /etc/lirc/hardware.conf
# Arguments which will be used when launching lircd

#Don't start lircmd even if there seems to be a good config file

#Don't start irexec, even if a good config file seems to exist.

#Try to load appropriate kernel modules

# Run "lircd --driver=help" for a list of supported drivers.

# usually /dev/lirc0 is the correct setting for systems using udev

# Default configuration files for your hardware if any
  • Edit /boot/config.txt and configure kernel extensions by adding the following line to the end of the file:
  • Reboot Raspberry Pi:
sudo shutdown -r 0

Step 4: Scanning the Remote Control

Follow the steps below to create LIRC configuration file and test the infrared transmitter:

  • Stop LIRC systemd service:
sudo systemctl stop lirc
  • List all available names for buttons supported by LIRC:
irrecord --list-namespace
  • Type in the following command to create new LIRC control configuration file and follow the on screen instructions to scan a remote control:
irrecord -d /dev/lirc0 ~/lircd.conf

Example configuration output:

Now enter the names for the buttons.

Please enter the name for the next button (press <ENTER> to finish recording)

Now hold down button "KEY_POWER".

Please enter the name for the next button (press <ENTER> to finish recording)

Now hold down button "KEY_VOLUMEUP".

Please enter the name for the next button (press <ENTER> to finish recording)

Now hold down button "KEY_VOLUMEDOWN".

Please enter the name for the next button (press <ENTER> to finish recording)

Successfully written config file.
  • Backup the original LIRC configuration file:
sudo mv /etc/lirc/lircd.conf /etc/lirc/lircd-backup.conf
  • Load the new configuration file:
sudo mv ~/lircd.conf /etc/lirc/lircd.conf
  • Launch LIRC systemd service again:
sudo systemctl start lirc

Step 5: Sending IR Commands

Point the infrared transmitters on the ANAVI Infrared pHAT to the consumer electronic device and send commands using LIRC. In my case I can turn on and off my old SONY GR7 mini Hi-Fi system with the following command:

irsend SEND_ONCE /home/pi/lircd.conf KEY_POWER



    • Pocket-Sized Contest

      Pocket-Sized Contest
    • Pro Tips Challenge

      Pro Tips Challenge
    • Paper Contest 2018

      Paper Contest 2018

    We have a be nice policy.
    Please be positive and constructive.




    I am running Raspbian Stretch with Desktop (kernel version 4.9) on a Raspberry Pi 3. and ANAVI Infrared pHAT IR board. I followed the steps as in this how-to. Created a hardware.conf as this was missing . But when I tried recording a panasonic aircon remote, it failed to create .conf file and seemed to hung in irrecord after two lines of dots of button presses.

    Any help on this?

    pi@raspberrypi:~ $ sudo irrecord -d /dev/lirc0 ~/lircd.conf
    Running as regular user pi
    Using driver default on device /dev/lirc0

    irrecord - application for recording IR-codes ----
    Press RETURN to continue.

    Checking for ambient light creating too much disturbances.
    Please don't press any buttons, just wait a few seconds...

    No significant noise (received 0 bytes)

    Enter name of remote (only ascii, no spaces) :panasonicir
    Using panasonicir.lircd.conf as output filename

    Now start pressing buttons on your remote control.

    It is very important that you press many different buttons randomly
    and hold them down for approximately one second. Each button should
    generate at least one dot but never more than ten dots of output.
    Don't stop pressing buttons until two lines of dots (2x80) have
    been generated.

    Press RETURN now to start recording.
    Got gap (78301 us)}

    Please keep on pressing buttons like described above.

    A few additional steps are required for Raspbian Strech. Please refer to the user's manual for details:

    The remote controls for air conditioning are far more complex compared to those for TVs. After configuring LIRC on Stretch from the latest user's manual, please follow the steps in this tutorial by cnx-software to scan the remote control for air conditioning:

    Hi Leon-anavi, Thank you very much. I am now able to control the Panasonic aircon with anavi infrared phat on a raspberry pi board :-) by following the steps in the tutorial link that you just gave. Then, I had to update the lircd.conf file with the gap value that I had obtained in the past using irrecord (see my log posted earlier). The gap value was 78301 us.
    Just a side note, for the latest Raspbian Stretch, it didn't require to update /etc/modules and /etc/lirc/hardware.conf mentioned in the user manual.

    I got a proof of concept with a few buttons controlled through a webpage working with one change: irrecord only worked by recording raw format. When using the suggested command irrecord hangs and I had to use Ctrl-C to get out. It worked fine using (notice the additional -f):

    irrecord -f -d /dev/lirc0 ~/lircd.conf

    Now I am really stoked and ready to record all buttons of the remote but it seems like the infrared receiver has gone haywire. When using irrecord it keeps complaining about the noise while I am recording in the same circumstances as before. I also switched to different rooms, switched out RPi's but nothing seems to work anymore. When running

    mode2 -m -d /dev/lirc0

    to monitor the input on the infrared receiver I get a constant stream of spaces and pulses of random length without pointing any remote at it. Covering up the receiver doesn't interrupt this stream either.

    Sending commands through the transmitters still works fine.

    Any suggestions to check further or do I have a faulty pHAT here?

    Hi Fred, I have sent you details over email earlier today. Please follow the instructions from the email and the latest version of the user's manual: