user51968: 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.

https://drive.google.com/file/d/1YNOqxE0mAZJsQrV7_zMbRZ_jkur19rXt/view?usp=sharing

user10794: 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)


51968: <p>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."</p>

<p>The full error when I compile is :</p>

<pre><code>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.
</code></pre>

<p><a href="https://drive.google.com/file/d/1YNOqxE0mAZJsQrV7_zMbRZ_jkur19rXt/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1YNOqxE0mAZJsQrV7_zMbRZ_jkur19rXt/view?usp=sharing</a></p>
 10794: <p>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.</p>

<p>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.</p>

<hr>

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

<pre><code>/* Timer/Counter2 Compare Match A */
#define TIMER2_COMPA_vect_num   13
#define TIMER2_COMPA_vect       _VECTOR(13)
#define SIG_OUTPUT_COMPARE2A        _VECTOR(13)
</code></pre>
