IR Decoder & Encoder - Part 1 - ElectroSchematics
IR Decoder & Encoder - Part 1 - ElectroSchematics
ElectroSchematics.com
T.K. Hareendran
Making your own infrared (IR) sniffer is not only rewarding but also amazingly simple. I’m talking
about an IR decoder/encoder that primarily decodes the invisible data transmitting from an IR remote
control handset under test into a perceivable notion suitable for further experimentation/
investigation. The same setup can also be used as a “limited” universal IR remote control. Let me show
how you can hack/make (decode/encode) an IR remote control with the help of a couple of low-priced
components!
IR Data Formats
The two most common IR remote control data formats — the NEC code and the RC5 code — are
explained in more detail here. The NEC code uses bursts at a carrier frequency of 38 kHz and starts the
transmission using a so-called leader code, a burst with a length of 9 ms, followed by a pause of 4.5 ms
and then the data word. The original purpose of this leader code (pre-burst) was to let the internal
control loops in the IR receiver modules settle. After transmitting the data word, only the leader code
and a single bit are transmitted repeatedly for as long as a key is pressed. A special property of this
code is a constant word length in combination with pulse-distance modulation. Both the address and
the data bits are transmitted twice — first as a normal byte and then followed by an inverted byte. The
half-period burst portion of each bit contains 22 pulses, each with a width of 8.77 µs and a period of
26.3 µs. A “0” is represented by a pulse distance of 1.125 ms, and a “1” is represented by a pulse
distance of 2.25 ms. Eight address bits are used to identify the device to be controlled. A further eight
bits are used for the transmission of the command data. As indicated above, the words are always
followed, without a pause, by the inverted words.
The RC 5 standard uses a bi-phase coding the carrier frequency fixed at 36 kHz. The transmission of a
data word begins with two start bits followed by a toggle bit. The toggle bit changes its value at each
new key press. The five address bits represent the address of the device to be controlled. The six
command bits contain the information to be transmitted. Each bit in the data word consists of half a
bit period with no transmission and half a bit period with a burst of 32 pulses at 36 kHz.
Hardware Setup — Forepart
Here’s the front-end circuit of the IR sniffer. The hardware will capture an IR code and retransmit it
on demand. The schematic isn’t particularly complex. The IR receiver module is represented here by
IRRX, powered from a 5-Vdc supply. An infrared emitter (IRED) is available for changing the
hardware as an IR encoder. LED1 indicates the IR signal activity but may be omitted together with R2.
First, I built the circuit on a piece of prototyping board (experimenting PCB). Here’s a photo of my
prototype:
Because the design is based on the IR sensor module TSOP1838 from Vishay, it inherently supports
the NEC format but can be easily extended to multiple IR data formats with necessary modifications.
The TSOP1838 is a miniaturized IR receiver module with a PIN diode and preamplifier assembled on
lead frame; the epoxy package is designed as an IR filter. The demodulated output signal can directly
be decoded by most microprocessors. See the block diagram of TSOP1838 below:
#include <IRremote.h>
int IRRX_PIN = 12; // D12 connected to Pin 3 of J1 – See schematic for J1 pin out!
IRrecv irrecv(IRRX_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
digitalWrite(IRRX_PIN,HIGH); // Optional Internal Pull‐up
}
void loop()
{
if (irrecv.decode(&results))
{
Serial.println(“Decoded Value:”);
Serial.println(results.value, HEX);
irrecv.resume();
}
}
A drained CR2025 coin-cell inside my NEC-protocol test remote control forced me to conduct the test
setup with another remote control, so my decoder setup was tested with a remote control of Videocon
DTH receiver, and I got “6F948B7” as the hex code for its “Power” button. For a momentary push, the
value is 6F948B7, and for push-and-hold, it’s 6F948B7 followed by FFFFFFFF. Later, I verified the
result with my trusty USB oscilloscope probed at pin 3 of header J1. See the annotated scope display
(random capture) below.
In the middle of experimenting, I learned that Videocon IR protocol is very similar to the NEC
protocol. Therefore, I tested my setup again with another code and confirmed that it’s NEC. What a
relief!
That’s all for this installment — not many ideas or much fun in it, I must admit, but there’s one more
installment (the encoder part) to come. Hope it might help someone — hold on!
Reference Courtesy: “Data formats for infrared remote control” / Document Number: 80071 /
www.vishay.com