Infrared (sometimes called infrared light and IR) is electromagnetic radiation (EMR) with wavelengths longer than those of visible light and shorter than radio waves. It is therefore invisible to the human eye. IR is generally understood to encompass wavelengths from around 1 millimeter (300 GHz) to the nominal red edge of the visible spectrum, around 700 nanometers (430 THz).
(Courtesy of Wikipedia)
A typical IR sensor and a remote control pictures are provided below.
The OUT leg of the IR sensor is connected to the microcontroller pin that will be doing the sensor readings. The microcontroller pin number that is used to connect the sensor is also the pin number used in the library attach block.
(courtesy of techdocs.altium.com)
The NEC IR transmission protocol uses pulse distance encoding of the message bits. Each pulse burst (mark – RC transmitter ON) is 562.5µs in length, at a carrier frequency of 38kHz (26.3µs). Logical bits are transmitted as follows:
Logical '0' – a 562.5µs pulse burst followed by a 562.5µs space, with a total transmit time of 1.125ms
Logical '1' – a 562.5µs pulse burst followed by a 1.6875ms space, with a total transmit time of 2.25ms
When a key is pressed on the remote controller, the message transmitted consists of the following, in order:
a 9ms leading pulse burst (16 times the pulse burst length used for a logical data bit)
a 4.5ms space
the 8-bit address for the receiving device
the 8-bit logical inverse of the address
the 8-bit command
the 8-bit logical inverse of the command
a final 562.5µs pulse burst to signify the end of message transmission.
The four bytes of data bits are each sent least significant bit first. Figure 1 illustrates the format of an NEC IR transmission frame, for an address of 00h (00000000b) and a command of ADh (10101101b).
Notice from Figure 1 that it takes:
27ms to transmit both the 16 bits for the address (address + inverse) and the 16 bits for the command (command + inverse). This comes from each of the 16 bit blocks ultimately containing eight '0's and eight '1's - giving (8 * 1.125ms) + (8 * 2.25ms).
67.5ms to fully transmit the message frame (discounting the final 562.5µs pulse burst that signifies the end of message).
REPEAT CODES
If the key on the remote controller is kept depressed, a repeat code will be issued, typically around 40ms after the pulse burst that signified the end of the message. A repeat code will continue to be sent out at 108ms intervals, until the key is finally released. The repeat code consists of the following, in order:
a 9ms leading pulse burst
a 2.25ms space
a 562.5µs pulse burst to mark the end of the space (and hence end of the transmitted repeat code).
Figure 2 illustrates the transmission of two repeat codes after an initial message frame is sent.
For each block, there is a short description entry and a detailed block and component description. You can click on block pictures in the short description table to access the details and sample codes.
Sample codes on how to use the blocks have been provided. To try them out, all you have to do is open a browser session of the MicroBlocks IDE and drag and drop them onto the editor programming area. Then you can just click on them and see the results.
To test any of the sample codes below, just drag and drop them onto the MicroBlocks IDE.
The library consists of a set of simple services, that together allow the user to utilize an IR Remote control.
IR Remote Library has two distinct types of block shapes:
oval: these are reporter blocks that return some kind of information back. The user would normally either assign these to a project variable or use it in a suitable input slot of other blocks. The return information type is a Number.
rectangular: these are command blocks that perform a programmed function and do not return any information.
In the examples provided below, pin number used in the attach IR receiver block is only applicable to the test setup used. Each user's own pin number may be different, depending on the sensor and/or microcontroller they are using.
The library provided by MicroBlocks specifically works with the controllers that operate using the NEC IR Protocol. There are many other other protocols in use. If your device does NOT use the NEC protocol, it will not work with this library.
This block waits for the next IR message and returns its IR key code. You need to point the IR keypad towards the IR sensor and press any buttons on it.
Associates the IR sensor with a particular pin on the microcontroller. All operations of the IR sensor library will be performed via this pin number.
Sends commands to an IR device number. The IR device number can be obtained using the block test IR, below.
Waits for the next IR message then displays the device number and the key received.
This example uses an Arduino remote control and displays its device code and the key code for the OK key pressed.
Reads the IR key code value from a specific remote control device number. Device numbers can be determined by using the test IR block.
Records a 68 byte sequence of IR message composed of mark and a space signal durations. It is an internal function to the library and no sample code is provided.
Print raw pulse timings to the Graph window. Can be used to analyze new protocols. First read a value from the remote control device. Then use this block to see the data. You can use the "copy graph data to clipboard" then paste the data into a text editor to see the pulse timings.
Reads a specified byte from the IR message frame. It is an internal function to the library and no sample code is provided.
Verifies that a complete IR Message frame has been received. It is an internal function to the library and no sample code is provided.
Transmits the specified byte value to the remote controller. It is an internal function to the library and no sample code is provided.