Problem Compiling code with Servo library.

I am trying to control a servo with a Joystick module.When compiling it throws an stating "Arduino: 1.6.12 (Windows 10), Board: “Arduino/Genuino Uno”

libraries\VirtualWire\VirtualWire.cpp.o (symbol from plugin): In function `vw_crc’:

(.text+0x0): multiple definition of `__vector_11’

libraries\Servo\avr\Servo.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."

Could anyone figure out what’s the problem?

Here is the code:

#include <Servo.h>
#include <VirtualWire.h>


const int trigPin = 5;
const int echoPin = 8;
const int RedLED = 10;
const int GreenLED = 11;
const int buzzer = 12;
long distance , duration;
int pos = 0;
Servo myservo;


void setup() {

 Serial.begin(9600);
 vw_setup(2000);
 vw_set_rx_pin(2);
 myservo.attach(6);
 vw_rx_start();
 pinMode(trigPin , OUTPUT);
 pinMode(echoPin , INPUT);
 pinMode(RedLED , OUTPUT);
 pinMode(GreenLED , OUTPUT);
 pinMode(buzzer , OUTPUT);
}

void loop() {

 uint8_t buf[VW_MAX_MESSAGE_LEN];
 uint8_t buflen = VW_MAX_MESSAGE_LEN;
 if (vw_get_message(buf , &buflen))
 {
   int i;

   digitalWrite(13 , true);

   for ( i = 0; i < buflen ; i++)
   {

     Serial.print(buf[i]);

     if (buf[i] == 's')
     {
       myservo.write(0);
       calculateDistance();
       detectObstacle();
     }
     if (buf[i] == 'l')
     {

       for (pos = 45; pos <= 90 ; pos+=1)
       {
         myservo.write(pos);
         delay(10);
         calculateDistance();
         detectObstacle();

       }
     }
     if (buf[i] == 'r')
     {

       for (pos = 90; pos >= 45; pos-=1)
       {
         myservo.write(pos);
         delay(10);
         calculateDistance();
         detectObstacle();
       }
     }
   }
   digitalWrite(13 , false);
 }

}
int calculateDistance()
{
 digitalWrite(trigPin , LOW);
 delayMicroseconds(2);
 digitalWrite(trigPin , HIGH);
 delayMicroseconds(10);
 digitalWrite(trigPin , LOW);
 duration = pulseIn(echoPin , HIGH);
 distance = duration / 58.2;
 return distance;
}
void detectObstacle()
{

 if (distance < 15)
 {

   Serial.println(" OBSTACLE DETECTED ");
   digitalWrite(RedLED , HIGH);
   digitalWrite(GreenLED , LOW);
   tone(buzzer , 6000);
   delay(2);

 }
 else
 {

   Serial.println(" NO OBSTACLE DETECTED");
   digitalWrite(RedLED , LOW);
   digitalWrite(GreenLED , HIGH);
   noTone(buzzer);
   delay(2);
 }

}

Link to answer

Power_Broker: Link to answer

Thanks a lot. It helped. :)