IR Receiver bugging ?

Hi, i'm quite new to the Arduino universe and I wanting to try playing around with an IR Receiver but when I tried it, it keeps giving the same message "IR code : 0x0".
While this is in the serial monitor and the "IR code : " part is normal, the 0x0 isn't and it appears even though I didn't press anything on my remote.
Can you please help me ?
By the way, here's my code :


#include "IRremote.h"

int receiver = 11;

/*-----( Declare objects )-----*/
IRrecv irrecv(receiver);     // create instance of 'irrecv'
//vairable uses to store the last decodedRawData
uint32_t last_decodedRawData = 0;
void translateIR() // takes action based on IR code received
{
  // Check if it is a repeat IR code 
  if (irrecv.decodedIRData.flags)
  {
    //set the current decodedRawData to the last decodedRawData 
    irrecv.decodedIRData.decodedRawData = last_decodedRawData;
    Serial.println("REPEAT!");
  } else
  {
    //output the IR code on the serial monitor
    Serial.print("IR code:0x");
    Serial.println(irrecv.decodedIRData.decodedRawData, HEX);
  }
  //map the IR code to the remote key
  switch (irrecv.decodedIRData.decodedRawData)
  {
    case 0xBA45FF00: Serial.println("POWER"); break;
    case 0xB847FF00: Serial.println("FUNC/STOP"); break;
    case 0xB946FF00: Serial.println("VOL+"); break;
    case 0xBB44FF00: Serial.println("FAST BACK");    break;
    case 0xBF40FF00: Serial.println("PAUSE");    break;
    case 0xBC43FF00: Serial.println("FAST FORWARD");   break;
    case 0xF807FF00: Serial.println("DOWN");    break;
    case 0xEA15FF00: Serial.println("VOL-");    break;
    case 0xF609FF00: Serial.println("UP");    break;
    case 0xE619FF00: Serial.println("EQ");    break;
    case 0xF20DFF00: Serial.println("ST/REPT");    break;
    case 0xE916FF00: Serial.println("0");    break;
    case 0xF30CFF00: Serial.println("1");    break;
    case 0xE718FF00: Serial.println("2");    break;
    case 0xA15EFF00: Serial.println("3");    break;
    case 0xF708FF00: Serial.println("4");    break;
    case 0xE31CFF00: Serial.println("5");    break;
    case 0xA55AFF00: Serial.println("6");    break;
    case 0xBD42FF00: Serial.println("7");    break;
    case 0xAD52FF00: Serial.println("8");    break;
    case 0xB54AFF00: Serial.println("9");    break;
    default:
      Serial.println(" other button   ");
  }// End Case
  //store the last decodedRawData
  last_decodedRawData = irrecv.decodedIRData.decodedRawData;
  delay(500); // Do not get immediate repeat
}

void setup()
{
  Serial.begin(9600);
  Serial.println("IR Receiver Button Decode");
  irrecv.enableIRIn(); // Start the receiver

}


void loop()
{
  if (irrecv.decode())
  {
    translateIR();
    irrecv.resume();
  }
}

Run the examples that come with the IRremote library.

1 Like

i think it is wrong

Hi @cheetcorn,

this a list of the recent flags as found on

https://github.com/Arduino-IRremote/Arduino-IRremote/tree/master

Not all of the flags are related to repeated IR data ...

And you might try the newer functions instead of the older ones.

Here are links from the github page to Wokwi

https://github.com/Arduino-IRremote/Arduino-IRremote/tree/master#examples-for-this-library

that may be of assistance (e.g. this one https://wokwi.com/projects/338611596994544210 ) to check it out ...

Good luck and have fun!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.