collect2.exe: error: ld returned 1 exit status on IRremot Library

Good Afternoon:

I’m trying to upload my IRremote Code to my Arduino UNO and I’m getting the following error:

C:\Users\Alan\AppData\Local\Temp\build554794f6afd95f64bb44c4fc9173d68c.tmp/core\core.a(wiring.c.o): In function `__vector_16’:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/wiring.c:47: multiple definition of `__vector_16’

libraries\IRremote\IRremote.cpp.o:C:\Users\Alan\Documents\Arduino\libraries\IRremote/IRremote.cpp:307: first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

I was able to upload this code before but now it’s not working. I’m on Windows 10, using Arduino UNO, running Arduino 1.6.8 and using library IRremote and my code is as follows (hope I can post it right this time). Your help in regards to this matter is greatly appreciated. Have a great day! :slight_smile:

here’s the complete output of the Micro Build Output pane:

#include <IRremote.h>      //must copy IRremote library to arduino libraries
#include <Servo.h>
#define plus 0x925D5B5D   //clockwise rotation button
#define minus 0xCB3D6F7D  //counter clockwise rotation button
#define BUTTON_1 0x6BFD8B01 //Moves servo to 0 degrees
#define BUTTON_2 0x42640C99 //Moves servo to 90 degrees
#define BUTTON_3 0xB1EFBA9D //Moves servo to 180 degrees

const int greenLed = 4;
const int redLed = 5;

int RECV_PIN = 2;       //IR receiver pin
Servo servo;
int val;                //rotation angle
int16_t pos;         // variable to store the servo position 
int16_t speed;       // Number of degrees to move each time a left/right button is pressed
//bool cwRotation, ccwRotation;  //the states of rotation

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  servo.attach(9);     //servo pin
  pos = 90;            // start at midpoint 90 degrees
  speed = 3;           // servo moves 3 degrees each time left/right is pushed
  servo.write(pos);    // Set initial position
  irrecv.enableIRIn(); // Start the receiver

  pinMode(greenLed, OUTPUT);
  pinMode(redLed, OUTPUT);

}

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

 switch(results.value) {
            case BUTTON_1:      pos=0*90; 
            digitalWrite(greenLed, HIGH);
            digitalWrite(redLed, LOW);
            Serial.println("Gate Unlocked"); break;
            
            case BUTTON_2:      pos=1*90;
            digitalWrite(greenLed, LOW);
            digitalWrite(redLed, LOW);
            Serial.println("Middle Ground");break;
            
            case BUTTON_3:      pos=2*89; 
            digitalWrite(greenLed, LOW);
            digitalWrite(redLed, HIGH);
            Serial.println("Gate Locked");break;
      }            

  }

  servo.write(pos);   // tell servo to go to position in variable 'pos'
  delay(20);          //General speed
}

Both IRremote and Servo are trying to use the same timer. So the two libraries won’t work together. There are versions of the servo library out there that use timer 2 instead.

Thank you very much for your prompt reply Delta_G! I don't mean to sound rude or disrespectful, but as I said, I was able to upload this sketch to my UNO before, and run the code without a problem. Do you think it's just a matter of a setting or something that I changed that is preventing me to upload this sketch?!?! :)

Alan777: Thank you very much for your prompt reply Delta_G! I don't mean to sound rude or disrespectful, but as I said, I was able to upload this sketch to my UNO before, and run the code without a problem. Do you think it's just a matter of a setting or something that I changed that is preventing me to upload this sketch?!?! :)

You must have changed something between then and now. It's up to you to tell us what you changed.

Although for another interrupt conflict, my reply in https://forum.arduino.cc/index.php?topic=454873.0 might be of help.

Be aware that that modification affects old code that you recompile as well as new code that you will write on the future. You can probably prevent that by making a copy of the IRremote library in your sketch directory (preferably in the src subdirectory) and modify the copy. You need to modify the include in your sketch to use the local copy and you need to modify the cpp as well to do the same.

I figured it out guys! The problem was that previously I was using another IRremote library that I got from this link: https://drive.google.com/drive/folders/0B77d7bcO_gwvfnU3ejV1eEYxRW5Td1FqV2ttOFlFWXFJQ1Y1MmZEeGVpcFI4bzZzenQxbkE

I think somewhere along the way I switched to another library, but the previously mentioned library allowed me to used the IRremote library and the Servo library simultaneously without any conflict. Thank you so much Delta_G and Sterretje for your valuable feedback, you guys are awesome! Hope somebody can also benefit from your knowledge and this super cool IRremotelibrary!!! :) :) :)