strange problem with library "IRremote.h"

Hi,
I am programming some Arduino sensors and other things and I want to make them work together, some activated with an IR sensor. If I use ONLY the code with that library, everything works. In the code you will find at the end of the post, I always get the same error:

Arduino: 1.8.4 (Windows 10), Board: "Arduino/Genuino Uno"

Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':

(.text+0x0): multiple definition of `__vector_7'

libraries\IRremote\IRremote.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

Multiple libraries were found for "IRremote.h"
 Used: C:\Users\matt\Documents\Arduino\libraries\IRremote
 Not used: C:\Program Files (x86)\Arduino\libraries\IRremote
exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I can't post the verbose output because it has more than 18000 characters.

The code about the IR sensor in the below code is a test, to see if the library worked. As you can understand from the subject, the test failed. I tried removing the IR library, and everything worked. Here the code:

#include <IRremote.h>
#include <LiquidCrystal.h>
#include <Servo.h>
#include <SPI.h>
//#include <MFRC522.h>
#include <RFID.h>
#include <Stepper.h>
#include <SimpleDHT.h>

int temperatureInterval = 1000;
int IRinterval = 50;
int alarmInterval = 500;
int ActualAlarmInterval = 1500;
int RFIDinterval = 100;
int stepperTendaInterval = 2457.6;
int IRreceiverInterval = 100;
int ventolaInterval = 10000;
int DHT11Interval = 10000;

int SDA_DIO = 53;
int RESET_DIO = 9;
int delayRead = 1000;

const String codiceGiusto = "70EFBE1938";
const int stepsPerRevolution = 4096;

RFID RC522(SDA_DIO, RESET_DIO);

Stepper tenda(stepsPerRevolution, 24, 25, 26, 27);
Stepper door(stepsPerRevolution, 30, 31, 32, 33);

int i = 0;

//const int tempPin = A0; // analog pin for the temp sensor
float celsius = 0; //all for the termometer
float millivolts; //all for the termometer
int tempSensor; //all for the termometer
int KitchenLed = 2;
int entranceLed = 3;
int thirdRoomLed = 4;
int fourthRoomLed = 5;
int IRreceiver = 9; 
int alarmLed = 11;
int alarmBuzzer = 10;
int triggerPort = 28;
int echoPort = 29;
int receiver = 22;
int pompa = 39;
int ventola = 53;
int DHT11 = A2;//???????????????????
SimpleDHT11 dht11;

long temperaturePreviousMillis = 0;
long IRreceiverPreviousMillis = 0;
long alarmPreviousMillis = 0;
long ActualAlarmPreviousMillis = 0;
long RFIDpreviousMillis = 0;
long ventolaPreviousMillis = 0;
long DHT11PreviousMillis = 0;

bool isAlarmOn = true;
bool isAlarmTriggered = false;

Servo washingMachine;

IRrecv irrecv(receiver);      
decode_results results;

void setup() {

  Serial.begin(9600); // start serial communication
  pinMode( triggerPort, OUTPUT );
  pinMode( echoPort, INPUT );
  washingMachine.attach(22);
  Serial.println("Premere sul telecomando:");
  Serial.println("1 = accendi luce della cucina");
  //Serial.println("2 = turn on second light");
  //Serial.println("3 = turn on third light");
  //Serial.println("4 = turn on fourth light");
  //Serial.println("5 = turn on fifth light");
  Serial.println("6 = turn on the dishwasher");
  //Serial.println("7 = show clock on LCD screens");
  //Serial.println("6 = turn on servo");
  //lcd.begin(16, 2);
  //lcd.clear();
  while (!Serial);     // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();         // Init SPI bus
  RC522.init();  // Init MFRC522 card
  pinMode(KitchenLed, OUTPUT);
  irrecv.enableIRIn();
}

void loop() {
 // if (millis() -  temperaturePreviousMillis > temperatureInterval ){ //temperature
   // temperaturePreviousMillis = millis();
   // int aRead = 0;
   // aRead = analogRead(pin); 
   // Serial.print("Analog = ");
   // Serial.print(aRead);
   // float tempC = aRead * 0.48875; // convert in centigrades
   // Serial.print("     Temp = ");
   // Serial.println(tempC);
   // lcd.print("Temp = ");
   // lcd.print(tempC);
   // lcd.print("º C");
  //}
  
  if (millis() -  alarmPreviousMillis > alarmInterval ){
    alarmPreviousMillis = millis();
    if (isAlarmOn == true) {
      //porta bassa l'uscita del trigger
      digitalWrite(triggerPort, LOW );
      //invia un impulso di 10microsec su trigger
      digitalWrite(triggerPort, HIGH );
      delayMicroseconds( 10 );
      digitalWrite(triggerPort, LOW );
      long duration = pulseIn(echoPort, HIGH);
      long r = 0.034 * duration / 2;
      if( duration > 38000 ) {
        Serial.println( "fuori portata");
      }
      else { 
        Serial.print( r ); Serial.println( "cm" );
      }
      if (duration < 912) {
        isAlarmTriggered = true;
      }
    }
  }
   
  if (millis() -  ActualAlarmPreviousMillis > ActualAlarmInterval ){
    ActualAlarmPreviousMillis = millis();
    if (isAlarmTriggered == true) {
      digitalWrite(alarmLed, HIGH);
      delay(750);
      digitalWrite(alarmLed, LOW);
      delay(750);
    }
  }
  if (millis() -  ActualAlarmPreviousMillis > ActualAlarmInterval ){
    ActualAlarmPreviousMillis = millis();
    if (isAlarmTriggered == true) {
      tone(19, 330, 375);
      delay(375);
      tone(19, 262, 375);
      delay(375);
      tone(19, 330, 375);
      delay(375);
      tone(19, 262, 375);
      delay(375);
    }
  }
  if (millis() - RFIDpreviousMillis > RFIDinterval ) {
    RFIDpreviousMillis = millis();
  byte i;
   
  // Se viene letta una tessera
  if (RC522.isCard())
  {
    // Viene letto il suo codice 
    RC522.readCardSerial();
    String codiceLetto ="";
    Serial.print("Codice letto: ");
     
 
    for(i = 0; i <= 4; i++)                //Lettura del codice della scheda e composizione della stringa
    {
      codiceLetto+= String(RC522.serNum[i],HEX);
      codiceLetto.toUpperCase();
    }

    Serial.print(codiceLetto);           //Viene stampato il codice letto
    
    if(codiceLetto.equals(codiceGiusto))   
    {
      Serial.println(" --> CODICE VALIDO");  //Se il codice letto è uguale a quello atteso verrà stampato "CODICE VALIDO", altrimenti verrà stampato "CODICE ERRATO"
          for (i = 0; i<1350; i++)  {
          door.step(-15); //Un passo in senso orario.
          delay(10);
          i = (i+1);
      }
      for (i = 1350; i>0; i--)  {
      door.step(15); //Un passo in senso orario.
    delay(10);
    i = (i-1);
    }
    }
    else
    {
      Serial.println(" --> CODICE ERRATO");  

    }
    delay(1000);
}
}    
 if (millis() -  IRreceiverPreviousMillis > IRreceiverInterval ){
   if (irrecv.decode(&results)) // have we received an IR signal?

  {
    Serial.println(results.value, HEX);
    irrecv.resume(); // receive the next value
    delay(10); 
  } 
 }
  if (millis() -  ventolaPreviousMillis > ventolaInterval ){
    ventolaPreviousMillis = millis();
    if ((temperature) >= (25)) {
      digitalWrite(ventola, HIGH)
    } else {
      digitalWrite(ventola, LOW)
    }
  }
  if (millis() -  DHT11PreviousMillis > DHT11Interval ){
    DHT11PreviousMillis = millis();
    byte temperature = 0;
  byte humidity = 0;
  byte data[40] = {0};
  if (dht11.read(DHT11, &temperature, &humidity, data)) {
    return;
  }
  
  Serial.print("Sample RAW Bits: ");
  for (int i = 0; i < 40; i++) {
    Serial.print((int)data[i]);
    if (i > 0 && ((i + 1) % 4) == 0) {
      Serial.print(' ');
    }
  }
  Serial.println("");
  
  Serial.print((int)temperature); Serial.print(" *C, ");
  Serial.print((int)humidity); Serial.println(" %");
  
  //lcd.clear();
  //lcd.setCursor(0, 0);
  //lcd.print((int)temperature); lcd.print(" *C, ");
  //lcd.setCursor(0, 1);
  //lcd.print((int)humidity); lcd.println(" %");
  
  // DHT11 sampling rate is 1HZ.
  delay(1000);
  }
}

Hello there!

With Arduino libraries, several of them try to utilize Timer1 on the main microcontroller chip. When two or more libraries are trying to use the same Timer, you will get the error about "multiple definitions of vector" and such.

If you can, try to compile the following code:

#include <IRremote.h>
#include <LiquidCrystal.h>
#include <Servo.h>
#include <SPI.h>
#include <MFRC522.h>
#include <RFID.h>
#include <Stepper.h>
#include <SimpleDHT.h>

void setup()
{

}
void loop()
{

}

I'll wager that the error is still popping up. Since there is no actual code, just the library calls, the libraries themselves are the source of the error.

I do know that the Servo library is a big contributor to this error. Try switching it from Servo.h to ServoTimer2.h (you may have to download the library from GitHub or something). Running the code I put above with this switch may allow the error to be resolved. There is a slight difference between Servo and ServoTimer2, so try compiling the code I posted with ServoTimer2, and then we'll talk.

Hi,
thank you for your reply.
Actually, the problem is more complicate, as this code runs without errors:

#include <IRremote.h>
#include <LiquidCrystal.h>
#include <Servo.h>
#include <SPI.h>
#include <MFRC522.h>
#include <RFID.h>
#include <Stepper.h>
#include <SimpleDHT.h>

void setup()
{

}
void loop()
{

}

I think I'll try to use the IR sensor on my first Arduino, then send the data to the second Arduino. Could this work?

speedylearner:
Actually, the problem is more complicate, as this code runs without errors:

That is very interesting. Below is a quote from your earlier error message:

speedylearner:
Multiple libraries were found for "IRremote.h"
Used: C:\Users\matt\Documents\Arduino\libraries\IRremote
Not used: C:\Program Files (x86)\Arduino\libraries\IRremote
exit status 1
Error compiling for board Arduino/Genuino Uno.

It seems that you have the same library stored on your computer in two different locations. Try going to the folder that the error message says you did not use, and move it from there to the desktop (move not copy). That way the IDE will only find one copy of the library. Then try to recompile your original code.

speedylearner:
I think I'll try to use the IR sensor on my first Arduino, then send the data to the second Arduino. Could this work?

It is entirely possible to use that method to communicate, however it may add complexity to your code that may not be necessary. Try my suggestion above and let me know if it works.

Thank you for your time, but nothing works. Now there is only one library but the same error crops up. Same with ServoTimer2, which I downloaded from GitHub.
Just to be sure, would the following code work in serial communication between the arduino?
This is the code for the sender Arduino, and no errors were found.

#include <IRremote.h>

char mystr[5] = "Hello"; //String data
int receiver = 2;

IRrecv irrecv(receiver);      
decode_results results;  

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

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    mystr[5] = (results.value, HEX);
    Serial.write(mystr,5);
    irrecv.resume(); // receive the next value
    delay(80); 
  }
}

//code valid per sender
char mystr[5] = "Hello"; //String data

That is NOT a string. It is a char array. You are supplying too much data to include a NULL terminator, so you do NOT have a string.

    mystr[5] = (results.value, HEX);

You can NOT write to position 5 of a 5 element array. The positions you can write to are 0 to 4.

You are abusing the comma operator. That code will not do what you expect, unless you expect something stupid.

and no errors were found.

Nonsense. There were no syntax errors. There are loads of logic errors.

So, can you suggest me a valid code to send what the IR sensor received?

So, can you suggest me a valid code to send what the IR sensor received?

Send it where? In what format? If you want the Arduino to get a value from a remote, and then transmit that same value to some other device, it's silly to put the Arduino in the middle. Just point the remote at the end device.

Let me clarify what I need and what I have to do. In the sketch posted in the first post, I cannot make the IR library work. If I use the library alone, it works, so I have thought to make the IR sensor send its results to my first arduino, with a simple sketch using only the IRremote library, then send the HEX results to the second Arduino which makes sensors and stuff work.
I am Italian so let me know if it is not clear or there are errors

I cannot make the IR library work. If I use the library alone, it works

Those two statements are contradictory. Either the library works or it (or your hardware) doesn't.

so I have thought to make the IR sensor send its results to my first arduino

Is your IR sensor capable of acting as a transmitter, too?

Why would the first Arduino be able to receive IR data from the second Arduino but not from the remote?

I suspect that what you need to do is have the second Arduino, with an IR sensor, receive the data from the remote, and then use some other method (NOT IR) to send data to the first Arduino.