Mapping IR emitter module KY-005 sensor/receiver module KY-022-IR sensor - A tutorial for raspberry pi
The content here is under the Attribution 4.0 International (CC BY 4.0) license
For the past few days I have been playing with the kit ELEGOO 37-in-1 Kit and the first project I wanted to build was a remote control using raspberry pi and the sensor KY-022 that comes with the kit. Giving the different sensors and boards I took some time to figure out the steps I needed to build the project. This post is the detailed step-by-step that I did to build my personal project using IR sensors.
DISCLAIMER: This post is focused on the kernel 5.4, and the base hardware used is as follows:
- Raspberry pi 3 model B +
- Raspbian as a operational system
- Energy supplied via USB cable
DISCLAIMER 2: The sections 1 and 2 can be swapped out without any problem. If you prefer to setup the hardware part first, then read the section 2 and then section 1. Therefore, if you prefer to setup the software first (as I prefer), you can keep the suggested order.
Setting up the pi to use IR
Note: the commands executed in this section are executed in the raspberry pi shell
There are two parts of this puzzle to make it to work, the first is to install the lirc.
sudo apt-get install lirc -y
Next we are going to configure the boot script to enable the IR package. 
has the steps to enable the pin to receive IR signal, and I will use the same
approach here. The changes in the file
config.txt assumes that
the receiver goes in the GPIO 17, ping 11. The transmitter goes in
the GPIO 18, pin 12 .
sudo nano /boot/config.txt
Once the change has been made in the file
config.txt, save it and reboot
the pi. Once back in the pi shell, verify if the devices were enabled properly,
executing the following command:
sudo ls -l /dev/lirc*
The output should be something like the following:
[email protected]:~ $ sudo ls -l /dev/lirc* crw-rw---- 1 root video 251, 0 Jan 31 12:17 /dev/lirc0 crw-rw---- 1 root video 251, 1 Jan 31 12:17 /dev/lirc1
One interface for reading signals (
/dev/lirc0) and the other to send it
Wiring up the pi with both sensors was a bit of challenge for me, first because it was a new sensor that I was working and it was difficult to find in a single website the wiring with both sensors and in the pi. Often, the tutorials were for arduino and for one sensor, the transmitter or the receiver . This section is the result for the lack of having both sensors on the pi. The first image depicts the wiring for the transmitter.
|Pi PIN||Transmitter PIN|
|11 (GPIO 17)||YELLOW|
The receiver sensor, was adopted from  as it has the wiring required but used with arduino.
|Pi PIN||Transmitter PIN|
|11 (GPIO 17)||YELLOW|
The following section, will cover how to map the wiring presented in this section and sending or receiving the signals, it will also dives in the remote control database that the project lirc has for already mapped remotes.
Mapping inputs to IR codes
Previous sections were focused on setting up the hardware and the needed software to make the ir sensors to work. This section focus on the configuration of lirc. The configuration presented here is needed in order to send ir commands.
The first step is to find out which remote you would like to configure.
lirc package provides the mapping between the IR codes and the remote
For me I ended up using the remote AA59-00600A. The following command depicts how to download
a given remote configuration:
cd && \ wget https://sourceforge.net/p/lirc-remotes/code/ci/master/tree/remotes/samsung/AA59-00600A.lircd.conf && \ sudo mv AA59-00600A.lircd.conf /etc/lirc/lircd.conf.d/ && \ sudo /etc/init.d/lircd status
Once downloaded the
irsend command is used to send IR commands to the television. For
the downloaded file above, the volume down IR command is as follows:
sudo irsend SEND_ONCE SAMSUNG_AA59-00600A KEY_VOLUMEDOWN
For each downloaded remote, I suggest to open the
.lircd.conf file and check the
name and the available keys under the section
Miss leading configuration
A few tutorials related to the pi, will have an extra step regarding configuring
the ir devices. The extra step says that it is required to update the file
under the directory
etc. For this post and the setup I am using this step is not require, there is no need
to add an entry in the file located at
- peppe8o, “Setup Raspberry PI Infrared Remote from terminal,” 2020 [Online]. Available at: https://peppe8o.com/setup-raspberry-pi-infrared-remote-from-terminal. [Accessed: 29-Jan-2021]
- R. pi, “GPIO,” 2021 [Online]. Available at: https://www.raspberrypi.org/documentation/usage/gpio. [Accessed: 30-Jan-2021]
- T. G. Pub, “SENSOR WIKI: KY-005 INFRARED TRANSMITTER (IR),” 2019 [Online]. Available at: https://www.thegeekpub.com/wiki/sensor-wiki-ky-005-infrared-ir-transmitter. [Accessed: 30-Jan-2021]
- epitran.it, “KY-022 INFRARED RECEIVER MODULE,” 2021 [Online]. Available at: https://www.epitran.it/ebayDrive/datasheet/45.pdf. [Accessed: 30-Jan-2021]
- lirc alec_leamas, “lirc-remotes - The lirc remotes database,” 2018 [Online]. Available at: https://sourceforge.net/p/lirc-remotes/code/ci/master/tree/remotes. [Accessed: 30-Jan-2021]
Table of contents
Got a question?
If you have question or feedback, don't think twice and click here to leave a comment. Just want to support me? Buy me a coffee!