Receiving And Decoding IR | Using An Infrared Library On Arduino

After the sketch has loaded, open your serial monitor and make sure it is set to 9600 baud. Aim your IR remote at the receiver and press a button. In this example we press the "Play/Pause" button on the Adafruit Mini Remote. The results were as follows:

Decoded NEC(1): Value:FD807F (32 bits)Raw samples(68): Gap:40826 Head: m8850 s44500:m500 s600 1:m550 s550 2:m500 s600 3:m550 s600 4:m500 s600 5:m500 s600 6:m500 s600 7:m550 s550 8:m500 s1750 9:m500 s1700 10:m500 s1700 11:m550 s1650 12:m550 s1700 13:m500 s1700 14:m500 s600 15:m550 s1700

16:m500 s1700 17:m500 s600 18:m500 s600 19:m500 s600 20:m550 s600 21:m450 s650 22:m500 s600 23:m500 s600 24:m500 s600 25:m500 s1700 26:m550 s1700 27:m500 s1700 28:m500 s1700 29:m550 s1700 30:m500 s1700 31:m500 s1700

32:m500Extent=65850Mark min:450 max:550

The important part of this dump is the first line. This tells us that the protocol detected was "NEC" which is protocol number "1" in IRLib's supported protocols. The data value received was the 32-bit hexadecimal value FD807F. The rest of the information is the raw timing data of the actual marks and spaces received. That information is useful in trying to understand and supported protocols.

This 32-bit number uniquely identifies the button that you pushed. If we push the Volume down and Volume up buttons on this remote we would get the values 0xFD00FF and 0xFD40BF.

Try pressing various buttons on a TV or DVD remote you might have lying around the house. If the top line says:

Decoded Unknown(0): Value:0 (0 bits)

this means that IRLib did not understand the protocol used by your remote. Here are some typical values from other remotes. I got these from the power button on a Sony DVD player, and the play button on my Scientific Atlantic DVR/Cable Box.

Decoded Sony(2): Value:74BCA (20 bits)Decoded Panasonic Old(5): Value:37990C (22 bits)

This shows that the DVD player used Sony protocol which is protocol number 2 and that it is a 20 bit protocol. The cable box uses Panasonic_Old protocol 5 which is 22 bits. Most protocols always use the same number of bits however some such as Sony have different versions which could use 8, 12, or 15 bits in addition to 20.

How It Works

Let's look at what's going on here. The receiver object listens to the IR sensor and when it sees a signal it starts measuring the timing of the marks and spaces. If a particular amount of time passes with no additional signals, it presumes that the data is complete and when you call My_Receiver.GetResults it returns "true". It passes the data to your decoder object. The decoder uses the timing information and the number of bits to see if it matches one of the supported protocols. If it succeeds, it returns "true" although in this sketch we did not bother to check that first.

You can access the protocol number in My_Decoder.protocolNum, the number of bits in My_Decoder.bits and the the decoded data value in My_Decoder.value.

At the top of the sketch we created the decoder object as type "IRdecode". This is a class which incorporates all 11 of the supported protocols. If you're using the library to control a device such as a servo or turn relays off and on, you probably are going to be using one remote with one protocol. Once you know which protocol you are using, you may wish to use a different decoder class that only works for your particular protocol. It can save valuable program space in your sketch. For example if we were using the Adafruit Mini Remote which uses NEC protocol would change line #7 to read:

Tag » Arduino Ir Remote Library Documentation