An unused TV remote can become a set of buttons for a timer, media controller, or desk gadget. The receiver reports pulse timing; the decoding library identifies a protocol, address, and command. This is more useful than copying raw numbers from someone else’s remote.
Check the pinout first
| Connection | Destination or purpose |
|---|---|
| Receiver supply | 5 V only if the actual receiver or breakout supports it. |
| Receiver ground | GND. |
| Receiver signal / OUT | D2. |
Similar receiver packages can have different lead orders. Follow the part datasheet or breakout markings. If a bare receiver requires a bypass capacitor or other supply filtering, fit those parts as its documentation specifies; using a documented breakout avoids guessing.
Install the library and capture commands
Install IRremote by Armin Joachimsmeyer and contributors through Library Manager. This example uses its 4.x API and IRremote.hpp, rather than the older IRrecv/decode_results examples.
Download the complete Arduino sketch
#include <IRremote.hpp>
const byte receiverPin = 2;
void setup() {
Serial.begin(9600);
IrReceiver.begin(receiverPin, DISABLE_LED_FEEDBACK);
Serial.println("Press a remote key; record protocol, address, and command");
}
void loop() {
if (IrReceiver.decode()) {
IrReceiver.printIRResultShort(&Serial);
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT) {
Serial.println("Held-key repeat");
}
IrReceiver.resume();
}
}
Open Serial Monitor at 9600 baud. Press and release a key, then hold it. Make a small table of the protocol, address, and command for the few keys your project needs. Some protocols have special repeat frames; the library marks these in the flags.
Map commands deliberately
For a toggle action, accept the matching protocol/address/command and ignore held-key repeats. For volume or a continuously adjusted value, repeats may be useful. A delay of half a second after every packet would hide information and make the controls sluggish, so the example immediately calls resume() to receive the next frame.
A raw decoded value may change format between library versions. Named fields are easier to explain and maintain. Keep the captured codes beside the project that uses them, and document the remote model if known.
Troubleshooting
- No messages: check the receiver pinout, battery, and whether the remote is infrared rather than Bluetooth or radio.
- Unknown protocol: inspect the library’s supported-protocol list and diagnostic examples. Not every air-conditioner or specialist remote uses a short standard command.
- Works only close up: remove strong sunlight, try a fresh battery, and verify the supply and carrier frequency.
- Compile errors mentioning old types: use the complete sketch and the 4.x library, not a mixture of two API generations.
Use this for convenient local control. Anyone with a compatible transmitter can imitate a command, so infrared is not a credential for a real lock. The IRremote project documents decoding, repeats, and migration from older examples.