IR Remote Issue With ESP32

I'm trying to upload a basic IR Remote code to an ESP32DEVKit_U4 modules but I keep getting this error:

In file included from %PATH%\libraries\IRremote\IRremote.h:24,
                 from %PATH%\libraries\IRremote\irSend.cpp:1:
%PATH%\libraries\IRremote\irSend.cpp: In member function 'void IRsend::mark(unsigned int)':
%PATH%\libraries\IRremote\IRremoteInt.h:220:30: error: 'TCCR2A' was not declared in this scope
  220 | #define TIMER_ENABLE_PWM    (TCCR2A |= _BV(COM2B1))
      |                              ^~~~~~
%PATH%\libraries\IRremote\irSend.cpp:24:9: note: in expansion of macro 'TIMER_ENABLE_PWM'
   24 |         TIMER_ENABLE_PWM; // Enable pin 3 PWM output
      |         ^~~~~~~~~~~~~~~~
In file included from %PATH%\libraries\IRremote\IRremoteInt.h:24:
%PATH%\libraries\IRremote\IRremoteInt.h:220:44: error: 'COM2B1' was not declared in this scope
  220 | #define TIMER_ENABLE_PWM    (TCCR2A |= _BV(COM2B1))
      |                                            ^~~~~~
%PATH%\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\cores\esp32/Arduino.h:111:25: note: in definition of macro '_BV'
  111 | #define _BV(b) (1UL << (b))
      |                         ^
%PATH%\libraries\IRremote\irSend.cpp:24:9: note: in expansion of macro 'TIMER_ENABLE_PWM'
   24 |         TIMER_ENABLE_PWM; // Enable pin 3 PWM output
      |         ^~~~~~~~~~~~~~~~
%PATH%\libraries\IRremote\irSend.cpp: In member function 'void IRsend::space(unsigned int)':
%PATH%\libraries\IRremote\IRremoteInt.h:221:30: error: 'TCCR2A' was not declared in this scope
  221 | #define TIMER_DISABLE_PWM   (TCCR2A &= ~(_BV(COM2B1)))
      |                              ^~~~~~
%PATH%\libraries\IRremote\irSend.cpp:35:9: note: in expansion of macro 'TIMER_DISABLE_PWM'
   35 |         TIMER_DISABLE_PWM; // Disable pin 3 PWM output
      |         ^~~~~~~~~~~~~~~~~
%PATH%\libraries\IRremote\IRremoteInt.h:221:46: error: 'COM2B1' was not declared in this scope
  221 | #define TIMER_DISABLE_PWM   (TCCR2A &= ~(_BV(COM2B1)))
      |                                              ^~~~~~
%PATH%\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\cores\esp32/Arduino.h:111:25: note: in definition of macro '_BV'
  111 | #define _BV(b) (1UL << (b))
      |                         ^
%PATH%\libraries\IRremote\irSend.cpp:35:9: note: in expansion of macro 'TIMER_DISABLE_PWM'
   35 |         TIMER_DISABLE_PWM; // Disable pin 3 PWM output
      |         ^~~~~~~~~~~~~~~~~
%PATH%\libraries\IRremote\irSend.cpp: In member function 'void IRsend::enableIROut(int)':
%PATH%\libraries\IRremote\IRremoteInt.h:223:30: error: 'TIMSK2' was not declared in this scope
  223 | #define TIMER_DISABLE_INTR  (TIMSK2 = 0)
      |                              ^~~~~~
%PATH%\libraries\IRremote\irSend.cpp:58:9: note: in expansion of macro 'TIMER_DISABLE_INTR'
   58 |         TIMER_DISABLE_INTR; //Timer2 Overflow Interrupt
      |         ^~~~~~~~~~~~~~~~~~
%PATH%\libraries\IRremote\IRremoteInt.h:228:9: error: 'TCCR2A' was not declared in this scope
  228 |         TCCR2A               = _BV(WGM20); \
      |         ^~~~~~
