A light emitting diode that emits in the infrared range. Depending on the input voltage, series resistors are required.

Technical data

Vf 1.1V
If 20mA
Emitting wavelength 940nm (non-visible light)

The designations (Vf and If) refer to the forward voltage and forward current of the light emitting diode.

Forward resistors:

Rf (3.3V) 120Ω

[e.g. when used with ARM CPU core based microcontrollers like Raspberry-Pi]

Rf (5V) 220Ω

[e.g. when used with Atmel Atmega based microcontrollers like Arduino].

The term (Rf) here refers to the required series resistor before the light emitting diode based on the applied voltage.

*On the board there is the possibility to directly solder the resistor needed in each case. **The place for soldering the resistor is directly above the connection pins on the PCB. In this case, the middle pin can be used, which then contains the resistor.

Pin assignment

Arduino code example

Baudrate of serial output should be set to 115200 otherwise remote control example will not work.

Code example ON/OFF

Pin assignment Arduino

Arduino Receiver
pin 3 signal
5V +V
Ground GND

This code example shows how an LED can be switched on alternately for four seconds and then switched off for two seconds using a definable output pin.

int Led = 3;
 
void setup ()
{
  pinMode (Led, OUTPUT); // Initialize output pin for the LED
}
 
void loop () //Main program loop
{
  digitalWrite (Led, HIGH); // LED is switched on
  delay (4000); // Wait mode for 4 seconds
  digitalWrite (Led, LOW); // LED is switched off
  delay (2000); // Wait mode for another two seconds during which the LED is switched off
}

Example program download

KY005-Arduino-ON-OFF.zip

Code example remote control

Arduino pin assignment

Arduino Receiver
pin 2 signal
5V +V
ground GND
Arduino Transmitter
Pin 3 Signal
Ground* GND+Resistor
ground GND
  • *Only if the series resistor is soldered on the module and not connected in front of the module

With the help of the two sensor modules KY-005 and KY-022 an infrared remote control + infrared receiver system can be built. For this purpose, two Arduinos are needed in addition to the two modules. These function here then as transmitter and as receiver of the signals. It is only important what the receiver of the signals in the serial console outputs and what the transmitter sends because this should match.

For the following code example an additional library is needed:

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

The library is not included in the package and must be copied to the "library" folder before starting the Arduino IDE.

This can be found by default under the following path of your Windows installation:

C:\user[username]\documents\Arduino\libraries.

For infrared sending systems, there are different protocols in which the data can be sent. In the following example the NEC protocol is used for sending data using the modified SimpleSender example and the modified SimpleReceiver example - the used library "Arduino-IRremote" takes care of the conversion to the correct data sequence by itself. 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 where your first Arduino is connected to which will later serve as a receiver. In this example it is possible to change lines 88 to 93.

Code for the receiver

/*
 * SimpleReceiver.cpp
 *
 * Demonstrates receiving NEC IR codes with IRrecv
 *
 *  Copyright (C) 2020-2021  Armin Joachimsmeyer
 *  armin.joachimsmeyer@gmail.com
 *
 *  This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
 *
 *  MIT License
 */

/*
 * Specify which protocol(s) should be used for decoding.
 * If no protocol is defined, all protocols are active.
 */
//#define DECODE_DENON        // Includes Sharp
//#define DECODE_JVC
//#define DECODE_KASEIKYO
//#define DECODE_PANASONIC    // the same as DECODE_KASEIKYO
//#define DECODE_LG
#define DECODE_NEC          // Includes Apple and Onkyo
//#define DECODE_SAMSUNG
//#define DECODE_SONY
//#define DECODE_RC5
//#define DECODE_RC6

//#define DECODE_BOSEWAVE
//#define DECODE_LEGO_PF
//#define DECODE_MAGIQUEST
//#define DECODE_WHYNTER

//#define DECODE_DISTANCE     // universal decoder for pulse width or pulse distance protocols
//#define DECODE_HASH         // special decoder for all protocols

#include <Arduino.h>

/*
 * Define macros for input and output pin etc.
 */
#include "PinDefinitionsAndMore.h"

#include <IRremote.h>

