ESP32 KY-005 Infrared Transmitter Module
The KY-005 is an infrared transmitter module that emits infrared light at a wavelength of 940 nm. It is commonly used in remote control applications and can be paired with the KY-022 Infrared Receiver Module for infrared communication projects.
β¬οΈ Jump to Code Examples
π Quick Links
π KY-005 Price
βΉοΈ About KY-005 Infrared Transmitter Module
The KY-005 is an infrared (IR) transmitter module designed to emit infrared light at 940 nm, making it ideal for remote control applications. It consists of a 5mm infrared LED and operates with a forward voltage of 1.1V and a current of 20mA.
β‘ Key Features #
- 940 nm Infrared Emission β Suitable for IR remote control and data transmission.
- Adjustable Resistor Requirement β
- 3.3V input β Use a 120Ξ© resistor
- 5V input β Use a 220Ξ© resistor
- Simple Digital Control β Easily interfaces with ESP32, Arduino, and other microcontrollers.
- Pairs with KY-022 β Works alongside the KY-022 Infrared Receiver Module for IR communication systems.
With its compact design and reliable performance, the KY-005 is an excellent choice for wireless IR control applications. π
βοΈ KY-005 Sensor Technical Specifications
Below you can see the KY-005 Infrared Transmitter Module Technical Specifications. The sensor is compatible with the ESP32, operating within a voltage range suitable for microcontrollers. For precise details about its features, specifications, and usage, refer to the sensorβs datasheet.
- Protocol: Infrared
- Forward Voltage (Vf): 1.1V
- Forward Current (If): 20mA
- Emitting Wavelength: 940 nm
- Recommended Series Resistor for 3.3V: 120Ξ©
- Recommended Series Resistor for 5V: 220Ξ©
- Dimensions: 18.5mm x 15mm
π KY-005 Sensor Pinout
Below you can see the pinout for the KY-005 Infrared Transmitter Module. The VCC
pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND
pin is the ground connection and must be connected to the ground of your ESP32!
Pin (S):
Signal pin, connects to the microcontroller's GPIO pin.Pin (middle):
Can be connected to ground if an additional resistor has been soldered onto the module.Pin (-):
Ground pin, connects to the ground of the circuit.
𧡠KY-005 Wiring with ESP32
Below you can see the wiring for the KY-005 Infrared Transmitter Module with the ESP32. Connect the VCC pin of the sensor to the 3.3V pin on the ESP32 or external power supply for power and the GND pin of the sensor to the GND pin of the ESP32. Depending on the communication protocol of the sensor (e.g., I2C, SPI, UART, or analog), connect the appropriate data and clock or signal pins to compatible GPIO pins on the ESP32, as shown below in the wiring diagram.
KY-005 Pin (S):
Connect to ESP32 GPIO pin (e.g.,GPIO17
).KY-005 Pin (middle):
Connect to ground if an additional resistor has been soldered onto the module; otherwise, leave unconnected.KY-005 Pin (-):
Connect to ESP32GND
. Ensure a series resistor (e.g., 220Ξ© for 5V) is used to protect the LED.
π οΈ KY-005 Infrared Transmitter Module Troubleshooting
This guide outlines a systematic approach to troubleshoot and resolve common problems with the . Start by confirming that the hardware connections are correct, as wiring mistakes are the most frequent cause of issues. If you are sure the connections are correct, follow the below steps to debug common issues.
β Infrared Signal Not Emitted
Issue: The module does not emit an infrared signal.
Solutions:
- Verify that the correct series resistor is used based on the input voltage (e.g., 220Ξ© for 5V).
- Ensure all connections are secure and correctly placed.
- Confirm that the microcontroller's GPIO pin is configured correctly in the code.
- Test the infrared LED with a camera to see if it lights up when active (infrared light is visible to most digital cameras).
π₯ Overheating or Damage to the Module
Issue: The module becomes hot or is damaged during operation.
Solutions:
- Check that the appropriate series resistor is in place to limit current through the LED.
- Ensure the input voltage does not exceed the module's specifications.
- Inspect for any short circuits or incorrect wiring that could cause excessive current draw.
π» Code Examples
Below you can find code examples of KY-005 Infrared Transmitter Module with ESP32 in several frameworks:
If you encounter issues while using the KY-005 Infrared Transmitter Module, check the Common Issues Troubleshooting Guide.

