Vector 11 Problem

Arduino: 1.6.6 (Windows 8.1), Board: "Arduino Nano, ATmega328"

libraries\Servo\avr\Servo.cpp.o: In function `__vector_11':

C:\Users\Kevin\Downloads\Compressed\arduino-1.6.6-windows\arduino-1.6.6\libraries\Servo\src\avr/Servo.cpp:81: multiple definition of `__vector_11'

libraries\NewTone\NewTone.cpp.o:C:\Users\Kevin\Downloads\Compressed\arduino-1.6.6-windows\arduino-1.6.6\libraries\NewTone/NewTone.cpp:46: first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling.

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

I encountering this kind of problem , im using a servo with a sensor and an alarm attach on it . How can i resolve this one ? I really need help . its my 1st time to code arduino board please , if you want to see my code i can reply it to you if you need it .

The tone() uses the same timer as the Servo library.

Try an alternative tone library : teckel12 / Arduino toneAC / wiki / Home — Bitbucket

Still got the same problem sir :frowning: i probably need help . This is my code btw , i just really need help my very 1st try to code this board .

#include <NewPing.h>
#include <toneAC.h>
#include <Servo.h>

const int RED_PIN = 9;
const int GREEN_PIN = 11;
const int BLUE_PIN = 3;
const int ALARM = 9;

const int trigPIN = 6;
const int echoPIN = 7;

int pos=0;
int MAX_DISTANCE = 100;

float sinVal;
int toneVal;

Servo myservo;
NewPing sonar(trigPIN,echoPIN,MAX_DISTANCE);
boolean triggered = false;

void setup() {
pinMode(RED_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
pinMode(GREEN_PIN,OUTPUT);

pinMode(trigPIN, OUTPUT);
pinMode(echoPIN, INPUT);

pinMode(ALARM, OUTPUT);

Serial.begin(9600);
myservo.attach(12);

analogWrite(RED_PIN,0);
analogWrite(BLUE_PIN,0);
analogWrite(GREEN_PIN,0);

delay(5000);
Serial.begin(115200); // open serial monitor at 115200 baud to see ping results

}

void color(unsigned char red, unsigned char green , unsigned char blue){
analogWrite(RED_PIN,red);
analogWrite(BLUE_PIN,blue);
analogWrite(GREEN_PIN,green);
}
void alarm(){
color(255,0,0);
delay(100);
color(255,255,0);
delay(100);
for (int x=0; x<180; x++) {
// convert degrees to radians then obtain sin value
sinVal = (sin(x*(3.1412/180)));
// generate a frequency from the sin value
toneVal = 2000+(int(sinVal*1000));
toneAC(ALARM, toneVal);
delay(50000);
break;
}
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
if(triggered==true){ // alarm
alarm();
}
else{
delay(50);
unsigned int uS = sonar.ping();
unsigned int distance = uS/ US_ROUNDTRIP_CM;
Serial.println(distance);
if(distance<100){
triggered =true;
}
}
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
if(triggered==true){ // alarm
alarm();
}
else{
delay(50);
unsigned int uS = sonar.ping();
unsigned int distance = uS/ US_ROUNDTRIP_CM;
Serial.println(distance);
if(distance<100){
triggered =true;
}
}
}
}

The Servo library uses Timer1, the NewPing uses Timer2.
The ATmega328P has three timers, and Timer0 is used for the Arduino time with millis().
The Servo and NewPing can be set to other timers, but the ATmega328P has no other timers.

The analogWrite(), which is PWM, also uses timers.
Pin 9 = Timer1
Pin 11 = Timer2
Pin 3 = Timer2
See the pinmapping: Arduino - PinMapping168

Could you remove (comment out) the calls to tone() or toneAC() and remove the include of a tone library.
Also remove (comment out) the analogWrite().
Will it compile ?
I think it will.

It is possible to use a tone library without the use of a timer : teckel12 / Arduino Timer Free Tone / wiki / Home — Bitbucket

Try the analogWrite(), I think it will not work.
Could you use a NeoPixel or WS2811 driver RGB led ?

This is your first Arduino project, and you already hit its limits ? That's nasty ! I hope you are not disappointed. For every problem is a solution. There are many modules to add or other Arduino boards.

Do you have enough power for the servo motors ?

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Thanks, makes reading a sketch inline so much easier. Tom… :slight_smile:

#include <NewPing.h>
/#include <toneAC.h>/
#include <Servo.h>

const int RED_PIN = 10;
const int GREEN_PIN = 12;
const int BLUE_PIN = 3;
const int ALARM = 9;

const int trigPIN = 6;
const int echoPIN = 7;

int pos=0;
int MAX_DISTANCE = 100;

float sinVal;
int toneVal;

Servo myservo;
NewPing sonar(trigPIN,echoPIN,MAX_DISTANCE);
boolean triggered = false;

