<IRremote.h>

I am using the <IRremote.h> Library examples and no matter what example I use it compiles just fine and seems to upload ok, but the moment I turn on to "Serial Monitor" I get the error message as shown in the attached message.

I am using a generic IR receiver and Pin 12 as Data pin. I have tried to alter the line
"results.decode_type == NEC;"
but that line wont accept any changes.

Everything was working fine Yesterday but for some reason all the Arduino Libraries were removed and I had to re-upload the library files.

Farticus:
"results.decode_type == NEC;"
but that line wont accept any changes.

Please provide a detailed description of what you mean by that, including the full and exact text of any error or warning messages you might be getting.

Please provide a detailed explanation of why you think this line needs to be modified.

Farticus:
no matter what example I use

Please post one of the examples here. I can see that when they did the deprecation they also modified the examples, but I didn't look closely so I don't know if this is a matter of you using outdated examples, or if the person who did the deprecation didn't fully update them:

Farticus:
Everything was working fine Yesterday but for some reason all the Arduino Libraries were removed and I had to re-upload the library files.

Did you change the location or contents of your sketchbook folder (File > Preferences > Sketchbook location)?

The IRremote library was recently updated. Older code will not work with the new version (3.x) of the library. Read the Wiki in the IRremote library page.

Either change the old code to work with the new library or install an older version of the library to work with the old code. The older versions are available via the library manager.

Converting your 2.x program to the 3.x version

Now there is an IRreceiver and IRsender object like the well known Arduino Serial object.
Just remove the line IRrecv IrReceiver(IR_RECEIVE_PIN); and/or IRsend IrSender; in your program, and replace all occurrences of IRrecv. or irrecv. with IrReceiver.
Since the decoded values are now in IrReceiver.decodedIRData and not in results any more, remove the line decode_results results or similar.
Like for the Serial object, call IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); or IrReceiver.begin(IR_RECEIVE_PIN, DISABLE_LED_FEEDBACK); instead of the IrReceiver.enableIRIn(); or irrecv.enableIRIn(); in setup().
Old decode(decode_results *aResults) function is replaced by simple decode(). So if you have a statement if(irrecv.decode(&results)) replace it with if (IrReceiver.decode()).
The decoded result is now in in IrReceiver.decodedIRData and not in results any more, therefore replace any occurrences of results.value and / or results.decode_type (and similar) to IrReceiver.decodedIRData.decodedRawData and / or IrReceiver.decodedIRData.decodedRawData.
Overflow, Repeat and other flags are now in IrReceiver.receivedIRData.flags.
Seldom used: results.rawbuf and results.rawlen must be replaced by IrReceiver.decodedIRData.rawDataPtr->rawbuf and IrReceiver.decodedIRData.rawDataPtr->rawlen.
The old functions sendNEC() and sendJVC() are deprecated and renamed to sendNECMSB() and sendJVCMSB() to make it clearer that they send data with MSB first, which is not the standard for NEC and JVC. Use them to send your old 32 bit IR data codes. In the new version you will send NEC commands not by 32 bit codes but by a (constant) 8 bit address and an 8 bit command.

I have download what appears to be the latest IRRemote Library from GitHub,deleted all previous IRlibraries, then loaded the example........." Simple Receiver".

The example wont even compile with an error on the line:

... IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); ........

I am using an Mega 2560 Arduino with Pin read set to pin 12.

/*
 * SimpleReceiver.cpp
 *
 * Demonstrates receiving NEC IR codes with IRrecv
 *
 *  Copyright (C) 2020-2021  Armin Joachimsmeyer
 *  armin.joachimsmeyer@gmail.com
 *
 *  This file is part of Arduino-IRremote https://github.com/z3t0/Arduino-IRremote.
 *
 *  MIT License
 */

/*
 * Specify which protocol(s) should be used for decoding.
 * If no protocol is defined, all protocols are active.
 */
#define DECODE_NEC 1

