Lightweight Arduino IR library for normal NEC protocol remote control devices.
If you have one of these cheap remote control units, with a matching IR receiver, you may find this library useful. It is specifically designed for the NEC IR protocol. Unlike the standard IR library, it does not use a timer and instead uses external interrupts. Its design based on a state machine model.
When compiled for a Uno, it uses 214 bytes of global variables and 3356 bytes of program storage space which is about half of the storage requirements of the more comprehensive standard Arduino IR library.
I've tested it on a Uno, an ATtiny841 (8 MHz internal) and a NodeMCU ESP8266. With the AVR processors, you are restricted on which pins you can use because of the external interrupts. If you cannot use an external interrupt pin, it should, however, not be too difficult to modify the code to use pin change interrupts instead.
There is a description of the NEC protocol here: NEC IR Remote Control Interface with 8051 - Tutorials or a more comprehensive one including extended codes and repeat https://www.ad-notam.com/download/RS232/ad_notam_IR_protocol_DFU.pdf
I've attached a sample demonstration sketch and the 2 parts of the library ( IrNec.cpp and IrNec.h) which can be added to the sketch folder.
Edit 1 : IrNec.cpp and IrNec.h updated to support repeat code (0xFFFFFFFF) and IR code byte order corrected.
AT841_IR_v0_01.ino (1.01 KB)
IrNec.h (1.04 KB)
IrNec.cpp (3.74 KB)
I Found my problem. I am using the example using the "lightweight IR library" with a ESP-32 Wroom-32D. First time I testes it there was not a problem up loading the code. I connected the sensor and all went well. When I did a minor change to the code It refused to upload again, and again. I tried everything, even using a new ESP, sensor and new USB cable. FINALLY FIXED by removing the sensor from Port 2, IO02,... I do not know why, but this fixed it. Does anyone know why ????
Its not clear if you really mean that it is an uploading issue, a compilation issue or merely that the code does not work. Anyway, it appears you already have some sort of solution.
The ESP is a bit special in that certain pins may not be pulled high at boot time. For which pins to use see: ESP32 Pinout Reference: Which GPIO pins should you use? | Random Nerd Tutorials
On the ESP an interrupt service routine should have the qualifier: IRAM_ATTR see. What is and when to use IRAM_ATTR ? - ESP32 Forum
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.
Hi the file that you provided shows only the code. Does IrNec have like a feature that can tell which device it's sending from for ex. NEC,SAMSUNG?
That library is only an IR receiver. It cannot send IR data. Further, it can only receive data from remote control devices which use the NEC protocol. The NEC protocol is very common, especially for cheap devices such as illustrated in the OP, but it is certainly not the only one.