Transforming Raspberry Pi Into a Remote Control




Introduction: Transforming Raspberry Pi Into a Remote Control

About: Software engineer and open source enthusiast

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
Microcontroller Contest 2017

Participated in the
Microcontroller Contest 2017

1 Person Made This Project!


  • Furniture Contest

    Furniture Contest
  • Colors of the Rainbow Contest

    Colors of the Rainbow Contest
  • Home Decor Challenge

    Home Decor Challenge



Answer 6 weeks ago

yes, you can still use LIRC even if you don't have the original remote but you have to known the infrared keycodes of the original remote.


Reply 6 weeks ago

Thanks Leon for your prompt reply.
Another question is, which code? I found these types of codes (e.g. A54C) from pioneer and these codes (e.g. 0x00000000000038C7) from sourceforge/lirc-remote/...
My guess is that I need to figure out how to convert A54C into 0x0000..., correct? I'm pretty clueless when it comes to hex, octal, etc.. I think lirc numbers are hex, correct? And, I don't know what pioneer codes are. Any help?
Thanks again.


Reply 6 weeks ago

The prefix 0x just indicates that the number is being written in hex. A54C looks like a hex number so probably you need to adjust the formatting as per LIRC expectations in the configuration file (aka with the right prefix and so on).


Reply 6 weeks ago

Thanks Leon. I think I get it now. Pioneer's codes simply left off the leading 0x00...
I can't wait to get started with your pHat. I just hope I can figure out the correct codes (I can't find the exact model of my old remote). I suspect there will be a lot of trial and error on my part.
Thanks again for a great tool and your help.


Reply 5 weeks ago

Yes, with infrared code there is always trial and error cycles :) Please note that LIRC configurations have evolved over the years and up to date instructions are available at the user's manual for ANAVI Infrared pHAT:


12 months ago

hi leon
hope you are doing well
i am new to the raspberry pi, but have been learning since past few months. i am doing my first major project that is controlling tv using voice recognition with raspberry pi3

i faced many challenges and few i even overcame but now i need help
i installed lirc

then i did changes in /boot/config.txt file

i did changes in /etc/lirc/lirc_options

i stopped ,start and checked status using lirc using proper commands and working fine

after that by using mode2 command i checked pulses recorded by remote that worked fine too

after that using irrecord i successfully registered keys of remote
and then i did mv and cp command as needed

i did restart lirc again using as usual command

but after that when i run the command

irsend send_once sony1 KEY_POWER
it is showing
transmission error
input/output error

also when i use irsend LIST sony1 " "
i get
00000000000 KEY_POWER like this

what could be the problem
P.S. : my tv is controlled with 2 remotes
Please help


Reply 11 months ago

Which version of Raspbian are you using? Changes in the kernel modules provided with Raspbian Buster require different approach which is available at the user's manual of ANAVI Infrared pHAT.


Reply 11 months ago

hi leon , thanks for the reply
i actually got that corrected
but moving on further , i got problems
My tv has 2 remotes ,1 was recorded successfully and it ran successfully using irsend and another one was not getting recorded normal way so i used raw mode to get it recorded.Now using irsend for second remote , all keys run but some keys respond and operate and others dont.
plz help

also leon,i am a beginner. I sent you friend request on FB and tried calling you on messenger for getting my queries resolved.If you can please do that ,it will be of great help
shweta gulati khullar


Reply 11 months ago

Hi shweta, have you tried scanning again the remote control on which you have issues with some of the keys? Infrared is a bit tricky for scanning and some times several attempts are required.

Please note I don't accept FB request for people that I don't know personally. Neither provide free private technical support.


Reply 11 months ago

Hi leon,
Thanks for the reply!
I created a custom alexa skill with http endpoint . According to me i did everything correct but i am getting response as "there is a problem with the requested skill's response. i enabled display interfaces too.while testing i am getting no output and wrong input shows while testing.i used ngrok http URL as endpoint
Please help


3 years ago

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.


Reply 3 years ago

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:


Reply 3 years ago

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.


3 years ago

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?


Reply 3 years ago

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: