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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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


FredJ34 (author)2017-12-10

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?

leon-anavi (author)FredJ342017-12-11

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:

About This Instructable




Bio: Software engineer and open source enthusiast
More by leon-anavi:Raspberry Pi Christmas TreeTransforming Raspberry Pi Into a Remote ControlPlaying OpenArena on PocketC.H.I.P.
Add instructable to: