A simple infrared (IR) sniffer

Post your cool example code here.
Post Reply
Posts: 2049
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

A simple infrared (IR) sniffer

Post by stevestrong » Sat Oct 07, 2017 4:43 pm

HI all,

I am currently involved with a small project which should detect (but not necessarily decode) different, not known IR signals.
Therefore I wrote a small sketch to print out the received data in form of a list of pulses including their time period.
My sketch uses timer 2 for measuring timer counts between two consecutive interrupts generated by the input GPIO signal.
The timer runs with a 1us clock (after the prescaler), so that the counts directly reflect the time in microseconds.
The data processing takes place only after a complete pulse train has been received, detected by a timeout of 15ms (adjustable, set a bit larger than the longest possible period) after the last detected signal transition. In this way the processor is not loaded with any unnecessary tasks in the ISRs.
It uses dual buffer to store the received timer counts in an alternate way, so theoretically one could easily change the sketch to detect repeated commands (signals with same timeline geometry and similar timings).

A typical output looks like this:

Code: Select all

Total pulses: 15
 0 1 0 2 2 2 0 0 2 2 0 0 0 0 2
 0=510 1=2580 2=1023
The last two rows is the timeline of the detected pulses: a short pulse (usually the start bit) marked as "0" having a period of 510us (see last row), followed by a second pulse marked as "1" having a time period of 2580 us, and so on.
The detected levels are not recorded, but they are obviously alternating from high to low and from low to high in a sequential order.
The values shown in the last row are averaged values (if more than one similar value available).
The error margin to identify a pulse which period has been already received is set to +-15%, can be changed if needed.

Happy sniffing!
(4.94 KiB) Downloaded 53 times

User avatar
Posts: 566
Joined: Mon Apr 27, 2015 2:28 pm
Location: Mt.Etna, Italy

Re: A simple infrared (IR) sniffer

Post by zoomx » Wed Oct 11, 2017 7:53 am

Thanks for sharing!

If you want to decode Air Conditioner remote you have to increase the array buffer at about 800 like this sketch
http://www.analysir.com/blog/2014/03/19 ... -arduino/ (link at the bottom)
because these remote signals are very long.

Post Reply