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

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]

Supplies

--- 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=lirc-rpi

dtoverlay=gpio-ir,gpio_pin=17

#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:

:

:

space

pulse

:

:

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.




3 People Made This Project!

Recommendations

  • Robots Contest

    Robots Contest
  • Space Contest

    Space Contest
  • Tinkercad Student Design Contest

    Tinkercad Student Design Contest

42 Comments

0
whatwillaguydo
whatwillaguydo

10 days ago

This is old so I hope someone sees my comment. I tried this on a Pi 0 W. It seemed to go how it should until I tried mode 2. I just got:

Using driver default on device /dev/lirc0
Trying device: /dev/lirc0
Using device: /dev/lirc0
Running as regular user pi

^C

Pushing remote buttons got me nothing. I had the same result with just sudo mode2. I have the same sensor as the picture wired up with the output on GPIO 17.

Does anyone have suggestions?

0
Rich101101
Rich101101

Reply 10 days ago

I figure it's overdue to update this Instructable. So I loaded a brand new version of Raspberry Pi OS today on a RPi4. The basic Instructable is unchanged except the errors during the LIRC install are gone!. Just Install LIRC, change lirc_options.conf & config.txt as directed. It still works!

Do you get any errors with systemctl status??

0
whatwillaguydo
whatwillaguydo

Reply 9 days ago

I realized I was on raspbian stretch instead of buster. I hadn't kept up with the latest version. I'm getting the latest OS set up right now in case that was part of the problem. I'll report back after that's done.

0
Rich101101
Rich101101

Reply 9 days ago

Good luck! Definitely want the latest OS. The latest version of Buster has made installing LIRC much simpler.. Keep us posted on your progress!

0
whatwillaguydo
whatwillaguydo

Reply 8 days ago

Well, I updated the os and tried again. I got no warnings on the status but mode2 had no response when I pressed buttons on a remote. I know the sensor is good since it worked on an arduino. My next step will be a fresh install. The update from stretch to buster might have broken some things that won't be broken on a clean install.

0
whatwillaguydo
whatwillaguydo

Reply 8 days ago

Problem solved!

For anyone facing this problem, there are a few things to check.

First, verify that you are on the latest Buster OS. You can do this with 'cat /etc/os-release'.
If it doesn't say buster in there, it's faster, easier, and safer to start over from a clean install.

I initially tried doing this on stretch and it DOES NOT WORK.

Second, check your wiring. If you're certain it's correct, check it again with a multimeter. With the pi on, verify 3.3V across the power legs directly on the sensor. With the pi off, check for continuity from the gpio signal pin all the way to the signal leg in the sensor.

My wiring looked good but it turns out the breakout cable I made 5 years ago had a bad connection on gpio 17. I moved to gpio 27 (and updated config.txt) and that solved my problem.

I want to say a huge thank you to Rich101101 for making this page and helping me solve my rookie mistakes.

0
Rich101101
Rich101101

Reply 8 days ago

Definitely agree with a clean install.

0
migas.eust
migas.eust

Question 1 year ago

Hello, I've been trying to get lirc working for the past few weeks and I cant't manage to do it. I've already read countles tutorials and reset my pi many times and couldn't get anywhere.
This is one of the most simple ones I've seen and I'm still messing something up. Could anyone help me?
I've followed the steps very carefully and there are a few things that were different for me.
I'm using a Raspberry Pi 4B and the last Raspberry OS with Linux raspberrypi 5.4.51-v7l+ #1333 SMP Mon Aug 10 16:51:40 BST 2020 armv7l GNU/Linux.
When I first install Lirc there are no errors like there suppose to be and there was no /etc/lirc/lirc_options.conf.dist but there was already a /etc/lirc/lirc_options.conf so i skipped that step.
There was no problem then until I get to sudo mode2 -d /dev/lirc0, which the output was:
Using driver default on device /dev/lirc0
Trying device: /dev/lirc0
Please use the --raw option to access the device directly instead through the abstraction layer

I've checked the pins and config.txt and they're fine. Can someone give me some clarity pls?

0
matbour
matbour

Answer 11 months ago

I had the same problem I think that is was because an other instance was using the gpio pins

0
wjhedf
wjhedf

Reply 6 months ago

Try typing only:

sudo mode2

and then send remote commands. It should work.

