Let's Make Robots!

Need Help with conflicting Arduino libraries

Hello everyone,

I recently recieved some HC-SR04's and am wanting to make a little device to test them. The idea is that one sensor controls when a piezo buzzer will play, and the other sensor will decide the pitch of that note. I have written some code together but on trying to compile I get this error:




core.a(Tone.cpp.o): In function `__vector_7':

C:\Program Files (x86)\arduino-1.0.1\hardware\arduino\cores\arduino/Tone.cpp:523: multiple definition of `__vector_7'

NewPing\NewPing.cpp.o:C:\Program Files (x86)\arduino-1.0.1\libraries\NewPing/NewPing.cpp:214: first defined here




I am using both the Tone library and the New ping library. No expert in the field but it appears as if both the libraries are conflicting with each other over some definitions.

If anyone has any experience with this issue please help me! I have attached everything I am using, the file extensions have been changed to allow upload.

NewPing.txt10.24 KB
Tone.txt14.56 KB
Ultrasonic_music_maker.txt1.06 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Thanks to Bas. As Im not using any special timer events as the 15 ultrasonic sensor example does I was able to delete from lines 211 to 217 which allowed my program to work. Hope anyone else who has this problem sees this.

The other day I stumbled upon the same problem too!

Option 1: you could use a different tone function that wouldn't use the timer: http://arduino.cc/forum/index.php/topic,106043.msg959970.html#msg959970 (got it from a book and it work find, but pauses execution of the program)

Option 2: you could comment couple of lines in the NewPing library (as the author suggests here: http://arduino.cc/forum/index.php/topic,106043.msg960630.html#msg960630), but then you won't be able to run the SR04s like this: http://code.google.com/p/arduino-new-ping/wiki/15_Sensors_Example


P.S.: right now I am using Option 1.

I actually came across your forum post on my google adventures :) I did open up the library and navigated to those lines but commenting them out only gave me bigger errors, I probably did it wrong. 

Ok so I have been trying all day and have managed to write this code. It only gets the distance values from one ultrasonic sensor atm but I think everything else should now fall in place.


const int trigPin = 8;

const int echoPin = 9;

long previousMillis = 0;

long interval = 100; 


void setup() {




void loop()


  long duration, cm;

  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval) {

    previousMillis = currentMillis;   

    //ultrasonic pulse

    pinMode(trigPin, OUTPUT);

    digitalWrite(trigPin, LOW);


    digitalWrite(trigPin, HIGH);


    digitalWrite(trigPin, LOW);


    //read bounce back wave

    pinMode(echoPin, INPUT);

    duration = pulseIn(echoPin, HIGH);



    //d = s*t

    cm = microsecondsToCentimeters(duration);


    //print results







long microsecondsToCentimeters(long microseconds)


  // 29 microseconds per centimeter, one way

  return microseconds / 29 / 2;


My guess (without really parsing the NewPing lib any deeper than I have to) is that using two pings with the library is a no-no, but I don't ever use it because it's almost easier for my money to hard code it. The thing is when you do hard code it, you make use of delays sensitive to the microsecond. If you have two sensors going at once then they're both going to get thrown off by the other's delays. There may be a way around this though. You're a pretty damned talented coder so I won't actually suggest a snippet or flow chart, but I will recommend you compare the standard "Blink" sketch to the BlinkWithOutDelay at this tutorial. Alternatively, look at how Oddbot dealt with a similar problem for the accelerometer in the MicroMagician at this walk through

I was hoping that the library would be a nice and easy way to get them working, alas, quiet the opposite. Thanks for the kind words and hopefully I can provide some evidence of that by making it work! I think it's research time into the delay department. OddBot has the answers to everything, is there anything that guy can't do.

The list of things I can't do is so long it won't fit on the server.
Basically I can't walk on water but my beer belly lets me float pretty good.

These Ultrasonic sensors are so simple that as Max says, it's really not worth the effort of using a library.
If you are using more than one Then allow time between reading them so that the echo from one sensor does not register on the other.

micros() is your friend.

I to believe it to be an interrupt conflict. Knowing that there is an element of timing in both libraries I can see how they could conflict if they were maybe using the same thing. Would it be possible to find out what both libraries are reffering to and maybe rename it in one of the libraries?