KY-005 Infrared transmitter
A light emitting diode that emits in the infrared range.

A light emitting diode that emits in the infrared range. Depending on the input voltage, series resistors are required.
Technical data
Forward voltage | 1.1 V |
Forward current | 20 mA |
Emitting wavelength | 940nm (non-visible light) |
Forward resistors:
Series resistor (3.3 V) | 120 Ω |
Series resistor (5 V) | 220 Ω |
On the PCB there is the possibility to directly solder the required resistor. The place for soldering the resistor is located directly above the connection pins on the PCB.
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 |
5 V | +V |
Ground | GND |
This code example shows how an LED can be alternately switched on 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
Code example remote control
Arduino pin assignment
Arduino | Receiver |
---|---|
Pin 2 | signal |
5 V | +V |
Ground | GND |
Arduino | Transmitter |
---|---|
Pin 3 | Signal |
Ground | GND |
With the help of the two sensor modules KY-005 and KY-022 a system with infrared remote control and infrared receiver can be built. For this purpose, two Arduinos are required in addition to the two modules. These then act as transmitters and receivers of the signals.
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.
In infrared transmitting systems there are different protocols in which the data can be sent. In the following example, the NEC protocol is used for sending. Documentation.
Please note: For the execution of the code example an additional file is necessary. This opens automatically as soon as you open the sample code from the Arduino IRremote library. Therefore, first open the example code via the following path: File -> Examples -> IRremote -> SimpleReceiver. Now you can replace the example code with our modified example. Now you have to select the Arduino you connected your receiver to: Tools -> Port -> COM.
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");
}
}
}
Please note: For the execution of the code example an additional file is necessary. This opens automatically as soon as you open the sample code from the Arduino IRremote library. Therefore, first open the example code via the following path: File -> Examples -> IRremote -> SimpleSender. Now you can replace the example code with our modified example. Now you have to select the Arduino you connected your transmitter to: Tools -> Port -> COM.
After you have transferred the code for your transmitter, the COM port has to be set to the port of your receiver again, so that you can see the corresponding outputs of your receiver in the serial output.
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
Code example Raspberry Pi
Two application examples are presented here. One, which briefly switches the infrared transmitter diode on and off again (emitting light not visible - can be seen e.g. by a cell phone camera), and a direct application example for the Raspberry Pi, where it is used as a receiver.
Code example ON/OFF
Pin assignment Raspberry Pi
Raspberry Pi | Sensor |
---|---|
GPIO 24 [Pin 18] | Signal |
Ground [Pin 6] | GND |
# 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
To start with the command:
sudo python3 KY005.py
Code example remote control
Raspberry Pi pinout:
Raspberry Pi | Receiver |
---|---|
GPIO15 [Pin 8] | Signal |
3.3 V [Pin 17] | +V |
Ground [Pin 25] | GND |
Raspberry Pi | transmitter |
---|---|
GPIO14 [Pin 10] | Signal |
Ground [Pin 6] | GND |
Source of the now following steps.
First, open the config.txt file using the following command:
sudo nano /boot/config.txt
Now add the following content to the end of the file:
dtoverlay=gpio-ir,gpio_pin=14
dtoverlay=gpio-ir-tx,gpio_pin=15
With the key combination [CTRL+O] you can save the file. Confirm this with [Enter] and exit the editor with the key combination [CTRL+X]. Now restart your Raspberry Pi with the following command:
sudo reboot
Now install the ir-keytable module:
sudo apt-get install ir-keytable -y
With the following command you can determine the device identification. This is necessary to be able to address the receiver in the further course:
sudo ir-keytable
The first line of the output should look something like this:
Found /sys/class/rc/rc0/ (/dev/input/event0) with:
Here it can be read that we can address our receiver via the identification rc0. Therefore we start the reception now via the following command:
ir-keytable -t -s rc0
Code example Micro:Bit
Code example ON/OFF
Pin assignment Micro:Bit:
Micro:Bit | Transmitter |
---|---|
Pin 0 | Signal |
- | +V |
Ground | GND |

Sample program download
Code example remote control
Pin assignment Micro:Bit:
Micro:Bit | Transmitter |
---|---|
Pin 0 | Signal |
- | +V |
Ground | GND |
Micro:Bit | Receiver |
---|---|
Pin 1 | Signal |
3 V | +V |
Ground | GND |
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 need to add these libraries to your IDE before using the code.
Add the library to your IDE by clicking on "Extensions" and entering each of the following URLs in the search box: *https://github.com/1010Technologies/pxt-makerbit-ir-transmitter.git* and *https://github.com/1010Technologies/pxt-makerbit-ir-receiver.git* Confirm the search in each case with Enter.