0
ymltej
ymltej

Question 1 year ago

$ sudo mv /etc/lirc/lirc_options.conf.dist /etc/lirc/lirc_options.conf after this command i am getting an error "mv: cannot stat '/etc/lirc/lirc_options.conf.dist': No such file or directory" can you please help me. As the above step is blocking me from proceeding further.
Thanks in advance

0
Rich101101
Rich101101

Answer 1 year ago

This command simply renames a file. Use the file manager to navigate to the folder and inspect the directory contents. Either the file is missing (and would then start over) or a typo.

0
Dandy_Don
Dandy_Don

1 year ago

I have some of this working.... I need some help, please.

I installed lirc correctly. When I enter sudo mode2 -d /dev/lirc0 I get the following OUTPUT:
Using driver default on device /dev/lirc0
Trying device: /dev/lirc0
Using device: /dev/lirc0
Running as regular user pi

When I aim my IR LED at the receiver, I get:
space <numbers>
pulse <numbers>
space <numbers>
pulse <numbers>
.
.
.

The issue I'm having is the space & pulse numbers never repeat. I thought the space & pulse numbers would repeat if the same button was pushed repeatedly.....

I can connect my IR receiver up to an oscilloscope & capture the output. I see a pulse train that I can't figure out. See attached image.

The IR LED comes from a laser tag gun. The pulse train is the same each time I pull the trigger.

I tried a TV remote aimed at the IR receiver & the oscilloscope trace shows multiple pulses with spaces between each section, as expected. The 'code' is different depending on which button is pressed.

So, in theory, the laser tag gun should output a single 'code' every time it is fired. But when I aim the gun at the RPi (IR receiver connected to pin 17) I get random numbers....

I'm confused.....

Any suggestions?

team1.png
0
Dandy_Don
Dandy_Don

Reply 1 year ago

Thanks for your quick response!!

i tried the Python program in part 2.... I get an error when I run the program:

ImportError: cannot import name 'RawConnection'

I'm not sure what's causing this error.....

Also, I don't have a remote control config file for the laser tag gun.... Based on your instructions, it is difficult to create a file for the laser tag IR LED.

Any other suggestions?

0
Rich101101
Rich101101

Reply 1 year ago

Not sure this will help but.... The import error means the module is not present for your active python version. Look to make sure the module is present for your python version or just Try compiling for Python2 or Python3.

0
Dandy_Don
Dandy_Don

Reply 1 year ago

I'm using Geany to code the Python & I told it to use Python3.

Where do I look to see if the module is present?

0
Dandy_Don
Dandy_Don

Reply 1 year ago

I am able to get the codes for the laser tag gun using another python program.

"TEAM1": 2945, 6037, 2945, 2041, 955, 2041, 955, 2041, 955, 2041, 955, 2041, 1952, 2041, 955, 2041, 955
"TEAM2": 2945, 6037, 2945, 2041, 955, 2041, 955, 2041, 955, 2041, 1952, 2041, 955, 2041, 955, 2041, 955

I still can't get LIRC working, however....

Going back thru the steps above, I get an error with the line in Step 1:
$ sudo mv /etc/lirc/lirc_options.conf.dist /etc/lirc/lirc_options.conf

My pi says no such file or directory '/etc/lirc/lirc_options.conf.dist'

I think this might be the problem, but I'm not sure how to fix it..... the first 2 lines in Step 1 work:
$ sudo apt-get update
$ sudo apt-get install lirc

After install & setup, I enter:
sudo /etc/init.d/lircd status
This shows LIRC is active & running. It says
"Info: Cannot configure the rc device for /dev/lirc0"
"Error: error in configfile at line 2"
"Error: reading of file '/etc/lirc/lircd.conf' failed"

Maybe I don't have the config file set up right......

0
Rich101101
Rich101101

Reply 1 year ago

Unfortunately I was unable to get IRRecord to work which is suuposed to create a config file by recording commands from your IR device. I hzve not tried this but This link may be helpful.
[Stretch/Buster] Using LIRC with kernel 4.19.X and gpio-ir - Raspberry Pi Forums
https://www.raspberrypi.org/forums/viewtopic.php?t=235256

0
Dandy_Don
Dandy_Don

Reply 1 year ago

I am using kernel 4.14.98-v7. Should I upgrade to 4.19?