Please help me with the code, Im using arduino UNO, connected an ultra sonic sensor and buzzer. The newping library is new for me, so I want that if distance is less than 50 cm , then buzzer should be activated. I have the code here, that I wrote...
#include <NewPing.h>
#define TRIGGER_PIN 7 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 8 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
const int buzzer = 6;
void setup() {
Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
pinMode(buzzer, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
delay(50);
// Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
Serial.print("Ping: ");
Serial.print(sonar.convert_cm(uS)); // Convert ping time to distance and print result (0 = outside set distance range, no ping echo)
Serial.println("cm");
if
(sonar.convert_cm(uS) < 50)
{
tone(buzzer, 1300);
delay(48);
digitalWrite(LED_BUILTIN, LOW);
}
}
And here are the errors
Arduino: 1.8.3 (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.
Whats the problem ?