This module can receive infrared signals and outputs them at the signal output as a digital sequence.

In addition, the LED integrated on the module flashes briefly when an infrared signal is detected.

Technical data

Carrier frequency 38kHz

Pin assignment

Code example Arduino

Pin assignment Arduino

Arduino Receiver
pin 2 signal
5V +V
ground GND

With the help of the sensor module KY-022 an infrared receiver can be built up. For this only the infrared receiver module and a single Arduino are needed. The Arduino acts as a receiver of the signals and outputs them to the serial console.

For the following code example an additional library is needed:

Arduino-IRremote by Ken Shirriff | published under the MIT license.

The example below uses this said library - for this, we recommend downloading it from Github, unzipping it and copying it to the Arduino library folder, which by default is located at (C:\User[username]\Documents\Arduino\libraries), so that it is available for this code example and subsequent projects. Alternatively, this is also included in the download package below as well.

For infrared transmitter and receiver systems, there are different protocols in which the data can be sent and received. In the following example the modified SimpleReceiver example is used for receiving - the used library "Arduino-IRremote" takes care of the conversion to the correct data sequence on its own. However, there are other protocols/encodings within the library - these are identified in the library documentation/code. Documentation.

In order to use the code that follows, a few important things need to be taken into account. First of all you have to open the already existing example from the library because it opens a very important file that is needed for receiving. To open this example go to File -> Examples -> IRremote -> SimpleReceiver. Once you have done this, all you need to do is replace the code in the example with the code below for the receiver. After that you only need to select the Arduino you have connected your receiver to. You do this as follows, you go to Tools -> Port -> COM. It is important that you select the COM to which your Arduino is connected which will later serve as a receiver. In this example it is possible to change the lines 88 to 93.

Code for the receiver

 * SimpleReceiver.cpp
 * Demonstriert den Empfang von NEC-IR-Codes mit IRrecv
 * Copyright (C) 2020-2021 Armin Joachimsmeyer
 * Diese Datei ist Teil von Arduino-IRremote
 * MIT-Lizenz

 * Geben Sie an, welche(s) Protokoll(e) für die Dekodierung verwendet werden soll(en).
 * * Wenn kein Protokoll definiert ist, sind alle Protokolle aktiv.
//#define DECODE_DENON // Enthält Sharp
//#define DECODE_JVC
//#define DECODE_PANASONIC // dasselbe wie DECODE_KASEIKYO
//#define DECODE_LG
#define DECODE_NEC // Beinhaltet Apple und Onkyo
//#define DECODE_SONY
//#define DECODE_RC5
//#define DECODE_RC6

//#define DECODE_LEGO_PF

//#define DECODE_DISTANCE // Universaldecoder für Impulsbreiten- oder Impulsabstandsprotokolle
//#define DECODE_HASH // Spezialdecoder für alle Protokolle

#include <Arduino.h>

 * Makros für Eingangs- und Ausgangspin definieren etc.
#include "PinDefinitionsAndMore.h"

#include <IRremote.h>