#include <IRremote.h>

/*
 * Set sensible receive pin for different CPU's
 */
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)
// Serial output for Digispark boards is at pin 2
#  if defined(ARDUINO_AVR_DIGISPARKPRO)
#define IR_RECEIVE_PIN    9 // PA3 - on Digispark board labeled as pin 9
#  else
#define IR_RECEIVE_PIN    0
#  endif
#  if defined(ARDUINO_AVR_DIGISPARK)
#define LED_BUILTIN PB1
#  endif
#elif defined(ESP32)
int IR_RECEIVE_PIN = 15;
#elif defined(ARDUINO_AVR_PROMICRO)
int IR_RECEIVE_PIN = 10;
#else
int IR_RECEIVE_PIN = 11;
#endif

void setup() {
    Serial.begin(115200);
    // Just to know which program is running on my Arduino
    Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));

    /*
     * Start the receiver, enable feedback LED and take LED feedback pin from the internal boards definition
     */
    IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN);

    Serial.print(F("Ready to receive IR signals at pin "));
    Serial.println(IR_RECEIVE_PIN);
}

void loop() {
    /*
     * Check if received data is available and if yes, try to decode it.
     * Decoded result is in the IrReceiver.decodedIRData structure.
     *
     * E.g. command is in IrReceiver.decodedIRData.command
     * address is in command is in IrReceiver.decodedIRData.address
     * and up to 32 bit raw data in IrReceiver.decodedIRData.decodedRawData
     */
    if (IrReceiver.decode()) {

        // Print a short summary of received data
        IrReceiver.printIRResultShort(&Serial);
        if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
            // We have an unknown protocol here, print more info
            IrReceiver.printIRResultRawFormatted(&Serial, true);
        }
        Serial.println();

        /*
         * !!!Important!!! Enable receiving of the next value,
         * since receiving has stopped after the end of the current received data packet.
         */
        IrReceiver.resume(); // Enable receiving of the next value

        /*
         * Finally, check the received data and perform actions according to the received command
         */
        if (IrReceiver.decodedIRData.command == 0x10) {
            // do something
        } else if (IrReceiver.decodedIRData.command == 0x11) {
            // do something else
        }
    }
}

Please do this:

  • When you encounter an error, you'll see a button on the right side of the orange bar "Copy error messages" in the Arduino IDE (or the icon that looks like two pieces of paper at the top right corner of the black console window in the Arduino Web Editor). Click that button..
  • In a forum reply here, click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum's code tags markup to your reply.
  • Press "Ctrl + V". This will paste the error between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.

If the text exceeds the forum's 9000 character limit, save it to a .txt file and post it as an attachment. If you click the "Reply" button here, you will see an "Attachments and other settings" link that will allow you to make the attachment.

Install the library from the IDE library manager. That way you know that you have the latest version (3.0.2). Only run example code that comes with the library.

The code that you posted compiles, for me, with no warnings or errors.

I am using an Mega 2560 Arduino with Pin read set to pin 12.

In the code, the IR decoder should be connected to pin 11 (or change the code to pin 12).

IR_RECEIVE_PIN = 11;

Thanks to all for your help. All seems OK now.

Did as suggested and downloaded latest "IRRemote" library direct from IDE and all works just fine.

Just 1 more question please.

How could I modify the code to print out just the HEX value received.

I wish to use a different routine dependant on the hex value received.

eg..." If("hexvalue 1 received == whatever){do something}"

" If("hexvalue 2 received == whatever){do something else}"

/*
 * SimpleReceiver.cpp
 *
 * Demonstrates receiving NEC IR codes with IRrecv
 *
 *  Copyright (C) 2020-2021  Armin Joachimsmeyer
 *  armin.joachimsmeyer@gmail.com
 *
 *  This file is part of Arduino-IRremote https://github.com/z3t0/Arduino-IRremote.
 *
 *  MIT License
 */

