Introduction: Infrared Protocol Decoder With Arduino

About: A fellow tinkerer.

Infrared communication is an easy way of wirelessly transmitting signals. A normal set up consists of a receiver and an emitter. The emitter works like a normal LED, only the light that it emits is not visible to the naked eye (most cameras can detect it though). The receiver then listens for any signals and converts the received signal into a binary message consisting of HIGHs and LOWs (5v and GND). The duration and time between bursts of signals dictate the protocol used and the message sent. Whether for another project or just for general curiosity, knowing which protocol your remote communicates with is always helpful.

This project will use the infrared decoding, receiving, and sending library IRLib2 which can be found here.

Read more about IR here.

Step 1: Build the Circuit

Since this is a simple circuit, start by building it. Looking at the circuit, we notice it only has one component, the IR decoder. The IR decoder, like many components, is simply a bunch of parts combined into one. In the image above, you can see that the IR decoder has a demodulator, which turns the messy square wave output into complete 5V pulses. In the third image, you can see the wave signal that the Arduino will receive.There are complex protocols and identification procedures in place that turn simple pulses into actual binary digits.

The IR decoder has 3 pins, one for GND, one for VCC and another one for the signal output. Your Arduino microcontroller is responsible for reading the signals coming from it. Therefore your code must also reflect this and constantly scan for signals. Precision is of the essence; if you miss one signal the entire message could be misinterpreted or even not read at all. To ensure accuracy, use a library that has been extensively tested in your code.

Note: I'm using a TSOP4838 IR decoder - depending on which one you have the pin layout might be different. Always double check!

Obtain the datasheet for the component here.

Step 2: Software

After installing IRLib2 (open the ZIP file from GitHub, drag the 5 folders into the libraries folder of your Arduino root install), use the dump example sketch (file>examples>IRLib2>dump) to test the receiver.

You can obtain verbose output by providing the Decoder object .dumpResults() function with a boolean true. This gives you information about the duration of the pulses and the time between them. The first line tells you the protocol used and its number, followed by the value of the message which you can then access in your code by using the Decoder object .value attribute.

In the code above, we create two objects of the IRLib2 library, a decoder, and a receiver. The receiver object is solely responsible for taking the voltage pulses from the receiver component and measuring time details. Then the decoder interprets this data and assigns it a value and a protocol based on the receiver data. The decode() function gets the data from the receiver, after we know it's there since the getResults() function has returned true, and does the rest for you.

Step 3: Test the Circuit

Now that everything is working, it's just a matter of using different remotes, examining the protocols, the data and seeing if long presses make any difference for the value (hint: RC5). Try all the buttons and see how the value has to do with the previous value. You might get an unsupported protocol but that's OK, just switch to another remote.

This part is a lot of fun so get clicking!

Step 4: Closing Thoughts

Infrared communication is extremely useful for simple data transmission for a project. However, you must be aware of its limitations:

- It can be easily blocked by any opaque object

- It does not have a very long range

- IR light is readily available in our atmosphere and can easily interfere with your signals

Make sure that you are aware of these limitations when choosing IR as your communication format.

In this tutorial, you learned how to use a TSOP4838 Infrared receiver (or equivalent) to decode signals coming from an IR led in your remote.

Please favorite and comment if this was useful!