Take the course at /learn/path/infrared-remotes. It is an intermediate course on the Arduino Uno: it assumes the Uno course and explains every protocol detail from scratch.
The bench
The remote side is an Uno with a VS1838B receiver on pin 2, the 21-key kit handset aimed at it, and an infrared LED behind 220 ohms on pin 3, with two buttons on pins 4 and 5 on a half breadboard. From the sending lesson on, a second Uno plays the TV: its own VS1838B on pin 2 and a 16x2 I2C LCD for a screen, with the LED's beam landing on its receiver.
The lessons
Carriers and light. The LED lit three ways onto the receiver: steady (seen as nothing), 38 kHz (seen for the whole burst) and 56 kHz (outside the band, nothing). Then the band is found by changing the carrier.
The NEC protocol. No library: the sketch times every burst and gap with
micros(), finds the 9 ms leader, reads 32 bits least significant first,
checks the inverted address and command bytes, and spots repeat frames. A
logic analyzer shows the frame, and moving the split point breaks it.
Decoding with IRremote. A mission console: each number key flies to a planet, and the LCD shows the light-minutes from the Sun. What the library takes from the Uno (timer 2) is spelled out.
Sending. Two buttons make a remote: IrSender.sendNEC() changes the TV's
channel and volume, and a different address makes the TV ignore it.
A learning remote. LEARN, a key on the handset, then PLAY sends the same frame to the TV, and why a board stops its own receiver while it sends.
Repeat codes. The TV's side of a held key: repeats ramp the volume, channels step once per press, and a let-go is noticed when repeats stop.
Boss: a universal remote. The TV speaks the Samsung protocol at address 0x07 and ignores the handset. The Uno translates each NEC key through a table, turns held keys into Samsung repeats, runs a movie-night macro, and gets a key mapped by you.
The sketches
| Sketch | What it does |
|---|---|
irxcarrier |
Lights the LED steady, at 38 kHz and at 56 kHz and times the receiver's answer |
irxnec |
Reads NEC by hand and prints the leader, the bits and the check bytes |
irxdecode |
IRremote decoder with an LCD: the mission console |
irxsend |
Two-button NEC remote on pin 3 |
irxtv |
The pretend TV: NEC address 0x00, channel and volume on its LCD |
irxlearn |
Learns one code and sends it again |
irxrepeat |
A TV that reports every new press, repeat and let-go |
irxtvsam |
The pretend TV again, listening for Samsung at address 0x07 |
irxuniv |
The universal remote: NEC in, Samsung out |
What the simulation leaves out
The light between the handset or LED and a receiver is drawn as a wire, so there is no distance, angle or sunlight. Leave a receiver's IR pin unwired and Mokxi sends an LED's light through the air on the canvas instead, by where the parts point. The receiver passes carriers from about 33 to 44 kHz, models no automatic gain control, and treats any LED current above 1 mA as light. The handset sends NEC only. The I2C bus to the LCD is slower than on a real Uno, so the TV sketches redraw the screen only once the remote goes quiet.
Related
The IR LED and character LCD part pages, and Displays: characters, digits and dots.