%PATH%\libraries\IRremote\irSend.cpp:68:9: note: in expansion of macro 'TIMER_CONFIG_KHZ'
   68 |         TIMER_CONFIG_KHZ(khz);
      |         ^~~~~~~~~~~~~~~~
%PATH%\libraries\IRremote\IRremoteInt.h:228:36: error: 'WGM20' was not declared in this scope
  228 |         TCCR2A               = _BV(WGM20); \
      |                                    ^~~~~
%PATH%\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\cores\esp32/Arduino.h:111:25: note: in definition of macro '_BV'
  111 | #define _BV(b) (1UL << (b))
      |                         ^
%PATH%\libraries\IRremote\irSend.cpp:68:9: note: in expansion of macro 'TIMER_CONFIG_KHZ'
   68 |         TIMER_CONFIG_KHZ(khz);
      |         ^~~~~~~~~~~~~~~~
%PATH%\libraries\IRremote\IRremoteInt.h:229:9: error: 'TCCR2B' was not declared in this scope
  229 |         TCCR2B               = _BV(WGM22) | _BV(CS20); \
      |         ^~~~~~
%PATH%\libraries\IRremote\irSend.cpp:68:9: note: in expansion of macro 'TIMER_CONFIG_KHZ'
   68 |         TIMER_CONFIG_KHZ(khz);
      |         ^~~~~~~~~~~~~~~~
%PATH%\libraries\IRremote\IRremoteInt.h:229:36: error: 'WGM22' was not declared in this scope
  229 |         TCCR2B               = _BV(WGM22) | _BV(CS20); \
      |                                    ^~~~~
%PATH%\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\cores\esp32/Arduino.h:111:25: note: in definition of macro '_BV'
  111 | #define _BV(b) (1UL << (b))
      |                         ^
%PATH%\libraries\IRremote\irSend.cpp:68:9: note: in expansion of macro 'TIMER_CONFIG_KHZ'
   68 |         TIMER_CONFIG_KHZ(khz);
      |         ^~~~~~~~~~~~~~~~
%PATH%\libraries\IRremote\IRremoteInt.h:229:49: error: 'CS20' was not declared in this scope
  229 |         TCCR2B               = _BV(WGM22) | _BV(CS20); \
      |                                                 ^~~~
%PATH%\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\cores\esp32/Arduino.h:111:25: note: in definition of macro '_BV'
  111 | #define _BV(b) (1UL << (b))
      |                         ^
%PATH%\libraries\IRremote\irSend.cpp:68:9: note: in expansion of macro 'TIMER_CONFIG_KHZ'
   68 |         TIMER_CONFIG_KHZ(khz);
      |         ^~~~~~~~~~~~~~~~
%PATH%\libraries\IRremote\IRremoteInt.h:230:9: error: 'OCR2A' was not declared in this scope
  230 |         OCR2A                = pwmval; \
      |         ^~~~~
%PATH%\libraries\IRremote\irSend.cpp:68:9: note: in expansion of macro 'TIMER_CONFIG_KHZ'
   68 |         TIMER_CONFIG_KHZ(khz);
      |         ^~~~~~~~~~~~~~~~
%PATH%\libraries\IRremote\IRremoteInt.h:231:9: error: 'OCR2B' was not declared in this scope
  231 |         OCR2B                = pwmval / 3; \
      |         ^~~~~
%PATH%\libraries\IRremote\irSend.cpp:68:9: note: in expansion of macro 'TIMER_CONFIG_KHZ'
   68 |         TIMER_CONFIG_KHZ(khz);
      |         ^~~~~~~~~~~~~~~~
In file included from %PATH%\libraries\IRremote\IRremote.h:24,
                 from %PATH%\libraries\IRremote\irRecv.cpp:1:
%PATH%\libraries\IRremote\irRecv.cpp: In member function 'void IRrecv::enableIRIn()':
%PATH%\libraries\IRremote\IRremoteInt.h:246:17: error: 'TCCR2A' was not declared in this scope
  246 |                 TCCR2A = _BV(WGM21); \
      |                 ^~~~~~