void setup() {
    Serial.begin(115200);
    // Just to know which program is running on my Arduino
    Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));

    /*
     * Start the receiver, enable feedback LED and take LED feedback pin from the internal boards definition
     */
    IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN);

    Serial.print(F("Ready to receive IR signals at pin "));
    Serial.println(IR_RECEIVE_PIN);
}

void loop() {
    /*
     * Check if received data is available and if yes, try to decode it.
     * Decoded result is in the IrReceiver.decodedIRData structure.
     *
     * E.g. command is in IrReceiver.decodedIRData.command
     * address is in command is in IrReceiver.decodedIRData.address
     * and up to 32 bit raw data in IrReceiver.decodedIRData.decodedRawData
     */
    if (IrReceiver.decode()) {

        // Print a short summary of received data
        IrReceiver.printIRResultShort(&Serial);
        if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
            // We have an unknown protocol here, print more info
            IrReceiver.printIRResultRawFormatted(&Serial, true);
        }
        Serial.println();

        /*
         * !!!Important!!! Enable receiving of the next value,
         * since receiving has stopped after the end of the current received data packet.
         */
        IrReceiver.resume(); // Enable receiving of the next value

        /*
         * Finally, check the received data and perform actions according to the received command
         */
        if (IrReceiver.decodedIRData.command == 0x34) {
            Serial.println("Signal received");
        } else if (IrReceiver.decodedIRData.command == 0x36) {
            Serial.println("Signal received and it is a different one this time around");
        } else {
            Serial.println("Signal received but sadly not the correct one");
        }
    }
}

Again, in order to use the following code, 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 a very important file is opened which is needed for sending. To open this example go to File -> Examples -> IRremote -> SimpleSender. Once you have done this you only need to replace the code in the example with the code below for the transmitter. After that you only need to select the Arduino you have connected your transmitter to. You do this as follows, you go to Tools -> Port -> COM. It is important that you select the COM to which your second Arduino is connected which will later serve as a transmitter. In this example it is possible to change the lines 49 to 58.

After you have set up your transmitter it is important to switch back to the COM with the correct port to get the serial output of the receiver Arduino.

Code for the transmitter

/*
   SimpleSender.cpp

    Demonstrates sending IR codes in standard format with address and command
    An extended example for sending can be found as SendDemo.

    Copyright (C) 2020-2021  Armin Joachimsmeyer
    armin.joachimsmeyer@gmail.com

    This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.

    MIT License
*/
#include <Arduino.h>

/*
   Define macros for input and output pin etc.
*/
#include "PinDefinitionsAndMore.h"

//#define SEND_PWM_BY_TIMER
//#define USE_NO_SEND_PWM

#include <IRremote.h>

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);

  Serial.begin(115200);

  // Just to know which program is running on my Arduino
  Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));

  /*
     The IR library setup. That's all!
  */
  IrSender.begin(IR_SEND_PIN, ENABLE_LED_FEEDBACK); // Specify send pin and enable feedback LED at default feedback LED pin

  Serial.print(F("Ready to send IR signals at pin "));
  Serial.println(IR_SEND_PIN);
}

/*
   Set up the data to be sent.
   For most protocols, the data is build up with a constant 8 (or 16 byte) address
   and a variable 8 bit command.
   There are exceptions like Sony and Denon, which have 5 bit address.
*/
uint16_t sAddress = 0x0102;
uint8_t sCommand = 0x34;

uint16_t sAddress1 = 0x0101;
uint8_t sCommand1 = 0x35;

uint16_t sAddress2 = 0x0103;
uint8_t sCommand2 = 0x36;

uint8_t sRepeats = 0;

void loop() {

  Serial.println(F("Send NEC with 16 bit address"));
  Serial.flush();

  // Results for the first loop to: Protocol=NEC Address=0x102 Command=0x34 Raw-Data=0xCB340102 (32 bits)
  IrSender.sendNEC(sAddress, sCommand, sRepeats);
  delay(1000);
  IrSender.sendNEC(sAddress1, sCommand1, sRepeats);
  delay(1000);
  IrSender.sendNEC(sAddress2, sCommand2, sRepeats);

  /*
     If you cannot avoid to send a raw value directly like e.g. 0xCB340102 you must use sendNECRaw()
  */
  //    Serial.println(F("Send NECRaw 0xCB340102"));
  //    IrSender.sendNECRaw(0xCB340102, sRepeats);

  delay(1000);  // delay must be greater than 5 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal
}

