I'm writing the code in VS Code on IO Platform. Yesterday i finished my code and uploaded it to the Arduino Uno. It works fine. Next day i launched the VS Code and i changed the code a bit, then i uploaded it and i got the error.


Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':
(.text+0x0): multiple definition of `__vector_7'
NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\uno\firmware.elf] Error 1

I am using the libary NewPing.h. The code should does this: If is distance more than 20cm, the the buzz makes the sound and turns on the red led. If distance is less than 20cm, the blue led turns on

The code:

#include <Arduino.h>  //It has to be there, because the arduino ide in VS Code will not work.

#include <NewPing.h>

#define echo_pin 3
#define trig_pin 4
#define max_range 450

#define red_led_pin 7
#define blue_led_pin 9
#define buzz_pin 10

int distance = 0;

NewPing sonar(trig_pin, echo_pin, max_range);

void setup(){
  pinMode(red_led_pin, OUTPUT);
  pinMode(blue_led_pin, OUTPUT);

  pinMode(buzz_pin, OUTPUT);

void loop() {

  distance = sonar.ping_cm();

  if (distance > 0) {
          distance = 0;

    for (int i=0; i<5; i++) {
      distance += sonar.ping_cm();
    distance /= 4;

    Serial.print("Distance: ");

    if (distance > 20) {

      digitalWrite(blue_led_pin, LOW);
      digitalWrite(red_led_pin, HIGH);
      tone(buzz_pin, 1500);
      tone(buzz_pin, 800);

    else {

      digitalWrite(red_led_pin, LOW);
      digitalWrite(blue_led_pin, HIGH);

I don't undersand, what has changed. I tried to import again the libary https://www.arduino.cc/en/guide/libraries by importing the *.zip file, also installing in IDE.

  • Please look into "NewPing.h". Is the line #define ENABLE_TIMER_BASED_PING 1 commented out or active?
    – chrisl
    Apr 9, 2020 at 9:25
  • Did you change the pin numbers from before? If yes, which exactly?
    – chrisl
    Apr 9, 2020 at 9:37
  • @chrisl How can i look into? How to open that file? Apr 10, 2020 at 16:18
  • I'm not sure, why you are asking be that. It is a simple text file. You can open it with any text editor. All the source files are pure text files, that can be edited easily with any text editor
    – chrisl
    Apr 10, 2020 at 16:24
  • I was able to compile your code without errors (using the Arduino IDE). I used this NewPing library from github. Please give us information about, which NewPing library you have used exactly.
    – chrisl
    Apr 10, 2020 at 16:37

1 Answer 1


You have a conflict of interrupts. Both the internal tone() command and the NewPing.h use Timer 2 by default, which makes them mutually exclusive.

However you can change NewPing to not use a timer by editing the src/NewPing.h file and setting TIMER_ENABLED to be false:

    #define TIMER_ENABLED true      // Set to "false" to disable the timer ISR (if getting "__vector_7" compile errors set this to false). Default=true
  • I wrote it to the my code under line with including th libary, but nothing has changed. What exactly and where should i type it? Finally, I installed the library based on instructions in this video: youtube.com/watch?v=_pSVzV4PdiA Apr 10, 2020 at 16:23
  • @AuthorCliment Majenko asked you to change the corresponding line in the NewPing.h file, not in your sketch. Open the NewPing.h file (which you can find somewhere in your libraries folder) with a text editor, find that line and change it according to Majenkos answer
    – chrisl
    Apr 10, 2020 at 16:25
  • @chrisl I dound that line. I changed it to false. And I'm still getting the same error. Apr 10, 2020 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.