%PATH%\libraries\IRremote\irRecv.cpp:120:9: note: in expansion of macro 'TIMER_CONFIG_NORMAL'
  120 |         TIMER_CONFIG_NORMAL();
      |         ^~~~~~~~~~~~~~~~~~~
In file included from %PATH%\libraries\IRremote\IRremoteInt.h:24:
%PATH%\libraries\IRremote\IRremoteInt.h:246:30: error: 'WGM21' was not declared in this scope
  246 |                 TCCR2A = _BV(WGM21); \
      |                              ^~~~~
%PATH%\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\cores\esp32/Arduino.h:111:25: note: in definition of macro '_BV'
  111 | #define _BV(b) (1UL << (b))
      |                         ^
%PATH%\libraries\IRremote\irRecv.cpp:120:9: note: in expansion of macro 'TIMER_CONFIG_NORMAL'
  120 |         TIMER_CONFIG_NORMAL();
      |         ^~~~~~~~~~~~~~~~~~~
%PATH%\libraries\IRremote\IRremoteInt.h:247:9: error: 'TCCR2B' was not declared in this scope
  247 |                 TCCR2B = _BV(CS21); \
      |                 ^~~~~~
%PATH%\libraries\IRremote\irRecv.cpp:120:9: note: in expansion of macro 'TIMER_CONFIG_NORMAL'
  120 |         TIMER_CONFIG_NORMAL();
      |         ^~~~~~~~~~~~~~~~~~~
%PATH%\libraries\IRremote\IRremoteInt.h:247:36: error: 'CS21' was not declared in this scope
  247 |                 TCCR2B = _BV(CS21); \
      |                                    ^~~~
%PATH%\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\cores\esp32/Arduino.h:111:25: note: in definition of macro '_BV'
  111 | #define _BV(b) (1UL << (b))
      |                         ^
%PATH%\libraries\IRremote\irRecv.cpp:120:9: note: in expansion of macro 'TIMER_CONFIG_NORMAL'
  120 |         TIMER_CONFIG_NORMAL();
      |         ^~~~~~~~~~~~~~~~~~~
%PATH%\libraries\IRremote\IRremoteInt.h:248:9: error: 'OCR2A' was not declared in this scope
  248 |                 OCR2A = pwmval; \
      |                 ^~~~~
%PATH%\libraries\IRremote\irRecv.cpp:120:9: note: in expansion of macro 'TIMER_CONFIG_NORMAL'
  120 |         TIMER_CONFIG_NORMAL();
      |         ^~~~~~~~~~~~~~~~~~~
In file included from %PATH%\libraries\IRremote\IRremote.h:24,
                 from %PATH%\libraries\IRremote\irRecv.cpp:1:
%PATH%\libraries\IRremote\IRremoteInt.h:248:17: error: 'OCR2B' was not declared in this scope
  248 |                 OCR2B = pwmval / 3; \
      |                 ^~~~~
%PATH%\libraries\IRremote\irRecv.cpp:120:9: note: in expansion of macro 'TIMER_CONFIG_NORMAL'
  120 |         TIMER_CONFIG_NORMAL();
      |         ^~~~~~~~~~~~~~~~~~~

It may look long but to break it down it has to do with the IR Remote Library.

The library version I'm using is the 4.4.1 version.

Here is my code:

#include <IRremote.h>

const int recv_pin = 2; // The IR receiver pin

IRrecv irrecv(recv_pin);
decode_results results;

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

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

When I upload my code my port is selected as:

image

IRemote does not support ESP32

Okay so what should I use the IR Remote on.

That code was written for the 2.x version of the IRremote library.

It will not compile with the 4.x version.

There were quite a few breaking changes in between.

You'll either have to go through and update your code to use the new interface (beginning with replacing #include <IRremote.h> with #include <IRremote.hpp> , or use the old library.

But IRremote definitely does.

