I tried convining and LCD display, ultrasonic sensons, LEDs and an IR reciever code into one main code. Seperately they work fine, but when I put them toguether it gives me the following error: "Error compiling for board Arduino/Genuino Mega or Mega 2560."

The full error when I compile is :

Arduino: 1.8.5 (Mac OS X), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':
(.text+0x0): multiple definition of `__vector_13'
libraries/IRremote/IRremote.cpp.o (symbol from plugin):(.text+0x0): first defined here
/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.9.2/../../../../avr/bin/ld: Disabling relaxation: it will not work with multiple definitions
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.


closed as unclear what you're asking by Roberto Lo Giacco, sempaiscuba, VE7JRO, gre_gor, per1234 Dec 10 '18 at 11:53

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • have you tried adding two at a time, rather than all or one approach - perhaps then you can determine which two don't co-exist (if all 6 conbinations of two at a time always works, then try 3 at a time) - at least, that's how I'd approach the issue if the error messages did not indicate the nature of the problem – Jaromanda X Dec 10 '18 at 1:55
  • 2
    You must post your code and you must also use proper formatting or your question will get closed very quickly – Roberto Lo Giacco Dec 10 '18 at 2:00
  • I attached the Code to the post – Jose Dlr Dec 10 '18 at 2:54
  • 1
    Your code should be pasted into the question, a link to the code might expire. If it is too long to include then it should be reduced down to a Minimal, Complete, and Verifiable example. – Nick Gammon Dec 10 '18 at 5:07

The processor has a fixed number of hardware devices such as timers and serial ports. If two libraries try to use the same device (in this case it looks like timer 2) then you won't be able to compile (let alone run) the code without resolving the issue. Possibly one of them could be altered to use a different timer, however this may not be trivial.

As an example, say you have one alarm clock, but you want to have it ring at both 5 a.m. and 7 a.m. You can't do that per se, you might need to get a second clock.

Looking at the source code in (install directory)/hardware/tools/avr/avr/include/avriomxx0_1.h I see that vector 13 is indeed for Timer 2;

/* Timer/Counter2 Compare Match A */
#define TIMER2_COMPA_vect_num   13
#define TIMER2_COMPA_vect       _VECTOR(13)
#define SIG_OUTPUT_COMPARE2A        _VECTOR(13)
  • 1
    It is Timer2 interrupt with tone() and IRremote, same as here: forum.arduino.cc/index.php?topic=120955.0 – Jot Dec 10 '18 at 6:22
  • Judging by the datasheet _vector_13 is "Pin Change Interrupt Request 2" so it might be something to do with pin change interrupts. I didn't look at the code as it wasn't posted above. – Nick Gammon Dec 10 '18 at 20:10
  • When I use the library manager and install IRremote by shirriff and add a tone() call and compile it for the mega 2560, then I get a __vector_13 error. I don't know how vector number 13 is related to Timer2, but it is. – Jot Dec 10 '18 at 22:45
  • Thanks Jot, i was able to figure out what to do. – Jose Dlr Dec 11 '18 at 0:57
  • @Jot you are right - I looked it up in the source. – Nick Gammon Dec 11 '18 at 21:22

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