Error compiling for board Arduino Uno in my arduino ide

Hi! Can you please help me with my code? I attach a copy below.

#include <AFMotor.h>  // AFMotor Library https://learn.adafruit.com/adafruit-motor-shield/library-install 
#include <NewPing.h>  // NewPing Library https://github.com/livetronic/Arduino-NewPing
#include <Servo.h>// Servo Library https://github.com/arduino-libraries/Servo.git
#include "pitches.h"

#define TRIG_PIN A0
#define ECHO_PIN A1
#define MAX_DISTANCE 200
#define MAX_SPEED 150
#define MAX_SPEED_OFFSET 20

NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);

AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(2, MOTOR12_1KHZ);
Servo myservo;

boolean goesForward = false;
int distance = 100;
int speedSet = 0;
int melody[] = {NOTE_C4, NOTE_G3, NOTE_A3, NOTE_G3, 0 , NOTE_B3, NOTE_C4};
int noteDurations[] = {4, 8, 8, 4, 4, 4, 4, 4};
int pirSensor = 2;

void setup() {

  myservo.attach(10);
  myservo.write(115);
  delay(2000);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  pinMode(pirSensor, INPUT);
}

void loop() {
  int distanceR = 0;
  int distanceL =  0;
  int pirState = digitalRead(pirSensor);
  delay(40);

  if (distance <= 15)
  {
    moveStop();
    delay(100);
    moveBackward();
    delay(300);
    moveStop();
    delay(200);
    distanceR = lookRight();
    delay(200);
    distanceL = lookLeft();
    delay(200);
  }
   else if (pirState == 1) {

  for (int thisNote = 0; thisNote < 13; thisNote++) {

    int noteDuration = 1000 / noteDurations [thisNote];
    tone(13, melody [thisNote], noteDuration);

    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);

    noTone(13);

    if (distanceR >= distanceL)
    {
      turnRight();
      moveStop();
    } else
    {
      turnLeft();
      moveStop();
    }
  }
  {
    moveForward();
  }
  distance = readPing();

  }
}

int lookRight()
{
  myservo.write(50);
  delay(500);
  int distance = readPing();
  delay(100);
  myservo.write(115);
  return distance;
}

int lookLeft()
{
  myservo.write(170);
  delay(500);
  int distance = readPing();
  delay(100);
  myservo.write(115);
  return distance;
  delay(100);
}

int readPing() {
  delay(70);
  int cm = sonar.ping_cm();
  if (cm == 0)
  {
    cm = 250;
  }
  return cm;
}

void moveStop() {
  motor1.run(RELEASE);
  motor2.run(RELEASE);
}

void moveForward() {

  if (!goesForward)
  {
    goesForward = true;
    motor1.run(FORWARD);
    motor2.run(FORWARD);
    for (speedSet = 0; speedSet < MAX_SPEED; speedSet += 2)
    {
      motor1.setSpeed(speedSet);
      motor2.setSpeed(speedSet);
      delay(5);
    }
  }
}

void moveBackward() {
  goesForward = false;
  motor1.run(BACKWARD);
  motor2.run(BACKWARD);
  for (speedSet = 0; speedSet < MAX_SPEED; speedSet += 2)
  {
    motor1.setSpeed(speedSet);
    motor2.setSpeed(speedSet);
    delay(5);
  }
}

void turnRight() {
  motor1.run(FORWARD);
  motor2.run(BACKWARD);
  delay(450);
  motor1.run(FORWARD);
  motor2.run(FORWARD);
}

void turnLeft() {
  motor1.run(BACKWARD);
  motor2.run(FORWARD);
  delay(450);
  motor1.run(FORWARD);
  motor2.run(FORWARD);

}
I got these error messages:

exit status 1
Arduino: 1.8.15 (Windows 10), Board: "Arduino 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

Multiple libraries were found for "Servo.h"

Used: C:\Users\PapaE\OneDrive\Documents\Arduino\libraries\Servo

Not used: C:\Program Files (x86)\Arduino\libraries\Servo

exit status 1

Error compiling for board Arduino Uno.

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

Any help appreciated. Thanks.
-Eli

Try using ServoTimer2 instead of Servo.

This is not a bootloader issue.

please explain im new to arduino

Sorry, misread - it's the tone function and the NewPing library both trying to use the same timer interrupt.
I would probably be easier to not use the NewPing library, and simply drive the ranger unit directly.

Either way, it has nothing whatsoever to do with the bootloader, and is simply a programming issue.

The author of the NewPing library has provided an explanation and suggestions for fixing this error:
https://bitbucket.org/teckel12/arduino-new-ping/wiki/Multiple%20Definition%20of%20"__vector_7"%20Error

@compacked, your topic has been moved to a more suitable location on the forum.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.