IRremote.h updated, old code not working, need help!

Hi,

I was using the IRremote.h library made by Ken Shirrif for a college project where I was simply sending an IR signal every 0.5 seconds and decoding it on the other side. There have apparently been some updates to the library recently and the code I was using is not working anymore. I have tried working through the instructions posted on the GitHub for converting programs but nothing I have tried has worked and I'm getting desperate now as my project deadline is fast approaching!

I am using an Elegoo Mega2560 to send the IR signal where the IR LED is connection to pin 9 (as per the instructions on GitHub). The code is being received on an ESP32. Currently no signal is being sent from the IR LED (I am checking using my phone camera and there is no blinking).

I was wondering if anyone on here has experienced the same problem with converting the old code and could help out?

I tried changing the library back to older versions but unfortunately I'm not sure what version I was originally using and none of the older versions have worked so far although I coded this in the last year.

Here is my original code for the IR sender.

#include <IRremote.h>

IRsend irsend;

void setup() {
}

void loop() {

      irsend.sendNEC(0x004efe71,32);
     delay(500);
}

Here is my original code for the receiver:

#include <IRremote.h>

const int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);

decode_results results;

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

void loop() {

  if (irrecv.decode(&results)) {
      if (results.value == 0x004efe71) {
           Serial.println("Living Room ");   //sending to app
           Serial.println( results.value, HEX);
      delay(600);
       }
 
    irrecv.resume(); // Receive the next value
  }

}

Thank you in advance!

link to the IRremote GitHub page: GitHub - Arduino-IRremote/Arduino-IRremote: Infrared remote library for Arduino: send and receive infrared signals with multiple protocols

Hello,

Edit: sorry you have read the readme, but why you didn't convert your code? At least show what you tried

Sorry, yes I am trying to work through the Readme but I can't seem to get it working.

I have made some progress now in that I believe a signal is being sent from the IR LED as I can now see a blinking when looking at it through my phone camera. Here is the updated IR Send code:

#include <IRremote.h>

const int IR_SEND_PIN = 9;

void setup() {
  IrSender.begin(IR_SEND_PIN, ENABLE_LED_FEEDBACK); //Now included as per GitHub
}

void loop() {

  IrSender.sendNECMSB(0x004efe71,32); //updated from sendNEC to sendNECMSB as per ReadMe
  delay(500);
}

Unforuntaely i'm still having trouble receiving and decoding the IR Signal. This is the code I had tried to update for the receiver as per the Readme on GitHub:

#include <IRremote.h>

const int IR_RECEIVE_PIN = 4;

void setup() {
   Serial.begin(115200); //Start Serial monitor in 115200
   IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
}

void loop() {

  if (IrReceiver.decode()) {

        // value from receiver in Living room
         if (IrReceiver.decodedIRData.decodedRawData == 0x004efe71) {
                Serial.println("Living Room \r\n");   //sending to app
          delay(1000);
    }
    else {
          Serial.println("Out of sight");
           }

      delay(1000);
    }
    //irrecv.resume(); //This command isn't recognised in the updated version and I have yet to find a replacement in the new library
  }

The current output I get for there receiver is just consistently "out of sight".

I realised that if my receiver was outputting "out of sight" then I must be at least receiving a signal so I put in some code to print the data being received in Hex value and I'm receiving the data: 8E7F7200.

It's good to know I am at least receiving something but that obviously isn't the hex value I am sending, at least not intentionally anyway. There are no other sources of IR around me at the moment so some how the value I am sending is being changed, I need to investigate further as I'm not sure why this is.

Good progress :slight_smile:

0x8E7F7200 is 0x004EFE71 with all bits reversed

So you have to reverse the bits (as said in the readme)

Here is a way to do it

uint32_t reverseBits( uint32_t val )
{
	uint32_t ret = 0;
	for (uint8_t i = 0; i < 32; i++)
	{
		ret = (ret << 1) | ((val >> i) & 1);
	}
	return ret;
}

Use like this

IrSender.sendNECMSB(reverseBits(0x004efe71),32); //updated from sendNEC to sendNECMSB as per ReadMe

(edit: fixed a little mistake in code..)

All working now, thanks so much for your help! Project saved :grinning:

Nice :slight_smile:

    //irrecv.resume(); //This command isn't recognised in the updated version and I have yet to find a replacement in the new library

The example "IRrecvDemo" contains this:

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

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