Introduction: Easy Setup IR Remote Control Using LIRC for the Raspberry PI (RPi) - Updated Oct 2021 [Part 1]

After much searching I was surprised and dismayed about the conflicting information on how to setup IR remote control for my RPi project. I thought it would be easy but setting up Linux InfraRed Control (LIRC) has been problematic for a long time but much changed in June 2019 with the release of the Buster version of Raspbian making much of the tutorials out there worthless. Many tutorials have you create a hardware.conf file but LIRC does not need nor want it and the lirc-rpi module has been replaced with the gpio-ir module.

The tutorial assumes the RPi is running raspbian (version Buster Oct 2021). Also a working knowledge of the terminal, basic commands from the command prompt and editing text files is assumed.

NOTE: YOU MUST build the included python code with PYTHON3 (NOT python2 or python) or you will receive an error in the import in Line1. The LIRC module is only installed in Python3!

Goal: To enable IR remote control of RPi projects

1) Setup LIRC on RPi [Part 1]

2) Demonstrate LIRC using python [Part 2]


--- Raspberry Pi (3,4,zero)

--- Dupont wire (female-female)

--- VS 1838b IR receiver

Step 1: Assemble Hardware

Using the VS1838b IR receiver couldn't be easier. Just hook up the sensor to the RPi directly with Dupont wire (Female-Female). You could also use a breadboard (not shown) or solder on a protoboard (photo)

Looking at the VS1838b IR Receiver from the front (with the big X facing you)

---- Left leg is out

---- Center leg is ground

---- Right leg is 3.3v

1) Attach the left leg to BCM pin 17 on the RPi (yellow wire)

2) Attach the center leg to ground (black wire)

3) Attach the right leg to 3.3v (red wire)

Step 2: Install Lirc

1) Open terminal window and install LIRC.

$ sudo apt-get update

$ sudo apt-get install lirc

Update October 2021:

This error has been fixed in the latest Buster Version Oct 2021 and the rest of this step should be ignored

Be forewarned that this will likely raise an error "Failed to start Flexible IR remote input/output application support" as the installed files now have .dist appended and the suffix must be removed as noted below. Not hard but frustrating.

----DON'T WORRY! as this will likely raise an error "Failed to start Flexible IR remote input/output application support" as the .dist suffix needs to be deleted from lirc_options.conf. Just rename the file as shown.

$ sudo mv /etc/lirc/lirc_options.conf.dist /etc/lirc/lirc_options.conf

2) Reinstall lirc now that the lirc_options.conf file has been renamed

$ sudo apt-get install lirc

Step 3: Edit Lirc_options.conf

Edit /etc/lirc/lirc_options.conf as follows by changing these two lines:



driver = default

device = /dev/lirc0



Step 4: Perform Move to Remove .dist Suffix From Lircd.conf.dist

Update Oct 2021: This step is no longer required and should be skipped

Remove suffix .dist from /etc/lirc/lircd.conf.dist

$ sudo mv /etc/lirc/lircd.conf.dist /etc/lirc/lircd.conf

Step 5: Edit Config.txt

Edit /boot/config.txt by adding one line in the lirc-rpi module section as follows. This example assumes the RPi is 'listening' on BCM Pin 17 for the IR receiver but any RPi IO pin can be used. I have not tried it yet but if you want to send commands from the RPi then add and uncomment the 4th line shown below to send IR commands on BCM pin 18

Update: Oct 2021 Note: If both lines are uncommented the LIRC test will fail. The LIRC test can ONLY receive or transmit not both! However it is possible to have both lines uncommented and transmit & receive from python AFTER LIRC is correctly setup.




# Uncomment this to enable the lirc-rpi module



#dtoverlay=gpio-ir-tx, gpio_pin=18




Step 6: Check Status and Reboot

1) Stop, start and check status of lircd to ensure there are no errors!

$ sudo systemctl stop lircd.service

$ sudo systemctl start lircd.service

$ sudo systemctl status lircd.service

2) Reboot

$ sudo reboot

Step 7: Test Remote

This step assumes you have have a IR receiver hooked up to your RPi on the pin specified in config.txt.

1) stop LIRCD service and test remote using mode2 command

$ sudo systemctl stop lircd.service

$ sudo mode2 -d /dev/lirc0

3) Point the remote at the receiver and press some buttons. You should see something LIKE this:







4) Press Ctrl-C to exit

Update October 2021 to format output better:

$ sudo mode2 -m -d /dev/lirc0

5) Your IR receiver is setup and ready to proceed to Part 2 and be accessed in python.