KY-005 Infrared transmitter
A light emitting diode that emits in the infrared range.
- Arduino
- Raspberry Pi
- Raspberry Pi Pico
- Micro:Bit
This module contains a light-emitting diode that emits infrared light. Infrared light is invisible to the human eye, but it is often used in many practical applications, such as remote controls or object recognition. The diode operates with a voltage of 1.1 V and a current of 20 mA. Depending on the input voltage, it is important to use series resistors to protect the LED and ensure smooth operation. These series resistors ensure that the correct amount of current flows through the diode, allowing it to be used effectively and safely. The module is ideal for projects that require infrared light and provides a reliable and simple solution for your infrared applications.
Technical Data | |
---|---|
Forward voltage (Vf) | 1,1 V |
Forward current (If) | 20 mA |
Emitting wavelength | 940 nm (non-visible light |
Series resistors:
Input voltage | Required series resistor |
---|---|
3,3 V | 120 Ω |
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 (ON/OFF-Example)
Arduino | Receiver |
---|---|
Pin 3 | signal |
5 V | +V |
GND | GND |
Code-Example (ON-/OFF-Example)
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
Pin assignment (Remote control example)
Arduino | Transmitter |
---|---|
Pin 3 | Signal |
GND* | GND+Resistor |
GND+RESISTOR | GND |
*Only if the serial resistor has been soldered to the module and is not connected in front of the module.
Code-Example (Remote control example)
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 -> SimpleSender. Now you can replace the example code with our modified example.
/*
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
This module contains a light-emitting diode that emits infrared light. Infrared light is invisible to the human eye, but it is often used in many practical applications, such as remote controls or object recognition. The diode operates with a voltage of 1.1 V and a current of 20 mA. Depending on the input voltage, it is important to use series resistors to protect the LED and ensure smooth operation. These series resistors ensure that the correct amount of current flows through the diode, allowing it to be used effectively and safely. The module is ideal for projects that require infrared light and provides a reliable and simple solution for your infrared applications.
Technical Data | |
---|---|
Forward voltage (Vf) | 1,1 V |
Forward current (If) | 20 mA |
Emitting wavelength | 940 nm (non-visible light |
Series resistors:
Input voltage | Required series resistor |
---|---|
3,3 V | 120 Ω |
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 (ON-OFF example)
Raspberry Pi | Sensor |
---|---|
GPIO 15 [Pin 10] | Signal |
GND [Pin 6] | GND |
Code-Example (ON-OFF example)
# 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
Start with the command:
sudo python3 KY005.py
Pin assignment (Remote control example)
Raspberry Pi | Receiver |
---|---|
GPIO15 [Pin 10] | Signal |
3.3 V [Pin 1] | +V |
GND [Pin 6] | GND |
Raspberry Pi | Transmitter |
---|---|
GPIO14 [Pin 10] | Signal |
GND [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=15
dtoverlay=gpio-ir-tx,gpio_pin=14
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
This module contains a light-emitting diode that emits infrared light. Infrared light is invisible to the human eye, but it is often used in many practical applications, such as remote controls or object recognition. The diode operates with a voltage of 1.1 V and a current of 20 mA. Depending on the input voltage, it is important to use series resistors to protect the LED and ensure smooth operation. These series resistors ensure that the correct amount of current flows through the diode, allowing it to be used effectively and safely. The module is ideal for projects that require infrared light and provides a reliable and simple solution for your infrared applications.
Technical Data | |
---|---|
Forward voltage (Vf) | 1,1 V |
Forward current (If) | 20 mA |
Emitting wavelength | 940 nm (non-visible light |
Series resistors:
Input voltage | Required series resistor |
---|---|
3,3 V | 120 Ω |
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 (ON-OFF Example)
Micro:Bit | Transmitter |
---|---|
Pin 0 | Signal |
- | +V |
GND | GND |
Code-Example (ON-OFF Example)
Pin assignment (Remote control example)
Micro:Bit | Transmitter |
---|---|
Pin 0 | Signal |
- | +V |
GND | GND |
Micro:Bit | Receiver |
---|---|
Pin 1 | Signal |
3 V | +V |
GND | GND |
Code Example (Remote control 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 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.
makerbit.onIrDatagram(function () {
if (true) {
basic.showIcon(IconNames.SmallHeart)
} else {
basic.showIcon(IconNames.Heart)
}
})
makerbit.connectIrSenderLed(AnalogPin.P0)
makerbit.connectIrReceiver(DigitalPin.P1, IrProtocol.NEC)
basic.forever(function () {
makerbit.sendIrDatagram("0x00FF02FD")
basic.pause(500)
})
Sample program download
This module contains a light-emitting diode that emits infrared light. Infrared light is invisible to the human eye, but it is often used in many practical applications, such as remote controls or object recognition. The diode operates with a voltage of 1.1 V and a current of 20 mA. Depending on the input voltage, it is important to use series resistors to protect the LED and ensure smooth operation. These series resistors ensure that the correct amount of current flows through the diode, allowing it to be used effectively and safely. The module is ideal for projects that require infrared light and provides a reliable and simple solution for your infrared applications.
Technical Data | |
---|---|
Forward voltage (Vf) | 1,1 V |
Forward current (If) | 20 mA |
Emitting wavelength | 940 nm (non-visible light |
Series resistors:
Input voltage | Required series resistor |
---|---|
3,3 V | 120 Ω |
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 (ON-OFF example)
Raspberry Pi Pico | Sender |
---|---|
GPIO17 | Signal |
3.3V | +V |
GND | GND |
Code example (ON-OFF example)
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. But here we will only use the transmitter with a pico. This then acts as a transmitter of the signals.
For the following code example 4 additional libraries are needed:
micropython-ir by Peter Hinch | published under the MIT license.
micropython-async by Peter Hinch | published under the MIT license.
In infrared transmitting systems there are different protocols in which the data can be sent. In the following example, different protocols are used for sending. Documentation
Code for the transmitter
# Implements a 2-button remote control on a Pico with auto repeat.
# Load libraries
from machine import Pin
import uasyncio as asyncio
from primitives.switch import Switch
from primitives.delay_ms import Delay_ms
# Import all implemented classes
from ir_tx.nec import NEC
from ir_tx.sony import SONY_12, SONY_15, SONY_20
from ir_tx.philips import RC5, RC6_M0
######## **** DISPLAY GREETING **** ############################
s = '''Test for IR transmitter.
test() for NEC protocol
test(1) for Sony SIRC 12 bit
test(2) for Sony SIRC 15 bit
test(3) for Sony SIRC 20 bit
test(4) for Philips RC-5 protocol
test(5) for Philips RC-6 mode 0.
'''
srp2 = '''
IR LED gate on pin 17
Connect pin 18 to a ground pin to send addr 1 data 54
Connect pin 19 to a ground pin to send addr 0x10 data 0x34.'''
################################################################
loop = asyncio.get_event_loop()
# If the "button" is held down the normal behaviour is to
# retransmit the data but most NEC models send a REPEAT code
class Rbutton:
toggle = 1 # toggle is ignored in NEC mode
def __init__(self, irb, pin, addr, data, proto):
self.irb = irb
self.sw = Switch(pin)
self.addr = addr
self.data = data
self.proto = proto
self.sw.close_func(self.cfunc)
self.sw.open_func(self.ofunc)
self.tim = Delay_ms(self.repeat)
def cfunc(self): # Button push: send data
tog = 0 if self.proto < 3 else Rbutton.toggle # NEC, sony 12, 15: toggle==0
self.irb.transmit(self.addr, self.data, tog, True) # Test validation
# Auto repeat. The Sony protocol specifies 45ms but this is tight.
# In 20 bit mode a data burst can be upto 39ms long.
self.tim.trigger(108)
def ofunc(self): # Button release: cancel repeat timer
self.tim.stop()
Rbutton.toggle ^= 1 # Toggle control
async def repeat(self):
await asyncio.sleep(0) # Let timer stop before retriggering
if not self.sw(): # Button is still pressed: retrigger
self.tim.trigger(108)
if self.proto == 0:
self.irb.repeat() # NEC special case: send REPEAT code
else:
tog = 0 if self.proto < 3 else Rbutton.toggle # NEC, sony 12, 15: toggle==0
self.irb.transmit(self.addr, self.data, tog, True) # Test validation
async def main(proto):
# Test uses a 38KHz carrier.
# Pin for the IR LED gate
pin = Pin(17, Pin.OUT, value = 0)
# List with all possible protocols
classes = (NEC, SONY_12, SONY_15, SONY_20, RC5, RC6_M0)
irb = classes[proto](pin, 38000)
# Uncomment the following to print transmition timing
# irb.timeit = True
b = [] # Rbutton instances
px3 = Pin(18, Pin.IN, Pin.PULL_UP)
px4 = Pin(19, Pin.IN, Pin.PULL_UP)
# edit these two for the desired effect/data/comand #
b.append(Rbutton(irb, px3, 0x1, 0x36, proto))
b.append(Rbutton(irb, px4, 0x10, 0x34, proto))
#####################################################
led = Pin(25, Pin.OUT)
while True:
await asyncio.sleep_ms(500) # Obligatory flashing LED.
led(not led())
# Function to be called to start the sending of the IR Data
def SendIRData(proto=0):
loop.run_until_complete(main(proto))
print(''.join((s, srp2)))
# Endless loop for continuous operation
while True:
SendIRData()