[IR control] wrong decode

Hi guys,
I’m new in Arduino’s World.

I’m trying to turn on or off my led with a remote IR control (like the device i use to control my TV).
I read that the standard IR library included in arduino doesn’t work well, so I switched that library with the <IRremote.h> library.
It’s working fine, but I encountered some troubles with the decode; I tried to use my IR device to turn on my LED but with a distance of 50cm it doesn’t work. Arduino read the IR signal (rx led works) but my serial monitor doesn’t show anything decoded (only FFFFFFF).

I use this code:

#include <IRremote.h>
 
int RECV_PIN = 3; // the pin where you connect the output pin of TSOP4838
int LED = 7;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);   // you can comment this line
  irrecv.enableIRIn();  // Start the receiver
  pinMode(LED, OUTPUT);
}
 
void loop() {
  if (irrecv.decode(&results)) {
    // unsigned int value = results.value;   
    digitalWrite(LED, HIGH);   // turn it ON when button is pressed            
    
    Serial.println(value); // you can comment this line
    irrecv.resume(); // Receive the next value
  }
}

According to you, what could be the problem ? The IR decoder linked to arduino? The signal is received but is not decoded!
Sorry for my bad english, I’m italian.

Thank you,
Andrea.

Try this. You turn the led on but never turn it back off and the loop executes so often and so fast that you won’t see it without the delay. I modified your code to turn the LED on when IR code is received, keeps it on for a second and turns it off if no codes received.

#include <IRremote.h>
 
int RECV_PIN = 3; // the pin where you connect the output pin of TSOP4838
int LED = 13;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);   // you can comment this line
  irrecv.enableIRIn();  // Start the receiver
  pinMode(LED, OUTPUT);
}
 
void loop() {
  if (irrecv.decode(&results)) 
  {
    unsigned int value = results.value;   
    digitalWrite(LED, HIGH);   // turn it ON when button is pressed            
    delay(1000);  // ADDED DELAY TO SEE LED
    Serial.println(value); // you can comment this line
    irrecv.resume(); // Receive the next value
  }
  
  // ADDED ELSE TO TURN LED OFF
  else 
  {
   digitalWrite(LED, LOW);
  }
}

Hi, thank you for your advice.

The problem is not if the IR code is received (it works), but why at 50 cm or 2m the IR decode the same button with 2 differents codes (and often not the same)