ESP32 KY-005 Arduino IDE Code Example
Fill in your main
Arduino IDE sketch file with the following code to use the KY-005 Infrared Transmitter Module:
#include <IRremote.h>
IRsend irsend;
void setup() {
Serial.begin(9600);
Serial.println("KY-005 Infrared Transmitter Test");
}
void loop() {
for (int i = 0; i < 3; i++) {
irsend.sendNEC(0xA90, 32); // Send NEC protocol with command 0xA90
delay(40);
}
delay(5000); // Wait 5 seconds before sending the signal again
}
This Arduino code utilizes the IRremote library to send an NEC protocol infrared signal with the command 0xA90
. The signal is sent three times with a 40ms delay between transmissions, followed by a 5-second pause before repeating. This setup is commonly used to control devices like TVs or other appliances that accept infrared commands.
Connect your ESP32 to your computer via a USB cable, Ensure the correct Board and Port are selected under Tools, Click the "Upload" button in the Arduino IDE to compile and upload the code to your ESP32.

ESP32 KY-005 ESP-IDF Code ExampleExample in Espressif IoT Framework (ESP-IDF)
This ESP-IDF code sets up the KY-005 Infrared Transmitter using the RMT (Remote Control) peripheral of the ESP32. It configures GPIO17 as the output pin and initializes the RMT driver to transmit an infrared signal. The IR protocol can be customized to match the target device's requirements.

ESP32 KY-005 ESPHome Code Example
Fill in this configuration in your ESPHome YAML configuration file (example.yml
) to integrate the KY-005 Infrared Transmitter Module
remote_transmitter:
- platform: gpio
pin: GPIO17
carrier_duty_percent: 50%
button:
- platform: template
name: "KY-005 Send IR Signal"
on_press:
- remote_transmitter.transmit_nec:
address: 0x00FF
command: 0xA90
This ESPHome configuration sets up the KY-005 Infrared Transmitter on GPIO17. It uses the NEC protocol to send an infrared command when a button is pressed, making it ideal for controlling TVs or other IR-enabled devices.
Upload this code to your ESP32 using the ESPHome dashboard or the esphome run
command.

ESP32 KY-005 PlatformIO Code Example
For PlatformIO, make sure to configure the platformio.ini
file with the appropriate environment and libraries, and then proceed with the code.
Configure platformio.ini
First, your platformio.ini
should look like below. You might need to include some libraries as shown. Make sure to change the board to your ESP32:
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
z3t0/IRremote
ESP32 KY-005 PlatformIO Example Code
Write this code in your PlatformIO project under the src/main.cpp
file to use the KY-005 Infrared Transmitter Module:
#include <Arduino.h>
#include <IRremote.h>
IRsend irsend;
void setup() {
Serial.begin(115200);
Serial.println("KY-005 Infrared Transmitter Test");
}
void loop() {
Serial.println("Sending IR signal");
irsend.sendNEC(0x00FF, 32);
delay(5000);
}
This PlatformIO code initializes the KY-005 Infrared Transmitter using the IRremote library. It sends an NEC protocol signal every 5 seconds, making it suitable for testing IR communication.
Upload the code to your ESP32 using the PlatformIO "Upload" button in your IDE or the pio run --target upload
command.

ESP32 KY-005 MicroPython Code Example
Fill in this script in your MicroPython main.py file (main.py
) to integrate the KY-005 Infrared Transmitter Module with your ESP32.
import machine
import time
IR_TX_PIN = machine.Pin(17, machine.Pin.OUT)
def send_pulse():
for _ in range(32):
IR_TX_PIN.value(1)
time.sleep_us(562)
IR_TX_PIN.value(0)
time.sleep_us(562)
while True:
print("Sending IR signal")
send_pulse()
time.sleep(5)
This MicroPython script configures the KY-005 Infrared Transmitter on GPIO17. It simulates an NEC-like IR signal by toggling the pin on and off rapidly, mimicking the transmission of an infrared command.
Upload this code to your ESP32 using a MicroPython-compatible IDE, such as Thonny, uPyCraft, or tools like ampy
.
Conclusion
We went through technical specifications of KY-005 Infrared Transmitter Module, its pinout, connection with ESP32 and KY-005 Infrared Transmitter Module code examples with Arduino IDE, ESP-IDF, ESPHome and PlatformIO.