# Error on  IRremote  project

**URL:** <https://forum.arduino.cc/t/error-on-irremote-project/379511>\
**Category:** Programming\
**Created:** [April 14, 2016, 12:08am UTC](https://forum.arduino.cc/t/error-on-irremote-project/379511 "2016-04-14T00:08:13Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_82](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@David\_82](https://forum.arduino.cc/u/David_82)\
**Post date:** [April 14, 2016, 12:08am UTC](https://forum.arduino.cc/t/error-on-irremote-project/379511/1 "2016-04-14T00:08:13Z")

</div>

Hi everyone! I'm a beginner to Arduino world and I love it but sometimes (quite often) i get a blocked with certain projects, like the one Im trying to do now.

I have an Arduino Mega, and for my IR remote project I'm using the IR library by Ken Shirriff.

So far so good, the problem comes when I try to add an extra function (melody for example).

```cpp
#include <IRremote.h>

int RECV_PIN = 11;
int buzz = 2;
IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  //melody(); // WHEN I ADD AN EXTRA FUNCTION LIKE THIS ONE I GET AN ERROR

}

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

/*void melody(){
  tone(buzz, 2500, 150);
  delay(150);
  tone(buzz, 2500, 150);
  delay(150);
  tone(buzz, 2500, 150);
  delay(150);
  tone(buzz, 4186, 500);
  }*/
  
  //ERRROR WHEN I TRY TO ADD AN EXTRA FUNCTION LIKE THIS ONE

```

And that's when i get this error:

```cpp
Arduino:1.6.6 (Windows 7), Placa:"Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\Admin\AppData\Local\Temp\buildaf6b3c979e963c25610b5838ddac79d0.tmp/core\core.a(Tone.cpp.o): In function `__vector_13':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Tone.cpp:539: multiple definition of `__vector_13'

libraries\IRremote\IRremote.cpp.o:C:\Program Files (x86)\Arduino\libraries\IRremote/IRremote.cpp:124: first defined here

c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.8.1/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions

collect2.exe: error: ld returned 1 exit status

exit status 1
Error de compilación

  Este informe podría tener más información con
  "Mostrar salida detallada durante la compilación"
  activala desde Archivo > Preferencias

```

Any ideas why this is happening?

Thanks in advance guys!  
I would appreciate any help/comments.

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [April 14, 2016, 12:27am UTC](https://forum.arduino.cc/t/error-on-irremote-project/379511/2 "2016-04-14T00:27:15Z")

</div>

Looks like there is incompatibility between IRremote.h and the tone function.

What remote are you using?

---

<div class="post-metadata">

**Author:** ![OldSteve](https://avatars.discourse-cdn.com/v4/letter/o/0ea827/32.png) [@OldSteve](https://forum.arduino.cc/u/OldSteve)\
**Post date:** [April 14, 2016, 1:59am UTC](https://forum.arduino.cc/t/error-on-irremote-project/379511/3 "2016-04-14T01:59:16Z")

</div>

You'll find the fix in this thread:-  
[IRRemote library conflicts with tone() function](http://forum.arduino.cc/index.php?topic=120955.0)

In a nutshell, in "IRremoteInt.h", you can define which timer you want 'IRremote' to use.

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [April 14, 2016, 2:10am UTC](https://forum.arduino.cc/t/error-on-irremote-project/379511/4 "2016-04-14T02:10:32Z")

</div>

Thank you YoungSteve!

Here is another option if the OP has NEC remote.  
[http://forum.arduino.cc/index.php?topic=317625.0](http://forum.arduino.cc/index.php?topic=317625.0)

.

---

<div class="post-metadata">

**Author:** ![OldSteve](https://avatars.discourse-cdn.com/v4/letter/o/0ea827/32.png) [@OldSteve](https://forum.arduino.cc/u/OldSteve)\
**Post date:** [April 14, 2016, 2:28am UTC](https://forum.arduino.cc/t/error-on-irremote-project/379511/5 "2016-04-14T02:28:50Z")

</div>

> LarryD:  
> Thank you **YoungSteve**!

Haha, I haven't heard _that_ for a long time. 😃

> Here is another option if the OP has NEC remote.  
> [New Library for IR Remotes - Exhibition / Gallery - Arduino Forum](http://forum.arduino.cc/index.php?topic=317625.0)

Looks like a good library for the NEC remotes. Especially useful for people using Arduinos based on the '328P or similar, since they don't have the extra timers to implement my suggestion. Nice work Larry.

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [April 14, 2016, 2:55am UTC](https://forum.arduino.cc/t/error-on-irremote-project/379511/6 "2016-04-14T02:55:41Z")

</div>

It is written as none blocking code and as you said no timers.  
Does use an interrupt.  
.

---

<div class="post-metadata">

**Author:** ![David\_82](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@David\_82](https://forum.arduino.cc/u/David_82)\
**Post date:** [April 14, 2016, 7:13am UTC](https://forum.arduino.cc/t/error-on-irremote-project/379511/7 "2016-04-14T07:13:58Z")

</div>

Thank you Steve and Larry for your help.

Unfortunately still not working I've change the timer in that file and no sucess.

This is what I changed in the IRremoteInt.h file. See below:

// Define which timer to use  
//  
// Uncomment the timer you wish to use on your board.  
// If you are using another library which uses timer2, you have options to  
// switch IRremote to use a different timer.  
//

// Arduino Mega  
#if defined( **AVR\_ATmega1280** ) || defined( **AVR\_ATmega2560** )  
//#define IR\_USE\_TIMER1 // tx = pin 11  
//#define IR\_USE\_TIMER2 // tx = pin 9  
//#define IR\_USE\_TIMER3 // tx = pin 5  
//#define IR\_USE\_TIMER4 // tx = pin 6  
#define IR\_USE\_TIMER5 tx = pin 46

---

<div class="post-metadata">

**Author:** ![OldSteve](https://avatars.discourse-cdn.com/v4/letter/o/0ea827/32.png) [@OldSteve](https://forum.arduino.cc/u/OldSteve)\
**Post date:** [April 14, 2016, 8:08am UTC](https://forum.arduino.cc/t/error-on-irremote-project/379511/8 "2016-04-14T08:08:47Z")

</div>

What error are you getting now?

It can't be the same one if IRremote isn't using timer2 any more.  
The \_\_vector\_13 define relates purely to timer2.

Changing timers seems to work for everyone else that has this error.  
Have you closed and re-opened the IDE since editing "IRremoteInt.h"?

As Larry asked, what sort of remote control format? If NEC, you could give his library a spin.

---

<div class="post-metadata">

**Author:** ![AnalysIR](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@AnalysIR](https://forum.arduino.cc/u/AnalysIR)\
**Post date:** [April 21, 2016, 12:03pm UTC](https://forum.arduino.cc/t/error-on-irremote-project/379511/9 "2016-04-21T12:03:07Z")

</div>

You should change

```cpp
 #define IR_USE_TIMER5    tx = pin 46

```

to

```cpp
   #define IR_USE_TIMER5    //tx = pin 46

```

It is probably not the issue.

Presumably you are using either an Arduino Mega1280 or Arduino Mega2560??  
...vs UNO or Leonardo etc

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 9:50pm UTC](https://forum.arduino.cc/t/error-on-irremote-project/379511/10 "2021-05-05T21:50:27Z")

</div>


