Remote controls such as those used for your TV, DVD/Blu-ray or Cable box use infrared transmitters and receivers. The transmitter is basically nothing more than flashlight that emits a light beam at a frequency that is lower than the human eye can detect. The remote control sends out a specially timed sequence of pulses to transmit data to your TV or other device. Each consumer electronics device manufacturer has its own set of protocols for these signals so that the signals intended for your TV for example do not interfere with those intended for your Blu-ray or cable box. Even within a single manufacturer there are special codes that make sure you only control the device you want to control.
When the IR LED is on for a brief period of time we call that a "Mark" and the period of time when it is off we call a "Space". A complete sequence of Marks and Spaces is referred to as a "frame" of data. The timing of these marks the spaces encodes the data we want to transmit. However the marks themselves are actually a modulated signal. Typically this is that about 38 kHz however some protocols use frequencies ranging from 36 kHz to 57 kHz. Modulating the signal ensures that other sources of infrared emission such as sunlight, light bulbs, or just the normal heat coming off of objects is not interpreted as part of the signal. The receiver must demodulate the signal and produce a clean square wave so that we can time the length of the off and on pulses. Your Circuit Playground Express includes a circuit that will demodulate the 38 kHz signals and turn them into a clean square wave that we can sample to understand the data.
Here is an illustration of how these signals are actually transmitted and how they look after they have been demodulated.
The signal usually starts with a very long mark and space. This header information helps identify the protocol and it allows the automatic gain control circuit in the receiver to adjust to the level of signal it is receiving. Then comes the data bits. In this example all of the marks are the same length but the variation of the length of spaces tell you whether it is a logical "1" bit or a logical "0" bit. Some protocols vary the length of marks and use fixed length spaces. Others vary the length of both marks and spaces. And still others use the transition from low to high versus high to low to designate a "0" or "1" bit.
Fortunately for the end user like you, the IRLib2 library takes care of all these details for you. If you are using one of our supported protocols, you don't need to know anything about the timing of the signals or how to interpret the patterns. The software takes the stream of pulses, decodes it, tell you what protocol it is using, how many bits of data in the signal, and then gives you an unassigned integer value up to 32 bits long that uniquely identifies the signal that was sent. You can also use these 32-bit integers in the sending portion of the software and it will re-create the string of marks and spaces in the proper protocol.
If you encounter a protocol that is not supported by IRLib2 there is an extensive section in the users manual that tells you how to analyze received data so that you can write your own decoder and encoder to support a new protocol. IRLib2 currently supports 12 protocols and many of those have variations within them. We are constantly adding support for new protocols and they will be incorporated into the library once they are tested and stable.
In the next section we will show you how to install the software and receive and decode an IR signal on your Circuit Playground Express.