IRRemote with Nano

Im using IRremote (4.5.0) on an Nano clone. It works but not 100% of the time. Sometimes it misses a code.

I have scoped the power rail and also the data into the Nano, both are good, its just that the Nano sometimes doesn't catch the code.

I've stripped my code to the bare minimum shown below.

Any insights or is this normal Nano behaviour?

void loop()
{
if (IrReceiver.decode())
{
ircode = (IrReceiver.decodedIRData.decodedRawData);

 if ((ircode == 5179) || (ircode == 7227))
 {
   digitalWrite(11, HIGH); //Green LED On
   digitalWrite(12, LOW);  //Red LED Off
 }
 else if ((ircode == 5180) || (ircode == 5438) || (ircode == 5950) || (ircode == 7486) || (ircode == 7998) || (ircode == 6462) || (ircode == 7230) || (ircode == 4414))
 {
   digitalWrite(11, LOW);  //Green LED Off
   digitalWrite(12, HIGH); //Red LED On
 }

}

IrReceiver.resume();

}

Are you sending IR signal from a TV Remote Control? Please, post the picture of your Remote Control and also the Model.

Have tried multiple remotes all with the same symptom. Works but with failures.

Try the following sketch:


#include <IRremote.h>

IRrecv irReceiver(9);  // Create an IR receiver object on pin 11
decode_results results;

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

void loop() 
{
  if (irReceiver.decode(&results)) 
  {  // Check if there's an IR signal
    Serial.println(results.value);   // Print the value of the received signal
    irReceiver.resume();              // Prepare to receive the next signal
  }
}

I could not get your code to run, however I have already tried an equivalent to get the codes in the first instance. This seems to have the same behaviour, mostly works but will miss random instances.

#include <IRremote.h>

#define IR_RECEIVE_PIN 6
long ircode = 0;

void setup() 
{
  Serial.begin(4800);
  IrReceiver.begin(IR_RECEIVE_PIN, DISABLE_LED_FEEDBACK);
}

void loop() 
{
  if (IrReceiver.decode())
  {  // Check if there's an IR signal
  ircode = (IrReceiver.decodedIRData.decodedRawData);
    Serial.println(ircode);   // Print the value of the received signal
    
  }
  IrReceiver.resume();              // Prepare to receive the next signal
}

Why? Is it not compiled? What are the error messages?

Compiled and uploaded but zero output on the serial monitor

Please, post a picure of the Remote Control you have used with my sketch. I want to see the Model.

I have tried multiple remotes, all with the same behaviour.

I now get an error message with your code saying it is for version 2.0 of IRRemote and is no longer supported. Im using rev 4.5.0

Try and let me know. Why are you not posting the picture of your Remote Control? Take a picture by your mobile camera and post here.

Why is it relevant?

As I've said, I have tried multiple remotes. One example is the Samsung BN59-01175N TV Remote Control

Why are you dismissing advice?

I don't believe I have?

Does it depend on distance? I.E. if you hold the remote a few cm from the receiver on the Nano does it work reliably?

My sketch works with this model: 2207 SMART (Colone of SONY).

Distance doesn't matter. On the scope I can see a perfect input stream to the Nano. Just sometimes it doesn't see it.

Have used the same library with ESP32 without issue so I'm really questioning if there is some quirk with the Nano, and especially Ali Express variants.

Can you show the connection diagram of your IR receiver circuit with your NANO?

IRremote 4.x on ATmega328P uses Timer2. If any part of your project or libraries (Servo, tone, PWM on pins 3/11, etc.) use Timer2, decoding becomes unreliable.

You are using digitalWrite(11). If pin 11 ever had PWM enabled before, that uses Timer2. Normally digitalWrite() disables PWM, but clones sometimes fail to fully reset Timer2 states.

Use the ReceiveDemo example and you will see the reason for skipped code in the Serial output

I wonder how they fail..?