ArduinoIR remote library modification to include interrupt

Just a quick update today, messing with a little project and I did a performance test on the ArduinoIR library, it is very slow taking 2ms to poll the IR pin so I figured why not just include an interrupt and trigger the polling of the pin using the pin! simple fix and removes the 2ms lagg from the program loop while avoiding missing any button presses!

of course you will need the ArduinoIR library to do this. You can get it here.
The below will output the IR code HEX to your serial pin. It’s basic but does the job without holding up the program loop!

#include <IRremote.h>

int RECV_PIN = 2;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  attachInterrupt(0,CHECK_IR,CHANGE);
  irrecv.enableIRIn(); // Start the receiver

}

void loop() {
 delay(500);
}

void CHECK_IR(){
  while(irrecv.decode(&results)){
  Serial.println(results.value, HEX);
  irrecv.resume();
  }
}


Share

Tags: , , , ,

One Response to “ArduinoIR remote library modification to include interrupt”

  1. Joaquin Eduardo Arreguez April 18, 2015 at 6:08 am #

    There is a problem with this code that I cannot figure how to solve:
    When you send something to re IR receiver, the code does print it on Serial port, but if you send another (different) signal, the first time you do it the result in Serial port is the same as the previous one.
    Example: “A” code is “FF30CF” ; “B” code is “FF7A85”
    Press “A” -> result: “FF30CF”
    Press “B” -> result: “FF30CF” —–> Wrong
    Press “B” -> result: “FF7A85” —–> The second (or even more) time I press “B” it gives the right value.

    Any Ideas on that??

Leave a Reply