void setup() {
    // Nur um zu wissen, welches Programm auf meinem Arduino läuft
    Serial.println(F("START " __FILE__ " von " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));

     * Starten des Empfängers, Aktivieren der Feedback-LED und Abgreifen des LED-Feedback-Pins von der internen Kartendefinition

    Serial.print(F("Bereit zum Empfang von IR-Signalen an Pin "));

void loop() {
     * Prüfen, ob empfangene Daten vorhanden sind und wenn ja, versuchen, diese zu dekodieren.
     * Dekodiertes Ergebnis steht in der Struktur IrReceiver.decodedIRData.
     * Z.B. Befehl ist in IrReceiver.decodedIRData.command
     * Adresse ist in Befehl ist in IrReceiver.decodedIRData.address
     * und bis zu 32 Bit Rohdaten in IrReceiver.decodedIRData.decodedRawData
    if (IrReceiver.decode()) {

        // Drucken einer kurzen Zusammenfassung der empfangenen Daten
        if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
            // Wir haben hier ein unbekanntes Protokoll, drucken Sie weitere Informationen
            IrReceiver.printIRResultRawFormatted(&Serial, true);

         * !!!Wichtig!!! Aktivieren Sie den Empfang des nächsten Wertes,
         * da der Empfang nach dem Ende des aktuell empfangenen Datenpakets gestoppt wurde.
        IrReceiver.resume(); // Empfang des nächsten Wertes freigeben

         * Abschließend prüfen Sie die empfangenen Daten und führen Aktionen entsprechend dem empfangenen Befehl aus
        if (IrReceiver.decodedIRData.command == 0x34) {
            Serial.println("Signal empfangen");
        } else if (IrReceiver.decodedIRData.command == 0x36) {
            Serial.println("Signal empfangen und dieses Mal ist es ein anderes");
        } else {
            Serial.println("Signal empfangen, aber leider nicht das richtige");

Beispielprogramm Download

Codebeispiel Raspberry Pi

Anschlussbelegung Raspberry Pi:

Raspberry Pi Empfänger
GPIO15 [Pin 8] Signal
3,3V [Pin 17] +V
Masse [Pin 25] GND

With its advanced processor architecture, the Raspberry Pi has the advantage over the Arduino that it can run a complete Linux operating system. Thus, with the help of an infrared receiver, not only simple data signals can be exchanged, but also complete software programs such as the media center software OpenElec can be operated by remote control.

To set up an infrared control system, we will do the following. LINK.

First, you will edit config.txt by using the command....

sudo nano /boot/config.txt

. Then put the following at the end of this file.


Use the key combination [CTRL+X] to finish editing and [CTRL+Y] to save.

After you have shut down the Raspberry Pi with...

sudo reboot

... you will now execute the following commands...

``language-bash lsmod | grep gpio

cat /proc/bus/input/devices

... You should then see the following.

``language-bash I: Bus=0019 Vendor=0001 Product=0001 Version=0100 N: Name="gpio_ir_recv" P: Phys=gpio_ir_recv/input0 S: Sysfs=/devices/platform/ir-receiver@e/rc/rc0/input0 U: Uniq= H: Handlers=kbd event0 B: PROP=0 B: EV=100013 B: KEY=fff 0 0 4200 108fc32e 2376051 0 0 7 158000 4192 4001 8e9680 0 0 10000000 B: MSC=10

The next thing you have to do is to install ir-keytable...

sudo apt-get install ir-keytable -y

... to confirm a successful installation you should...

``language-bash ir-keytable

... and then also get the following output.

Found /sys/class/rc/rc0/ (/dev/input/event0) with:
	Name: gpio_ir_recv
	Driver: gpio_ir_recv, table: rc-rc6-mce
	LIRC device: /dev/lirc1
	Attached BPF protocols: Operation not permitted
	Supported kernel protocols: lirc rc-5 rc-5-sz jvc sony nec sanyo mce_kbd rc-6 sharp xmp imon 
	Enabled kernel protocols: lirc rc-6 
	bus: 25, vendor/product: 0001:0001, version: 0x0100
	Repeat delay = 500 ms, repeat period = 125 ms

After all this, here are a few more steps...

sudo ir-keytable -p all

... is used to display all possible protocols that can be used.

Protocols changed to lirc rc-5 rc-5-sz jvc sony nec sanyo mce_kbd rc-6 sharp xmp imon 
sudo ir-keytable

Is now entered to see which device is used for sending (here there is the possibility that either rc0 or rc1 is used (see /sys/class/rc/rc0 or rc1))...

Found /sys/class/rc/rc0/ (/dev/input/event0) with:
	Name: gpio_ir_recv
	Driver: gpio_ir_recv, table: rc-rc6-mce
	LIRC device: /dev/lirc1
	Attached BPF protocols: Operation not permitted
	Supported kernel protocols: lirc rc-5 rc-5-sz jvc sony nec sanyo mce_kbd rc-6 sharp xmp imon 
	Enabled kernel protocols: lirc rc-6 
	bus: 25, vendor/product: 0001:0001, version: 0x0100
	Repeat delay = 500 ms, repeat period = 125 ms

... depending on what is the case, the following command is modified as needed.

ir-keytable -t -s rc0

This now completes the configuration of our receiver.

Code example Micro:Bit

Port assignment Micro:Bit:

Micro:Bit Receiver
Pin 1 Signal
3V +V
Ground GND

This is a MakeCode example for Micro:Bit which essentially does the same as the examples of the other two variants. However, this example is closer to the Raspberry Pi example than the Arduino example.

An additional librarie is needed for the following code example:

pxt-makerbit-ir-receiver from 1010Technologies | published under the MIT License.

You have to add this library to your IDE before you can use the code.

You do this by going to Extensions in your IDE and, using the following URL, search for the library to add it. It should be mentioned that the library sometimes appears only after you have restarted the IDE.

Sample program download