Infrared remote control is one of the oldest and most reliable wireless communication technologies still in everyday use. From TV remotes to air conditioners, virtually every appliance you own speaks an IR protocol. As an electronics enthusiast, being able to decode IR signals with an Arduino opens up a world of possibilities — controlling custom projects with a spare remote, cloning remote functions, or building a universal IR blaster. This tutorial breaks down the three most important IR protocols — NEC, SONY, and RC5 — and shows you exactly how to decode them with the IRremote library.
Table of Contents
- How IR Remote Communication Works
- NEC Protocol: The Most Common IR Standard
- SONY SIRC Protocol
- RC5 Protocol: Philips Bi-Phase Standard
- Hardware Setup: TSOP Receiver and Arduino
- Using the IRremote Library to Decode Signals
- Sending IR Signals (IR Blaster)
- Frequently Asked Questions
How IR Remote Communication Works
IR remotes transmit data by flashing an infrared LED at a carrier frequency — typically 38 kHz. The receiving device (a TSOP1738 or similar demodulator) strips the carrier frequency and outputs a clean digital signal representing the data pulses. This modulation-demodulation approach helps filter out ambient IR noise from sunlight and incandescent bulbs.
The raw signal is a series of ON (mark) and OFF (space) durations measured in microseconds. Each protocol has a unique way of encoding bits using combinations of mark and space lengths:
- NEC: Uses pulse distance modulation — marks are fixed, spaces vary.
- SONY: Uses pulse width modulation — spaces are fixed, marks vary.
- RC5: Uses bi-phase (Manchester) encoding — transitions represent bits.
NEC Protocol: The Most Common IR Standard
The NEC protocol (developed by Nippon Electric Company) is the most widely used IR protocol globally. It is found in most generic Chinese remote controls, many TV brands, and a large number of hobbyist IR modules.
NEC Frame Structure
A full NEC transmission consists of:
- Leader code: 9 ms mark + 4.5 ms space (the distinctive “AGC burst”)
- Address byte: 8 bits — identifies the device
- Inverted address byte: 8 bits — logical NOT of address (for error checking)
- Command byte: 8 bits — the actual button code
- Inverted command byte: 8 bits — logical NOT of command
- Stop bit: 562.5 µs mark
Total frame: 32 bits of data. Logical 0 is encoded as a 562.5 µs mark + 562.5 µs space. Logical 1 is encoded as a 562.5 µs mark + 1687.5 µs space.
When a button is held down, NEC sends a repeat code instead of the full frame: 9 ms mark + 2.25 ms space + 562.5 µs mark. This tells the receiver the button is still pressed without resending all 32 bits.
Extended NEC: Some devices use a 16-bit address (no inverted address byte) to support more than 256 device addresses. The IRremote library decodes both variants automatically.
SONY SIRC Protocol
Sony developed its own IR protocol called SIRC (Serial Infra-Red Control). It comes in three variants: 12-bit, 15-bit, and 20-bit. The 12-bit version is most common in consumer electronics.
SIRC Frame Structure (12-bit)
- Start bit: 2.4 ms mark + 600 µs space
- Command bits (7 bits): Transmitted LSB first
- Address bits (5 bits): Device address, transmitted LSB first
Bit encoding uses pulse width modulation:
- Logical 0: 600 µs mark + 600 µs space
- Logical 1: 1200 µs mark + 600 µs space
The carrier frequency is 40 kHz (slightly higher than the 38 kHz NEC standard). Most 38 kHz TSOP receivers can still pick up Sony signals but with slightly reduced range. SIRC transmits the frame three times back to back with a 45 ms gap, improving reception reliability.
The 15-bit SIRC adds an extra 8 bits of address, and the 20-bit variant extends to a 7-bit command, 8-bit address, and 5-bit extended address — used for Sony cameras and multi-function devices.
RC5 Protocol: Philips Bi-Phase Standard
RC5 was developed by Philips and was the dominant European IR protocol through the 1980s and 1990s. Unlike NEC and SONY, RC5 uses bi-phase (Manchester) encoding, where each bit period is divided into two equal halves. A transition from high to low in the middle of a bit period represents logic 1; a transition from low to high represents logic 0.
RC5 Frame Structure
- Two start bits: Both logic 1 (in older RC5, first start bit later repurposed as a field bit)
- Toggle bit: Flips with each button press, allowing the receiver to distinguish between a held button and a new press
- 5-bit address: Up to 32 device types
- 6-bit command: Up to 64 commands per device (extended RC5 uses 7 bits via the field bit)
Each bit takes 1778 µs (two 889 µs half-periods). The carrier is 36 kHz. An RC5 frame is transmitted every 113.778 ms when a button is held.
RC5 is self-clocking due to Manchester encoding, meaning timing drift is less of an issue. However, it requires more complex decoding logic compared to NEC’s simple pulse-distance scheme.
Hardware Setup: TSOP Receiver and Arduino
You need a TSOP1738 (38 kHz) demodulator IC, a 100 Ω resistor, and a 100 µF capacitor for stable power supply decoupling on the TSOP’s VCC pin.
TSOP1738 pinout (flat side facing you, pins down): left pin = OUT, middle = GND, right = VCC.
| TSOP1738 Pin | Arduino Connection |
|---|---|
| OUT | Digital Pin 2 (via 100Ω resistor optional) |
| GND | GND |
| VCC | 5V (with 100µF cap to GND) |
For sending IR signals, connect an IR LED (940 nm wavelength) in series with a 100 Ω current-limiting resistor from Pin 3 to GND. The IRremote library uses Pin 3 (Timer2 PWM) by default for sending on Arduino Uno.
Using the IRremote Library to Decode Signals
The IRremote library (version 4.x) is the current standard. Install it via Library Manager by searching for “IRremote” by Armin Joachimsmeyer.
#include <IRremote.hpp>
#define IR_RECEIVE_PIN 2
void setup() {
Serial.begin(9600);
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
Serial.println("IR Receiver ready. Point any remote and press a button.");
}
void loop() {
if (IrReceiver.decode()) {
Serial.print("Protocol: ");
Serial.println(IrReceiver.decodedIRData.protocol);
Serial.print("Address: 0x");
Serial.println(IrReceiver.decodedIRData.address, HEX);
Serial.print("Command: 0x");
Serial.println(IrReceiver.decodedIRData.command, HEX);
Serial.println();
IrReceiver.resume(); // Ready for next value
}
}
When you press a button on an NEC remote, you will see output like:
Protocol: NEC
Address: 0x04
Command: 0x08
For SONY remotes:
Protocol: SONY
Address: 0x01
Command: 0x35
The library automatically identifies and decodes NEC, NEC extended, SONY 12/15/20-bit, RC5, RC6, Samsung, LG, and many other protocols. If the protocol is unrecognized, it reports as UNKNOWN and you can examine the raw timing data.
Sending IR Signals (IR Blaster)
Once you know the protocol, address, and command of any button, you can retransmit it to control your appliances:
#include <IRremote.hpp>
#define IR_SEND_PIN 3
void setup() {
IrSender.begin(IR_SEND_PIN, ENABLE_LED_FEEDBACK);
}
void loop() {
// Send NEC command: Address 0x04, Command 0x08
IrSender.sendNEC(0x04, 0x08, 0); // 0 = no repeat
delay(1000);
// Send SONY command: Address 0x01, Command 0x35, 12-bit
IrSender.sendSony(0x01, 0x35, 0, SIRCS_12_BITS);
delay(1000);
// Send RC5 command: Address 0x00, Command 0x01
IrSender.sendRC5(0x00, 0x01, 0);
delay(1000);
}
Practical IR blaster applications include a TV volume controller triggered by a button or voice command, an automated AC temperature scheduler using an ESP8266 + IR blaster over Wi-Fi, or a universal remote programmed via a web interface.
Frequently Asked Questions
How do I know which IR protocol my remote uses?
Upload the IRremote ReceiveDemo example, point your remote at the TSOP receiver, and press any button. The Serial Monitor will display the detected protocol name. Most generic remotes use NEC, Sony TV remotes use SIRC, and older Philips equipment uses RC5. If you see UNKNOWN, try the raw timing data capture example to manually analyze the waveform.
Why does my IR receiver decode garbage data or nothing at all?
Three common causes: First, the TSOP receiver is optimized for a specific carrier frequency — a TSOP1738 (38 kHz) will struggle with RC5 signals at 36 kHz or SONY signals at 40 kHz. Second, strong ambient IR from sunlight or halogen lamps can saturate the demodulator. Third, using digital pin interrupts already assigned to other libraries (e.g., Serial) can cause timing conflicts. Try using the 100 Ω + 100 µF decoupling on the TSOP VCC pin as recommended in the datasheet.
Can I use any IR LED for transmitting?
You need an IR LED with a peak wavelength of 940 nm (standard for most remotes). Visible LEDs will not work. The LED forward voltage is typically 1.2–1.5 V, so a 100 Ω series resistor from the 5 V Arduino pin limits current to about 35 mA — sufficient for 3–5 meter range. For longer range, use a transistor driver (BC547 + 33 Ω resistor) to push 100–200 mA peak through the LED.
What is the difference between IRremote 3.x and 4.x?
Version 4.x uses the IrReceiver and IrSender objects instead of the v3 IRrecv and IRsend class instances. The API is cleaner, but sketches written for v3 will not compile with v4 without minor modifications. If you find tutorials with irrecv.decode(&results) syntax, they are using v3. Always check which version is installed in your Library Manager.
Can Arduino decode and send RC6 as well?
Yes. The IRremote library supports RC6 in modes 0 through 6, including the Microsoft MCE remote (RC6 mode 6A). RC6 is more complex than RC5, using Manchester encoding with a 6× leading bit (6T = 2664 µs) and a header bit. The library handles this automatically — simply check for RC6 in the decoded protocol field.
Take Your Arduino IR Projects Further
Understanding NEC, SONY, and RC5 IR protocols gives you the knowledge to decode virtually any consumer IR remote and build systems that interact with real-world appliances. Whether you are automating a test rig, building a smart home controller, or just exploring how your TV remote works, the IRremote library makes the task straightforward.
Find all the Arduino boards, IR components, and sensors you need at zbotic.in Arduino & Microcontrollers. Fast delivery across India, with expert support for your project questions.
Add comment