I just got an Elegoo UNO starter kit the other day and have been working my way through the little tutorials on all the parts it came with. I am using VSCode with Platform.io plugin and (after getting it set up) it has been working nicely.

The code I am currently struggling with is a sketch that is supposed to use the IR Remote and Receiver the kit came with, I keep getting the error: collect2.exe: error: ld returned 1 exit status

I have done some looking around online but haven't had much luck getting anything to work.

My full code is below:

char foo;

#include <Arduino.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <IR.h>

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

void setup() {
  Serial.println("IR Receiver Button Decode");

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

//The implementation effect of the above program is 
//the same as that of the following, but it is more concise

//    switch(results.value)
//  {
//  case 0xFFA25D: Serial.println("POWER"); break;
//  case 0xFFE21D: Serial.println("FUNC/STOP"); break;
//  case 0xFF629D: Serial.println("VOL+"); break;
//  case 0xFF22DD: Serial.println("FAST BACK");    break;
//  case 0xFF02FD: Serial.println("PAUSE");    break;
//  case 0xFFC23D: Serial.println("FAST FORWARD");   break;
//  case 0xFFE01F: Serial.println("DOWN");    break;
//  case 0xFFA857: Serial.println("VOL-");    break;
//  case 0xFF906F: Serial.println("UP");    break;
//  case 0xFF9867: Serial.println("EQ");    break;
//  case 0xFFB04F: Serial.println("ST/REPT");    break;
//  case 0xFF6897: Serial.println("0");    break;
//  case 0xFF30CF: Serial.println("1");    break;
//  case 0xFF18E7: Serial.println("2");    break;
//  case 0xFF7A85: Serial.println("3");    break;
//  case 0xFF10EF: Serial.println("4");    break;
//  case 0xFF38C7: Serial.println("5");    break;
//  case 0xFF5AA5: Serial.println("6");    break;
//  case 0xFF42BD: Serial.println("7");    break;
//  case 0xFF4AB5: Serial.println("8");    break;
//  case 0xFF52AD: Serial.println("9");    break;
//  case 0xFFFFFFFF: Serial.println(" REPEAT");break;  
//  default: 
//    Serial.println(" other button   ");

  }// End Case

This is code that was included with the tutorials, but I am not certain it is airtight as I have already had to do some tweaking of the code and header files included with the device. The error I am getting is the following:

include/IR.h:29:0: warning: "REPEAT" redefined
 #define REPEAT 22
In file included from src\main.cpp:4:0:
include/IRremote.h:57:0: note: this is the location of the previous definition
 #define REPEAT 0xffffffff
In file included from src\main.cpp:6:0:
include/IR.h:36:78: warning: initializer-string for array of chars is too long [-fpermissive]
Linking .pio\build\uno\firmware.elf
C:\Users\wiley\AppData\Local\Temp\ccDVm6mB.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_main.cpp.o.1820':
<artificial>:(.text.startup+0x60): undefined reference to `IRrecv::IRrecv(int)'
C:\Users\wiley\AppData\Local\Temp\ccDVm6mB.ltrans0.ltrans.o: In function `main':
<artificial>:(.text.startup+0x160): undefined reference to `IRrecv::enableIRIn()'
<artificial>:(.text.startup+0x16c): undefined reference to `IRrecv::decode(decode_results*)'
<artificial>:(.text.startup+0x1c6): undefined reference to `IRrecv::resume()'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\uno\firmware.elf] Error 1

I don't understand the errors it is telling me are in the IR.h file. It says that REPEAT is redefined but it only defined once in the file. In regards to the undefined reference to IRrecv:: I dont understand, because I have all the encessary files in the 'Include' folder, and when I CTRL click those functions in the editor it takes me to the files and shows me the code... so why can't it find the code when I run it?


#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_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_NUM 21
#define REPEAT 22



I have searched online a lot, and this seems to be a common issue with this IR.h library, and none of the fixes proposed have got me anywhere. (I get the same outputs when trying to run this sketch within the Arduino IDE with all a libraries installed)

I have been developing with Java and Python for a while now, but I have almost no experience with C or C++ before the Arduino, so maybe this is a simple error I just don't understand. Super frustrating!! Any help or guidance would be appreciated! Thanks

  • 1
    The "real" error messages are the "undefined reference" lines. The compiler (linker in fact) can't find the code (.cpp) files for one of the libraries (IRremote probably). The Arduino IDE does some magic to take care of that automatically, but I'm not familiar with VSCode or Platform.io. Look for options to include libraries somewhere in your project settings or something like that.
    – Mat
    Commented Nov 18, 2020 at 18:00
  • BTW the warning before that is pretty deadly (memory corruption bug). The loop must be adjusted so that it doesn't go over keyValue's bounds.
    – Mat
    Commented Nov 18, 2020 at 18:01
  • I have made sure all the .h files and .cpp files I am using are in the "Include" folder of the project, which has worked with the previous header files. It's silly that it says it cant find the code because if I CTRL click on the methods in the editor it takes me right to the .cpp file it is in, inside the "Include" folder, so I dont get why it cannot find it at run time. Commented Nov 18, 2020 at 19:27
  • Also, I dropped the loop down to 22 and that issue regarding the loop dissapeared, but more appeared regarding the .h files. Will update OP Commented Nov 18, 2020 at 19:28
  • You don't include .cpp files, you need to compile (and then link) them. Again, I don't know your setup, but the .cpp files shouldn't be in include settings. See if you can add extra source files somewhere in the project settings.
    – Mat
    Commented Nov 18, 2020 at 19:29

1 Answer 1


I have figured it out.

The problem was I had not properly set up the project with the proper libraries. I thought I was doing it right manually but I was not. PlatformIO has a really convenient Library manager that helps with set up. You just select a library and it will automatically add it to the project you choose and make sure the correct dependencies are listed in the .ini file. I was trying to manually drop the files I needed into the correct directories, and was not doing the proper adjustments to the .ini file. Thanks for the help @Mat!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.