Source: https://mokxi.com/libraries/irremote
Updated: 2026-11-02

Libraries / Input
Arduino library · Input

# IRremote: read and send TV remote codes

IRremote is the standard Arduino library for infrared remote controls. With a 38 kHz receiver such as the VS1838B or a KY-022 module on a digital pin, it decodes the button presses of almost any remote, NEC, Samsung, Sony, RC5, RC6, LG, JVC, Denon and more, into a protocol, an address and a command number. With an IR LED it sends them back.

Open the example in the editor See the calls

Built in on Mokxi: #include <IRremote.h> and it builds, with nothing to install. Free, and no account needed.

## What IRremote does

Version 3 changed the interface, and many tutorials still show the old one. The current code uses a global IrReceiver object: IrReceiver.begin(pin), then in the loop IrReceiver.decode() to check for a frame, IrReceiver.decodedIRData.command to read the button, and IrReceiver.resume() to listen for the next. The old IRrecv irrecv(pin) and decode(&results) style is still accepted.

A cheap kit remote sends NEC codes: the address identifies the remote and the command identifies the button, so a sketch usually switches on the command. Holding a button sends repeat frames, flagged in decodedIRData.flags, which you can ignore or use for volume-style controls.

Library Manager name | IRremote

Author | Armin Joachimsmeyer, Ken Shirriff and others

Include | #include <IRremote.h>
#include <IRremote.hpp>
#include <IRremoteInt.h>
#include <TinyIRReceiver.hpp>

Boards | every board Mokxi compiles for but ATtiny85

In the simulator | Simulated: it runs against the part the way it does on the bench.

Parts it drives | Infrared receiver, VS1838B, Infrared remote, 21 buttons

## Install it

It builds on every board Mokxi compiles for but ATtiny85.

In Mokxi it is built in: #include <IRremote.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "IRremote" by Armin Joachimsmeyer, Ken Shirriff and others from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add IRremote to lib_deps in PlatformIO. Mokxi follows the calls of release 4.6.0, so a sketch written here builds there too.

What to know in the simulator: A send pin wired to an irreceiver’s IR pin is the beam, so a board can send to itself or to another; the handset part sends NEC. Off the AVR boards the end of a frame is noticed when the sketch next asks, so a receive-complete callback runs then. On the Uno R4 decode() reads a frame it sees starting rather than in the background. Bang & Olufsen needs RECORD_GAP_MICROS of 16 ms, as upstream.

ESP32-C3 · Arduino Uno · Arduino Nano · Arduino Mega 2560 · Arduino Leonardo · SparkFun Pro Micro · Arduino Micro · ESP32-C6 · Raspberry Pi Pico · Raspberry Pi Pico W · Seeed XIAO SAMD21 · STM32 · STM32 Nucleo-F411RE · STM32 Blue Pill · micro:bit V2 · Arduino Uno R4 · ESP32 DevKit · ESP32-S3-DevKitC-1 · ESP8266 NodeMCU · Arduino Pro Mini 3.3 V · Seeed XIAO ESP32-C3 · ESP32-C3 SuperMini · Seeed XIAO ESP32-C6 · ESP32-DevKitC V4 · LOLIN32 Lite · Wemos D1 R32 · Cheap Yellow Display · TTGO T-Display · Seeed XIAO ESP32-S3 · Arduino Nano ESP32 · Arduino Nano RP2040 Connect · Seeed XIAO RP2040 · Waveshare RP2040-Zero · Arduino Uno R4 WiFi

## The calls you will use

In the order a sketch meets them.

### IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK)

Starts receiving on a pin and blinks the built-in LED with each frame.

### IrReceiver.decode()

True when a frame has been decoded and is waiting.

### IrReceiver.decodedIRData.command

The button’s command number. decodedIRData.address is the remote’s address and decodedIRData.protocol the protocol.

### IrReceiver.printIRResultShort(&Serial)

Prints the protocol, address and command in one line, the quickest way to learn a remote’s codes.

### IrReceiver.resume()

Gets ready for the next frame. Without it, no further button is decoded.

### IrSender.begin(3)

Starts sending on the IR LED’s pin.

### IrSender.sendNEC(0x00, 0x45, 0)

Sends an NEC frame with an address, a command and a number of repeats.

## Example: Read the kit remote

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

### Wiring

- Arduino Uno R3 11 to Infrared receiver, VS1838B OUT
- Arduino Uno R3 5V to Infrared receiver, VS1838B VCC
- Arduino Uno R3 GND to Infrared receiver, VS1838B GND
- Infrared remote, 21 buttons IR to Infrared receiver, VS1838B IR

Open it in the editor, wired and ready to run

## Common errors and how to fix them

### 'decode_results' does not name a type, or the old example will not build

A 2.x tutorial is being built against a newer library in your IDE. Either switch to the IrReceiver style shown here, or check that the include is IRremote.hpp or IRremote.h and that only one IRremote library is installed.

### Only the first button press is seen

IrReceiver.resume() is missing after reading the frame. Call it once you have handled each decode.

### Every press reads as 0 or the same code

Those are repeat frames from a held button, or the protocol is UNKNOWN. Print printIRResultShort() to see the protocol, press briefly, and skip frames whose flags include IRDATA_FLAGS_IS_REPEAT if you only want new presses.

### Nothing is received at all

Check the receiver’s pinout, which differs between bare sensors and modules, and that the pin in begin() is the signal pin. Bright sunlight and some LED bulbs swamp IR receivers; test in the shade.

## Projects that use IRremote

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

IR remote codes on pin 12 An infrared receiver on pin 12: press a button on the remote and the IRremote library prints the code it sends, the full 32-bit NEC value the lesson’s table lists. Remote dimmer: IR on 12, LED on 5, buzzer on 13 Buttons 0 to 3 on the remote set the LED on pin 5 to off, dim, medium and full; an active buzzer on pin 13, switched by an NPN transistor, clicks for every code the receiver on pin 12 hears. IR receiver on pin 2 An IR receiver module on pin 2: press a button on the remote and the IRremote library prints the button’s name and its code. Remote-controlled colors: IR on pin 2, RGB on 11, 10 and 9 An IR receiver on pin 2 and an RGB LED with red on 11, green on 10 and blue on 9: buttons 1 to 7 on the remote pick a color of the rainbow and 0 turns the light off. IR decoder The kit remote and a VS1838B with the IRremote library: timer 2 samples the receiver in the background, and each button is named on the serial monitor. IR remote control relay module IRremote and a 21-key handset: keys 1 to 4 toggle the four channels of a relay board, each switching a 12 V lamp, and 0 turns them all off.

## Keep going

### Learn

- Arduino IR Remote: Decode NEC, Switch Lamps
- Arduino IR Transmitter: Laser Tag With Two Nanos

### Parts

- Infrared receiver, VS1838B
- Infrared remote, 21 buttons

### More input libraries

- XPT2046_Touchscreen
- Keypad
- OneButton
- Encoder
- RotaryEncoder
- CapacitiveSensor
- Adafruit MCP23017 Arduino Library
- PCF8574 (Rob Tillaart) and PCF8574 library (Renzo Mischianti)

Every built-in library · Open the editor

## Try IRremote without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
