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


About This Instructable




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