The text seemed academic, but in reality it was sex )))

The #include <IRremote.hhp> give me an error:

%PATH%  fatal error: IRremote.hhp: No such file or directory
    1 | #include <IRremote.hhp>
      |          ^~~~~~~~~~~~~~
compilation terminated.
exit status 1

Compilation error: IRremote.hhp: No such file or directory

That is what happens when you spell it incorrectly.

#include <IRremote.hpp>, not #include <IRremote.hhp>.

Now with this code:

#include <IRremote.hpp>

const int recv_pin = 2; // The IR receiver pin

IRrecv irrecv(recv_pin); // Create an IRrecv object
decode_results results;  // Create a results object to store the decoded IR data

void setup() {
  Serial.begin(115200);            // Initialize serial communication at 115200 baud rate
  irrecv.begin(recv_pin, false, 0);  // Initialize the receiver (no LED feedback)
}

void loop() {
  if (irrecv.decode(&results)) {  // If an IR signal is received
    Serial.println(results.value, HEX);  // Print the received value in hexadecimal format
    irrecv.resume();  // Get ready to receive the next signal
  }
}

Im getting this:

%PATH%\tools\esp-x32\2302\bin\../lib/gcc/xtensa-esp32-elf/12.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: %PATH%\Temp\arduino\sketches\A8B7DB314C8C6A0AD90F54A8CA8D2417\sketch\d.ino.cpp.o:(.literal._Z4loopv+0x4): undefined reference to `IRrecv::decode(decode_results*)'
%PATH%\tools\esp-x32\2302\bin\../lib/gcc/xtensa-esp32-elf/12.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: %PATH%\Temp\arduino\sketches\A8B7DB314C8C6A0AD90F54A8CA8D2417\sketch\d.ino.cpp.o: in function `loop()':
%PATH%\Saleem\ArduinoFromPureScratch\d\d.ino:14: undefined reference to `IRrecv::decode(decode_results*)'
collect2.exe: error: ld returned 1 exit status

exit status 1

Compilation error: exit status 1


Yes; you've got some work to do to get the 2.x code updated to work with the 4.x library, as I mentioned at the top. Using the proper include was only the first step.

And, by the way, you are welcome. Good luck, and good-bye.

Guide for upgrading your code from version 2.x of library to 4.x of library can be found here

I'm not sure that the ESP32 is supported by IRremote because the serial monitor is giving me this:

11:27:32.097 -> ets Jul 29 2019 12:21:46
11:27:32.097 -> 
11:27:32.097 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
11:27:32.138 -> configsip: 0, SPIWP:0xee
11:27:32.138 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
11:27:32.138 -> mode:DIO, clock div:1
11:27:32.138 -> load:0x3fff0030,len:4832
11:27:32.138 -> load:0x40078000,len:16460
11:27:32.138 -> load:0x40080400,len:4
11:27:32.138 -> load:0x40080404,len:3504
11:27:32.138 -> entry 0x400805cc
11:27:32.241 -> E (142) quad_psram: PSRAM ID read error: 0xffffffff, PSRAM chip not found or not supported

But you are sure that you have correct board /board settings on IDE and that your board has PSRAM?

From "supported boards" here

We use the Arduino-IRremote-master library version 4.4.1 from the folder: E:\arduino-ESP32C3\portable\sketchbook\libraries\Arduino-IRremote-master 
"E:\\arduino-ESP32C3\\portable\\packages\\esp32\\tools\\riscv32-esp-elf-gcc\\esp-2021r2-patch5-8.4.0/bin/riscv32-esp-elf-size" -A "C:\\Temp\\arduino_build_569259/SendAndReceive.ino.elf"
The sketch uses 274804 bytes (20%) of the device memory. A total of 1310720 bytes are available.
Global variables use 15124 bytes (4%) of dynamic memory, leaving 312556 bytes for local variables. Maximum: 327680 bytes.

You don't have Esp32-c3.
You should select Esp32 dev module as your board