Understanding the Basics of Infrared Communications
2021-01-06 | By Maker.io Staff
Infrared communication is among the simplest wireless communication methods, and it serves as a cost-effective way of transmitting a few bits of data wirelessly. It’s safe to assume anyone reading this has used many different remote controls at home or work, and most of those simple devices communicate with the receiver via infrared pulses. This blog covers the basics of IR communications, and it explains two of the most commonly used IR protocols for controlling different devices.
How IR communications work
Infrared LEDs produce light that’s not visible to the human eye. Typically, the wavelength of light that such devices output is around 950 nanometers. However, IR LEDs aren’t the only thing that can emit IR or near IR waves. Many other sources, like light bulbs and the sun itself, release IR waves, which is one of the difficulties when dealing with IR communications.
Furthermore, anyone can send IR signals. Typically, no handshake, authentication, or authorization takes place between the sender and the receiver. A TV, for example, can be controlled by any remote that speaks the same language. In communications, language is referred to as a protocol, which is nothing more than an agreement between the sender and the recipient of the data. The two parties agree to follow a predefined pattern and transmit the information in a certain way.
The simplest method for transmitting binary values with an IR LED would be to turn the infrared LED on (to send a logical 1) or to leave it turned off (which could represent a logical 0) for a certain period. The sender could do this until all the data bits have been transmitted. Unfortunately, this won’t work in reality since many other sources emit IR radiation. The receiver would not be able to filter out unwanted signals from other sources.
To overcome this issue, the sender is required to pulse the LED on and off very quickly, instead of just turning it on and off. Typically, a frequency of 38,000 Hz is used, and this is also referred to as the carrier frequency of the IR signal. Note that other wavelengths and carrier frequencies are also possible — for example, 940 nm and 36 kHz. However, in reality, that doesn’t seem to be a problem. Most IR receivers will still work with slight variations in wavelength and carrier frequency.
The NEC IR transmission protocol
The technique of flashing the IR LED on and off to represent data bits has nothing to do with IR communication protocols. Such protocols describe how the data bits have to be laid out so that both parties can understand what they mean.
The popular NEC protocol, for example, uses a technique called pulse distance encoding to distinguish between the two logic states. The standard NEC protocol uses a carrier frequency of 38 kHz. The logic states are encoded by using pulses of different lengths to distinguish between HIGH and LOW.
Images made by the author
Binary values are encoded as follows:
- Logical 1: a 562.2 µs burst followed by a 1.687 ms low period
- Logical 0: a 562.2 µs burst followed by a 562.2 µs low period
The message frame itself comprises the following components:
- A nine-millisecond leading pulse burst
- A 4.5 ms low period
- The 8-bit address of the device
- The logical inverse of the first eight bits
- The 8-bit command
- The logical inverse of the command bits
- A final 562.5 µs burst to signify the end of the message
The inverse of the address and command can be used as a checksum to verify that the two transmitted values are correct. Some remote controls, however, transfer a 16-bit address, and some of them even send 16-bit commands.
Note that different messages might have different transmission times. The NEC protocol also supports repeat commands which instruct the receiver to repeat the previous message.
This article omits the exact timings of such repeat commands for the sake of simplicity. When an IR receiver is hooked up to an oscilloscope, the transmitted bits can be observed:
The RC5 (Philips) protocol
Unlike the NEC protocol, Philips decided to utilize a Manchester encoding to distinguish between the logical bits in transmitted messages. Here, the order of the pulses and breaks characterize the bits. Furthermore, the RC5 protocol uses a 36 kHz carrier frequency, and all messages require the same time to be transmitted.
As the figure shows, the order of the pulses and blank phases determine whether a logical 1 or a logical 0 was transmitted:
- Logical 1: an 889 µs low period followed by an 889 µs burst
- Logical 0: an 889 µs burst followed by an 889 µs low period
The message frame itself consists of the following parts:
- Two start bits. Both must be HIGH
- A toggle bit, which can be used to detect repeated signals
- Five address bits
- Six command bits
Every message takes around 24.892 ms to get transmitted. As noted, the toggle bit can be utilized to detect whether the user presses a button repeatedly or whether it's being held down. Whenever the button gets pressed once, the toggle bit flips. When the button is being held down, the same message is sent to the receiver without changing the toggle bit.
Summary
Using IR LEDs and receivers for data transmission is a straightforward way of communicating wirelessly. The low transmission speeds of popular IR transmission protocols make this method easy to implement, even when using slow microcontrollers. The sender has to pulse the LED on and off to transmit data because many other objects emit IR radiation. Otherwise, the receiver wouldn’t be able to differentiate between actual messages and noise.
The NEC protocol uses pulse distance encoding to distinguish between logic states in transmitted messages. The message itself consists of a synchronization sequence, typically followed by an eight-bit address and command. The RC5 protocol uses Manchester encoding to differentiate the logic states. The message itself contains two starting bits, a toggle bit, five address bits, and six data bits. Both systems support repeat sequences that tell the receiver to repeat the last command.
We will dig into these concepts more in upcoming articles where we learn to harness the power of IR communication in our own how-tos and projects!
Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.
Visit TechForum