Upload error

Hi,

I am working on a project in which I use the HC-SR04 sensor. This is my first time using Arduino libraries so the origin of my error is probably in my inexperience.

So, every time when I try to upload the code (down below), I get this error:

Error compiling for board Arduino/Genuino Uno.

#include <NewPing.h>
 
#define TRIGGER_PIN 6
#define ECHO_PIN 7
#define MAX_DISTANCE 100
 
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); 
int music; 
void setup() {
   Serial.begin(9600);
   pinMode(13, OUTPUT);
   pinMode(8, OUTPUT);
   
}
 void loop() {

   delay(150);
   unsigned int uS = sonar.ping_cm();
   music = map(uS, 1, 100, 40, 6500);
   Serial.print(uS);
   Serial.println("cm");
   tone(8, music);
   if( uS < 20){
      digitalWrite(13, 1);
      
   }
   else{
     digitalWrite(13, 0);
   }
}

Is there anything that I’m missing? I have no clue about what could have caused this error, since I have successfully used this library in my previous version. Also, other .ino files load to arduino with no problem.

I thank you in advance for your replies.

Simon.

That's the last line of the compiler output that just says it saw an error. Go get the actual error message above that where it says what was actually wrong.

Thank you. This is what I got:

Arduino: 1.8.2 (Windows 7), Board: "Arduino/Genuino Uno"

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

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

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

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

What does this mean? :slight_smile:

It means that NewPing and Tone are both trying to use the same timer interrupt. Those libraries aren't going to be compatible then. Can't use them both in the same sketch. Maybe someone has a different library for one of them that uses a different timer.

There are definitely ultrasonic sensor libraries that don't use interrupts or you can just write the code in your sketch, it's only a few lines and there are plenty examples available. That's not to say there's no point in using the NewPing library/ I'm sure it's a very good library, but there are other options for using an ultrasonic sensor if you can't use it.