void setup() {
pinMode(RED_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
pinMode(GREEN_PIN,OUTPUT);

pinMode(trigPIN, OUTPUT);
pinMode(echoPIN, INPUT);

pinMode(ALARM, OUTPUT);

Serial.begin(9600);
myservo.attach(11);

analogWrite(RED_PIN,0);
analogWrite(BLUE_PIN,0);
analogWrite(GREEN_PIN,0);

delay(5000);
Serial.begin(115200); // open serial monitor at 115200 baud to see ping results

}

void color(unsigned char red, unsigned char green , unsigned char blue){
analogWrite(RED_PIN,red);
analogWrite(BLUE_PIN,blue);
analogWrite(GREEN_PIN,green);
}
void alarm(){
color(255,0,0);
delay(100);
color(255,255,0);
delay(100);
for (int x=0; x<180; x++) {
// convert degrees to radians then obtain sin value
sinVal = (sin(x*(3.1412/180)));
// generate a frequency from the sin value
toneVal = 2000+(int(sinVal1000));
/
toneAC(ALARM, toneVal); */
delay(50000);
break;
loop();
}
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
if(triggered==true){ // alarm
alarm();
}
else{
delay(50);
unsigned int uS = sonar.ping();
unsigned int distance = uS/ US_ROUNDTRIP_CM;
Serial.println(distance);
if(distance<100){
triggered =true;
}
}
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
if(triggered==true){ // alarm
alarm();
}
else{
delay(50);
unsigned int uS = sonar.ping();
unsigned int distance = uS/ US_ROUNDTRIP_CM;
Serial.println(distance);
if(distance<100){
triggered =true;
}
}
}
}

This is my updated code sir , no error already but is this works ? Is the alarm still alarms ? I appreciate all negative/postive comment you will say sir. I think servo will run smoothly powered by a 5v dc source well it is small also . The analogwrite thing you comment sir i cant barely understand can you manipulate the code for me . I`m really sorry about this :frowning:

TomGeorge:
Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Thanks, makes reading a sketch inline so much easier. Tom… :slight_smile:

Do you mean an algorithm of my project sir ? I`m very sorry for asking you again a question sir sorry

Hi,
The sketch you posted on post #5 needs to be put in code tags.
So it looks like this.

#include <NewPing.h>
/*#include <toneAC.h>*/
#include <Servo.h>


const int RED_PIN = 10;
const int GREEN_PIN = 12;
const int BLUE_PIN = 3;
const int ALARM = 9;

const int trigPIN = 6;
const int echoPIN = 7;

int pos=0;
int MAX_DISTANCE = 100;


float sinVal;
int toneVal;

Servo myservo;
NewPing sonar(trigPIN,echoPIN,MAX_DISTANCE);
boolean triggered = false;


void setup() {
  pinMode(RED_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
  pinMode(GREEN_PIN,OUTPUT);
  
  pinMode(trigPIN, OUTPUT);
  pinMode(echoPIN, INPUT);
  
  pinMode(ALARM, OUTPUT);
  
  Serial.begin(9600);
  myservo.attach(11);
 
  analogWrite(RED_PIN,0);
  analogWrite(BLUE_PIN,0);
  analogWrite(GREEN_PIN,0);

  delay(5000);
   Serial.begin(115200); // open serial monitor at 115200 baud to see ping results
  
}

void color(unsigned char red, unsigned char green , unsigned char blue){
  analogWrite(RED_PIN,red);
  analogWrite(BLUE_PIN,blue);
  analogWrite(GREEN_PIN,green);
}
void alarm(){
  color(255,0,0);
  delay(100);
  color(255,255,0);
  delay(100);
  for (int x=0; x<180; x++) {
    // convert degrees to radians then obtain sin value
    sinVal = (sin(x*(3.1412/180)));
    // generate a frequency from the sin value
    toneVal = 2000+(int(sinVal*1000));
   /* toneAC(ALARM, toneVal); */
     delay(50000);
     break;
   loop();
  }
}
void loop() {
   for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
    if(triggered==true){  // alarm
      alarm();
    }
    else{
      delay(50);
      unsigned int uS = sonar.ping();
      unsigned int distance = uS/ US_ROUNDTRIP_CM;
      Serial.println(distance);
      if(distance<100){
        triggered =true;
      }
      }
    }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
     if(triggered==true){ // alarm
      alarm();
    }
    else{
      delay(50);
      unsigned int uS = sonar.ping();
      unsigned int distance = uS/ US_ROUNDTRIP_CM;
      Serial.println(distance);
      if(distance<100){
        triggered =true;
      }
      }
  }
}

Tom… :slight_smile:

kevin100:
Do you mean an algorithm of my project sir ? I`m very sorry for asking you again a question sir sorry

He means pictures, images, diagrams of your physical hardware.