Decoding an IR remote pulse - What are the limits of pin change handlers and pulse count periods?

I needed to add a keypad to an imp project so I literally cut off the numeric keypad portion of a spare consumer IR remote control and tapped into the 3V logic level control signal to the IR LED. This gives me a unique pulse pattern per key. The pattern is ~1msec long bursts of 37KHz pulses. I hoped to trigger on pin change and use hardware.micros() or and PULSE_COUNTER mode to decode these signals.

However, it seems that the imp is too slow to catch a consistent time period accurate to < 0.5msec. Is this an accurate assessment? What is the smallest PULSE_COUNTER period I can use? If I call on a PULSE_COUNTER pin back to back what is the delay I can expect between calls?

I’m about to just add an ATTINY to decode the signals and forward on to the Imp. Is there a better way?

We actually have a reference design (and some code) to do exactly this :slight_smile:

Take a look at the Sana reference design. The IR Receiver class (which is one of the pieces of code linked to from that page) should be a good starting point.

Using a demodulator chip is sort-of cheating, though :wink: but it is probably the only way to get the decoding fast enough in Squirrel. The other option would be to try and use the sampler, but you’d either have to sample really fast (74KHz) or use some icky analogue filtering. Springing for the demodulator chip has to be the recommended answer…


Pretty much everyone uses a demodulator; if you don’t then there’s a lot of gain control you need to do, etc - I’ve never seen anything that didn’t use one, in fact :slight_smile:

I’m going to try this tonight. Of course, I was wiring this keypad in directly. Now I have to add an IR LED next to the receiver inside my box. I am probably going to regret not using an ATTiny or MSP430 and just writing my own keypad scanner.

A long overdue update.

The code for the IR Receiver Class from Sana worked great. Thanks!

Of course it means I have an IR transmitter and IR receiver inside my closed box, but Hey, it works.

And if I expose the IR receiver I have a handy remote input to automate tests.

Hi! The code that I receive using the receiver class from sana’s github codes shows different outputs everytime the same button is pressed but the arduino doesn’t. Any inputs on why is this happening? I have only modified the thresholds since the 800 and 1800 microsecs showed only 0’s. My current thresholds are 550 and1650 microsecs.

I finally finished a Sana and noticed the same thing. It looks like the GitHub code is for a different revision of the board. That might only mean pin changes though. I connected the transmitter and receiver to my scope and the output look good… I’m a little lost when trying to decode input pulses though.