Page 1 of 1

NEC Infrared receiver class

Posted: Mon Apr 27, 2015 1:24 pm
by MattMatic
(Hope this is the right place THIS time :D )

Just threw together a little library in about an hour that will let you capture infrared remote values according to the NEC protocol.
(The type available on eBay under "Arduino infrared remote")

(NOTE: You may need to use a 10k pull-up resistor for the TL1838, otherwise you can get spurious triggers if just relying on the pyboard pull-up)

Essentially does a capture timer of the high-pulses (no-IR) and handles the bitstream. When a completed 32 bits have been received, and they all tally (Address + NOT Address + Command + NOT Command) then it issues the callback function.

Enjoying the speed of Python development :D


Re: NEC Infrared receiver class

Posted: Mon Apr 27, 2015 2:49 pm
by photoacoustic
Thank for this code.
this code will help me for understanding Timer with input capture! :)
I have a phototransistor for DC motor speed measurement
best regards

Re: NEC Infrared receiver class

Posted: Mon Apr 27, 2015 8:04 pm
by MattMatic

Re: NEC Infrared receiver class

Posted: Mon Apr 27, 2015 8:40 pm
by dhylands
I'm also coding up some Tachometer code in the next few days.

I'm going to port some code I wrote for an ATTIny45:

Re: NEC Infrared receiver class

Posted: Tue Jun 02, 2015 7:40 pm
by ubuntourist
I'm all-thumbs with analog electronics.

I'm looking at two IR receivers. Bricks? The brands are Keys one is Xlnda but they look identical. One has a constantly flickering red LED on the board and the other has a solid red LED. (I think the solid red one is broken from an incorrect connection when first plugged in. A colleague said he "heard and smelled" it. But he seems to feel that "solid red" is better than "flickering red".)

To test both, we've got a remote for an overhead SmartBoard projector, which definitely works. However, we cannot get either receiver to detect anything. (I've downloaded the library listed in the thread and run the example code, connecting signal to X4 on the PyBoard. All I see is a constantly repeating "0 0 True".) I added in the 10K pull-up resistor (between "S" on the brick and X4 on the PyBoard, yes?) but that didn't appear to change anything.


Re: NEC Infrared receiver class

Posted: Fri Jun 26, 2015 8:38 am
by MattMatic
There are many protocols for IR transmitters.

I only implemented the NEC format.

An output of 0,0,true indicates zero address, zero command, and a repeat.
It's likely your remotes are not NEC format - the repeat signal in NEC format is simply an IR pulse. The command and data, on the other hand, are verified since the frame contains both the 8-bit binary of each and the 8-bit inverse of each.

So, it's possible to get 'repeat' triggers from other brand remotes or false positives.

You'd need to get a storage scope out to see what the protocol is. This page might help:


Re: NEC Infrared receiver class

Posted: Tue Nov 19, 2019 2:31 pm
by ajocius
Is this possible to read signal from remote controls laying around at home using your code MattMatic? I would like to read signal from AV receiver remote control, then use it with IR transmitter connected to ESP32 to automate AV receiver, so that I can for example turn on AV receiver using voice command or some other trigger. I have looked into github but was not sure how to implement it. Should I copy code into ESP32 and then address it from using:

Code: Select all

def nec_cb(nec, a, c, r)
        print(a, c, r)				# Address, Command, Repeat

    from necir import NecIr
    nec = NecIr()
I am not sure how will ESP32 know what PIN has IR receiver or transmitter connected. Do you have some working code example that I could follow? Too many questions, but I can't figure out how it works.

Re: NEC Infrared receiver class

Posted: Thu Nov 21, 2019 6:59 am
by mcauser
Not every remote uses the NEC protocol. There's a bunch of different protocols. If you know the model number of your AV devices, there's a few sites which list 1000s of the IR devices, which protocols they use and what each button sends. Otherwise, there's some scripts which let you capture what each button sends.

There's stacks of sites like this:

It's definitely possible to have an ESP32 with an IR LED pointed towards your AV receiver and have it blink out the appropriate commands.
If you have an IR receiver on your ESP32, you could use it to relay commands, or just accept web traffic / mqtt to issue commands.

MattMatic's driver is specific to the Pyboard, as it uses pyb.Timer. There is an ESP32 equivalent. Will need some refactoring.

Have you seen Peter Hinch's driver? It's working on the ESP32 and uses asyncio. ... ter/nec_ir

Re: NEC Infrared receiver class

Posted: Thu Nov 21, 2019 9:58 am
by ajocius
Haven't tried, thanks for sending link, will test out! Do you know if this also sends IR signal out? Or is it just receiver?

Re: NEC Infrared receiver class

Posted: Thu Nov 21, 2019 1:46 pm
by pythoncoder
Mine is just a receiver.

A TX is some way down my long TODO list. Please don't hold your breath waiting...