Sample program download

KY005-Arduino-Remote.zip

Code example Raspberry Pi

There are two application examples for this sensor module presented here. One which briefly turns the infrared transmitter diode on and off (emitting light not visible - can be seen through a cell phone camera for example), and a direct application example for the Raspberry Pi where it can be programmed as either an infrared receiver for remote controls to control e.g. the media center software OpenElec, or as an infrared transmitter for software controlled remote control.

Code example ON/OFF

Pin assignment Raspberry Pi

Raspberry Pi Sensor
GPIO 24 [Pin 18] Signal
Ground* [Pin 6] +V
Ground [Pin 6] GND
  • *Only if the series resistor is soldered on the module and not connected in front of the module
# Import and set up required modules
import RPi.GPIO as GPIO
import time
  
GPIO.setmode(GPIO.BCM)
  
# Here the input pin is declared, to which the sensor is connected. Additionally the PullUP resistor at the input will be activated
LED_PIN = 15
GPIO.setup(LED_PIN, GPIO.OUT, initial= GPIO.LOW)
  
print "LED test [press CTRL+C to end test]"
 
# main program loop
TRY:
        WHILE TRUE:
                PRINT("LED 4 SECONDS ON")
                GPIO.OUTPUT(LED_PIN,GPIO.HIGH) #LED is turned on
                time.sleep(4) #wait mode for 4 seconds
                print("LED 2 seconds off") 
                GPIO.output(LED_PIN,GPIO.LOW) #LED is switched off
                time.sleep(2) #wait mode for another two seconds when LED is off then
  
# clean up after the program is finished
except KeyboardInterrupt:
        GPIO.cleanup()

Example program download

KY005-RPi-ON-OFF.zip

To start with the command:

sudo python3 KY005.py

Code example remote control

Raspberry Pi pinout:

Raspberry Pi Receiver
GPIO15 [Pin 8] Signal
3.3V [Pin 17] +V
Ground [Pin 25] GND
Raspberry Pi transmitter
GPIO14 [Pin 10] Signal
ground* [pin 9] GND+resistor
Ground [Pin 6] GND

With its advanced processor architecture, the Raspberry Pi has the advantage over the Arduino that it can run a complete Linux operating system. 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.

For this purpose, the modules KY-005 are applied as infrared transmitter and KY-022 as infrared receiver.

To set up an infrared control system, you will follow these steps.

Source of the steps that follow now.

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.

dtoverlay=gpio-ir,gpio_pin=14
dtoverlay=gpio-ir-tx,gpio_pin=15

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...

lsmod | grep gpio
cat /proc/bus/input/devices

... You should then see the following.

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 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...

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 (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, next we will use our sender to send something to our receiver.

cat /etc/rc_keymaps/rc6_mce.toml | grep SLEEP

As a result of the previously executed command you should...

0x800f040c = "KEY_SLEEP"

... should appear. After that you only have to execute one last command...

ir-ctl -S rc6_mce:0x800f040c -d /dev/lirc1

... and you are now done and have a working setup.

Code example Micro:Bit

Code example ON/OFF

Pin assignment Micro:Bit:

Micro:Bit Transmitter
Pin 0 Signal
- +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.

Sample program download

microbit-KY-005.zip

Code example remote control

Pin assignment Micro:Bit:

Micro:Bit Transmitter
Pin 0 Signal
- +V
Ground GND
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.

Two additional libraries are needed for the following code example:

pxt-makerbit-ir-transmitter from 1010Technologies | released under the MIT License

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

You must add these libraries to your IDE before using the code.

You do this by going to Extensions in your IDE and using the following 2 URLs https://github.com/1010Technologies/pxt-makerbit-ir-transmitter.git and https://github.com/1010Technologies/pxt-makerbit-ir-receiver.git to search for the library and add it. It should be mentioned that sometimes the libraries only appear after you have added the second library.

Sample program download

microbit-KY-005-and-022-Remote.zip