Arduino NEC IR remote control decoder

Arduino NEC remote control decoder circuit

After the decoding of an infrared remote control which uses RC5 protocol, now I’m going to decode a remote control uses NEC protocol (this example works with both NEC and extended NEC remote controls). Arduino RC5 decoder topic link:
Arduino RC5 IR remote control decoder

About the NEC protocol:
The complete extended NEC protocol message is started by 9ms burst followed by 4.5ms space which is then followed by the Address and Command. The address is 16-bit length and the command is transmitted twice (8 bits + 8 bits) where in the second time all bits are inverted and can be used for verification of the received message. The following drawing shows an extended NEC message example.

Extended NEC protocol message code

The NEC protocol uses pulse distance encoding of the bits. Each pulse is a 562.5µs long with carrier frequency of 38KHz. Logic bits are transmitted as follows:
Logic 0: 562.5µs pulse burst followed by 562.5µs space, with a total transmit time of 1125µs (562.5 x 2).
Logic 1: a 562.5µs pulse burst followed by a 1687.5µs (562.5 x 3) space, with a total transmit time of 2250µs (562.5 x 4).

NEC protocol modulation

Components Required:

  • Arduino board
  • IR remote control with NEC protocol
  • 16×2 LCD screen
  • IR receiver
  • 47µF capacitor
  • 10K ohm variable resistor
  • 330 ohm resistor
  • Protoboard
  • Jumper wires

Arduino NEC protocol decoder circuit:
Arduino remote control decoder circuit schematic is shows below.

Arduino remote control decoder circuit

Arduino NEC remote control decoder code:
Note that there is no remote control library used in this example. The software is fully based on hardware interrupts.
The IR receiver output is logic high at idle state (or while the remote control sends a space) and when it receives a burst it changes the output to logic low.

The message of the NEC protocol is 32-bit long, address (16 bits), command (8 bits), and inverted command (8 bits). Before the previous 32 bits there is 9ms burst and 4.5ms space.
A logic 1 is represented by 562.5µs burst and 562.5µs space (total of 1125µs) and a logic 0 is represented by 562.5µs burst and 1687.5µs space (total of 2250µs).
Keep in mind that the IR receiver output is always inverted.

I used Timer1 module to measure pulses and spaces widths, it is configured so that is increments by 2 every 1 us (1/8 prescaler).
The interval [ 9500µs, 8500µs ] is used for the 9ms pulse and for the 4.5ms space the interval
[ 5000µs, 4000µs ] is used.
The 562.5µs pulse is checked with the interval [ 700µs, 400µs ] .
For the 562.5µs or 1687.5µs space I used the interval [ 1800µs, 400µs ], and to know if its a short or long space I used a length of 1000µs.
In Timer ticks:
[ 9500µs, 8500µs ] = [ 19000 , 17000 ] ticks
[ 5000µs, 4000µs ] = [ 10000 , 8000 ] ticks
[ 700µs, 400µs ]    = [ 1400 , 800 ] ticks
[ 1800µs, 400µs ]  = [3600 , 800 ] ticks

The output of the IR receiver is connected to the external interrupt INT0 pin (Arduino pin #2) and every change in the pin status generates an interrupt and Timer1 starts calculating, Timer1 value will be used in the next interrupt, this means Timer1 calculates the time between two interrupts which is pulse time or space time. Also, Timer1 interrupt is used to reset the decoding process in case of very high pulse or space.
The decoding results are displayed on 1602 LCD screen.

Finally I made a small video shows how this project works in hardware circuit:

Reference:
http://www.sbprojects.com/

One comment

  1. Congratulations! What a perfect IR decoder software: small, good working and instructive.

    I built it today into my Si4735 radio project and within 3 hours the troubles with IRlib2 vanished. Machine code size shrunk by 3k bytes as well.

    However, there is one small bug in Your Arduino circuit:
    The 47uF capacitor in parallel to the IR receiver IC is quite useless until You put a 47 Ohm resistor into the 5V line between IR receiver IC and the Arduino. You may omit the capacitor entirely, if the wires are not too long.
    The software is robust enough to remove any erroneous impulses.

    Kind regards,
    Herbert

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.