/*
 * Specify which protocol(s) should be used for decoding.
 * If no protocol is defined, all protocols are active.
 */
#define DECODE_NEC 1

#include <IRremote.h>

int IR_RECEIVE_PIN = 9;

void setup() {
    Serial.begin(9600);
    // Just to know which program is running on my Arduino
    Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));

    /*
     * Start the receiver, enable feedback LED and take LED feedback pin from the internal boards definition
     */
    IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN);

    Serial.print(F("Ready to receive IR signals at pin "));
    Serial.println(IR_RECEIVE_PIN);
}

void loop() {
    /*
     * Check if received data is available and if yes, try to decode it.
     * Decoded result is in the IrReceiver.decodedIRData structure.
     *
     * E.g. command is in IrReceiver.decodedIRData.command
     * address is in command is in IrReceiver.decodedIRData.address
     * and up to 32 bit raw data in IrReceiver.decodedIRData.decodedRawData
     */
    if (IrReceiver.decode()) {

        // Print a short summary of received data
        IrReceiver.printIRResultShort(&Serial);
        if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
            // We have an unknown protocol here, print more info
            IrReceiver.printIRResultRawFormatted(&Serial, true);
        }
        Serial.println();

        /*
         * !!!Important!!! Enable receiving of the next value,
         * since receiving has stopped after the end of the current received data packet.
         */
        IrReceiver.resume(); // Enable receiving of the next value

        /*
         * Finally, check the received data and perform actions according to the received command
         */
        if (IrReceiver.decodedIRData.command == 0x10) {
            // do something
        } else if (IrReceiver.decodedIRData.command == 0x11) {
            // do something else
        }
    }
}

Using the switch structure (my favorite). Replace the codes on the cases with your key codes.

#define DECODE_NEC 1

#include <IRremote.h>

int IR_RECEIVE_PIN = 9;


void setup()
{
   Serial.begin(9600);
   // Just to know which program is running on my Arduino
   Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));

   IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN);

   Serial.print(F("Ready to receive IR signals at pin "));
   Serial.println(IR_RECEIVE_PIN);
}

void loop()
{

   if (IrReceiver.decode())
   {
      unsigned int keycode = IrReceiver.decodedIRData.command;
      Serial.println(keycode, HEX);
      // ignore repeat codes
      if ((IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT))
      {
         IrReceiver.resume();
         return;
      }
      switch (keycode)
      {
         case 0x01:
            Serial.println("button 1");
            break;
         case 0x02:
            Serial.println("button 2");
            break;
         case 0x03:
            Serial.println("button 3");
            break;
         case 0x04:
            Serial.println("button 4");
            break;
         default:
            Serial.println("invalid entry");
      }
      IrReceiver.resume(); // Enable receiving of the next value
   }
}

Using if, else if, else.

#define DECODE_NEC 1

#include <IRremote.h>

int IR_RECEIVE_PIN = 9;


void setup()
{
   Serial.begin(9600);
   // Just to know which program is running on my Arduino
   Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));

   IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN);

   Serial.print(F("Ready to receive IR signals at pin "));
   Serial.println(IR_RECEIVE_PIN);
}

void loop()
{

   if (IrReceiver.decode())
   {
      unsigned int keycode = IrReceiver.decodedIRData.command;
      Serial.println(keycode, HEX);
      // ignore repeat codes
      if ((IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT))
      {
         IrReceiver.resume();
         return;
      }
      if(keycode == 0x01)
      {
            Serial.println("button 1");
      }
       else if(keycode == 0x02)
      {
            Serial.println("button 2");
      }
      else if(keycode == 0x03)
      {
            Serial.println("button 3");
      }
      else if(keycode == 0x04)
      {
            Serial.println("button 4");
      }
      else 
      {
            Serial.println("invalid entry");
      }      
      IrReceiver.resume(); // Enable receiving of the next value
   }

}

Thank you for your help. That works just fine with V3.0.3 :slight_smile:

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