Values strange when using IR receiver with interrupt pin

Hey,

I'm working on a project that i want to controll with an IR remote. to make have the comunication smooth I connected the IR receiver to D2 on my arduino nano so i could use the interrupt function. But when i try to read the remote(wich is an other arduino) it gives a bunch of strange values. It should be 0xA90. when i try to read the value without using the interrupt it works fine.

#include <IRremote.h>

#define interruptNumber 0
#define irPin 2

IRrecv irrecv(irPin);
decode_results results;
volatile int received = 0;

void setup() {
  irrecv.enableIRIn();

  Serial.begin(9600);

  attachInterrupt(interruptNumber, irReceive, CHANGE);
}

void irReceive() {
  if (irrecv.decode(&results)) {
    received = results.value;
    irrecv.resume();
  }
}

void loop() {
  Serial.println(received, HEX);
  delay(200);
}

This is what i get in the Serial Monitor

0
0
FFFFD67D
FFFFE923
FFFFE923
FFFF8600
FFFFD67D
FFFF8600
FFFFE923
FFFFE923
FFFF8600
FFFF8600
FFFF8600
FFFFE923
A90
FFFFE923
FFFF8600
FFFFE923
FFFFD67D
FFFFD67D
FFFFD67D
FFFF8600
FFFFE923
FFFFE923
FFFFE923
FFFF8600
FFFF8600
FFFF8600
FFFF8600
FFFF8600
FFFFD67D
A90
FFFFD67D
FFFF8600
A90
FFFFD67D
A90
FFFF8600
FFFF8600
FFFF8600
FFFF8600
FFFFE923
FFFFE923
FFFFE923
FFFF8600
FFFF8600
FFFF8600
FFFFE923
FFFFE923
FFFFE923
FFFF8600
FFFF8600
FFFFD67D
FFFF8600

Any help appreciated. Thanks.

How do you suppose that the IR library works? What mechanism do you think it uses to receive data?

If you said anything but "Interrupts, of course", you got it wrong. If you did say "Interrupts, of course", then please explain how you think interrupts will be triggered while your ISR is working.

Here is a library example of receiving IR commands without using an interrupt:

 /*
 * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
  delay(100);
}

This will loop until the following condition is true:
(irrecv.decode(&results))
Then print the results which have been collected.

If you want to process by an ISR, you would have to create a similar loop in that ISR, waiting until the results were there.
The problem is, as has already been pointed out, this would interfere will the collection of the very results you are waiting for.
The IR library uses a timer driven ISR with a period of 50 microseconds to process the sensor results, and this would be blocked while servicing your own ISR.

What are you trying to achieve by using an ISR here ?

Thanks for this info

But how do i read the IR input when i'm in an other loop.
For example I'm in a loop that plays an animation on a led matrix and i want to use receive the ir signal. how do i do that?

how do i do that?

You can call irrecv.decode() from anywhere.