Error: timer0_pin_port & exit status 1

A few days ago I was working with ARDUINO UNO. The program consist on pressing a button, so a machine can start working. After 5 seconds, a proximity sensor has to sense the object for at least, 3 seconds (if not, it would make noise).

Once the button is pushed, and after 5 seconds the sensor fail to sense the object, a buzzer should ring, warning that the machine is not working properly. The buzzer will stop once the user presses the reset button.

Here is the code that I wrote:

int Pinpulsador=2;// declaro las variables
#define Pintrig 6
#define Pinecho 7
#define max_distance 200
NewPing sonar(Pintrig, Pinecho, max_distance);
int Pinbuzzer=9;
int distance;
int duracion;
void setup() {
  Serial.begin (9600);
  pinMode(Pintrig, OUTPUT);
  pinMode(Pinecho, INPUT);

void loop() {
          if (Pinpulsador==HIGH){
              delay (5000);
              if(distance > 0) {
                 long duracion, distance;
            digitalWrite(Pintrig, LOW);        // Nos aseguramos de que el trigger está desactivado
            delayMicroseconds(100);              // Para asegurarnos de que el trigger esta LOW
            digitalWrite(Pintrig, HIGH);       // Activamos el pulso de salida
            delayMicroseconds(3000);             // Esperamos 10µs. El pulso sigue activo este tiempo
            digitalWrite(Pintrig, LOW);        // Cortamos el pulso y a esperar el echo
            duracion = pulseIn(Pinecho, HIGH);
        else if (distance>0 && distance<10){
          long duracion, distance;
            digitalWrite(Pintrig, LOW);       
            digitalWrite(Pintrig, HIGH);       
            digitalWrite(Pintrig, LOW);       
            duracion = pulseIn(Pinecho, LOW);
   }else (Pinpulsador==LOW && Pintrig==LOW);
   delay (5000);
    digitalWrite(Pintrig, LOW);
     digitalWrite(Pintrig, LOW);
     digitalWrite(Pintrig, LOW);
     duracion= pulseIn(Pinecho, LOW);
     tone (Pinbuzzer, 400);

And this is the error that it shows:

Arduino: 1.8.9 (Windows 10), 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.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Yours Faithfully, Violeta

PS: Bare in mind that I’m not a native speaker, so I’m sorry if I made some mistakes.

There is a timer conflict between NewPing and Tone.

The NewPing author has developed a NewTone library you can use. See

From the wiki
Timer 2 Conflict
Having a conflict with the tone library or another library using timer 2? Instead of the tone library, use my NewTone or toneAC libraries which instead uses timer 1 (and also has many other advantages). Or use my Timer Free Tone library which doesn't use any timers to generate tones.
Multiple Definition of "_vector_7" Error
Wiki help page on how to resolve the multiple definition of "_vector_7" error.