IR Receiver issues in the serial monitor

Normally I wouldn’t post here and do the “help noob” thing but my Uno starter kit has what I think to be bad example code. I’m trying to learn how to work an IR remote but I think I’m having issues related to a recent change to the IRremote library.

Anyways here’s some code, if anyone wants to help me continue my Arduino journey
this first is an example from the Arduino IRremote library(shows 0 no matter what I push on 2 different remotes) and the second is from the Elegoo Uno R3 Super starter kit IRremote module(shows nothing on 2 different remotes)

thank you very much to any who can help

/*
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

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

void loop() {
 if (irrecv.decode()) {
   Serial.println(results.value, HEX);
   irrecv.resume(); // Receive the next value
 }
 delay(100);
}

This is the code from the elegoo uno R3 starter kit

//www.elegoo.com
//2020.3.12

#include "IRremote.h"
#include "IR.h"



IRrecv irrecv(RECEIVER);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'

void setup() {
 Serial.begin(9600);
 Serial.println("IR Receiver Button Decode");
 irrecv.enableIRIn();
}

void loop()
{
 int tmpValue;
 if (irrecv.decode()) // have we received an IR signal?
 {
   for (int i = 0; i < 23; i++)
   {
     if ((keyValue[i] == results.value) && (i<KEY_NUM))
     {
       Serial.println(keyBuf[i]);
       tmpValue = results.value;
     }
     else if(REPEAT==i)
     {
       results.value = tmpValue;
     }
   }
   irrecv.resume(); // receive the next value
 }

This next bit is the IR.h bit included in the previous code

#ifndef _IR_H
#define _IR_H

#define RECEIVER 11

#define KEY_POWER (0xFFA25D)
#define KEY_FUNC_STOP (0xFFE21D)
#define KEY_VOL_ADD (0xFF629D)
#define KEY_FAST_BACK (0xFF22DD)
#define KEY_PAUSE (0xFF02FD)
#define KEY_FAST_FORWARD (0xFFC23D)
#define KEY_DOWN (0xFFE01F)
#define KEY_VOL_DE (0xFFA857)
#define KEY_UP (0xFF906F)
#define KEY_EQ (0xFF9867)
#define KEY_ST_REPT (0xFFB04F)
#define KEY_0 (0xFF6897)
#define KEY_1 (0xFF30CF)
#define KEY_2 (0xFF18E7)
#define KEY_3 (0xFF7A85)
#define KEY_4 (0xFF10EF)
#define KEY_5 (0xFF38C7)
#define KEY_6 (0xFF5AA5)
#define KEY_7 (0xFF42BD)
#define KEY_8 (0xFF4AB5)
#define KEY_9 (0xFF52AD)
#define KEY_REPEAT (0xFFFFFFFF)
#define KEY_NUM 21
#define REPEAT 22

unsigned long keyValue[]={KEY_POWER,KEY_FUNC_STOP,KEY_VOL_ADD,KEY_FAST_BACK,KEY_PAUSE,KEY_FAST_FORWARD,
               KEY_DOWN,KEY_VOL_DE,KEY_UP,KEY_EQ,KEY_ST_REPT,KEY_0,KEY_1,KEY_2,KEY_3,KEY_4,KEY_5,
               KEY_6,KEY_7,KEY_8,KEY_9,KEY_REPEAT};

char keyBuf[][15]={"POWER","FUNC/STOP","VOL+","FAST BACK","PAUSE","FAST FORWARD","DOWN","VOL-",
                 "UP","EQ","ST/REPT","0","1","2","3","4","5","6","7","8","9"};
#endif
[code]

[/code]

The IRRemote library was recently updated. The new version will not run code written for the older version of the library. So, fix the older code to run on the new version or install an older version. The older library versions are available through the library manager.

Here is test code that has been tested with the newest version (3.00) and works.

#include <IRremote.h>

const byte IR_RECEIVE_PIN = 11;

void setup()
{
   Serial.begin(115200);
   Serial.println("IR receive test");
   IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);// onboard LED blinks with received IR signal
}

void loop()
{
   if (IrReceiver.decode())
   {
      unsigned long keycode = IrReceiver.decodedIRData.command;
      Serial.println(keycode, HEX);
      if ((IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT)) // ignore repeat code
      {
         IrReceiver.resume();
         return;
      }
      IrReceiver.resume();
   }
}

Is your code partially in italics? I didn’t think so. Read the how get the most out of this forum sticky to see how to properly post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code in code tags.

I removed my IRremote libraries and reinstalled the 3.0.1 library before running this code but the serial monitor is only printing question marks?

i see Serial.println(keycode,HEX); so should i think this should be printing the hex values

I got in contact with elegoo and was able to get my code working by only using their included library but its kinda frustrating that they’re ok with just teaching me outdated coding

Is the baud rate in serial monitor set to 115200? Like I said, the code is tested and known to work. In fact I just ran it and get good results.

The changes to the IRRemote library were made rather recently so if Elegoo has not caught up it is not surprising. I am more frustrated that a lot of my code for IR remotes is now incompatible with the new library.

The trouble that you are having has been experienced by many of late. I have tried to help 5 or 6 people in the last couple of weeks with the same problems.

Please go back to your original post and put the code in code tags.

1 Like

I didn't have my baud rate set correctly but your code works for me now as it should
thanks for the advice and the new code to study

Karma for fixing the code tags.

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