Problems when using <Servo.h> and <PulseSensorPlayground.h> liblaries

I am on project which uses servo motor and pulse sensor.
But whenever i try to comfile, i encounter an error like this.

libraries\Servo\avr\Servo.cpp.o (symbol from plugin): In function ServoCount': (.text+0x0): multiple definition of __vector_11'
sketch\sketch_dec02a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1

This is the code required to solve:

#define USE_ARDUINO_INTERRUPTS true
#pragma once

#include <PulseSensorPlayground.h>
#include <Servo.h> 
Servo servo;
PulseSensorPlayground pulseSensor;

const int PulseWire = 0;
const int RED = 3;
const int BLUE = 6;
const int START = 7;
const int RESET = 8;
const int servoPin = 9;    
const int buttonpin = 10;
const int LED13 = 13;
const int speakerpin = 12;
const int GSR = A2;
      
int Threshold = 550; 
int sensorValue = 0;
int gsr_average = 0;
int skin;// 피부전도율
int beat;//심장박동
int isLie = 0; // 거짓말일 경우 1
int gsrRange = 100; // gsr범위, 변경 가능 
int lieNum = 0; //거짓말 횟수
int angle = 0;                              

void GSR_BPM(int sB, int rB)
{
  long GSR_sum = 0;
  int myBPM = pulseSensor.getBeatsPerMinute();  // Calls function on our pulseSensor object that returns BPM as an "int".
  int BPM_sum = 0;
  int BPM_avg,Bpm_range;

  int diff_BPM = BPM_avg - beat;   //심장박동수는 증가하기 때문에 음수 고려x
  int BPM_range = BPM_avg / 11;
  
  if (sB == 1) // start버튼 클릭
  {
    if (pulseSensor.sawStartOfBeat()&& myBPM > 50 && myBPM < 160 )
    {
      delay(3000);
       
       Serial.println("  A HeartBeat Happened ! "); 
       Serial.print("BPM: ");                        
       Serial.println(myBPM);

       for(int i = 0 ; i < 10; i++)
       {
          BPM_sum += myBPM;
          sensorValue = analogRead(GSR);
          GSR_sum += sensorValue;
          delay(30);
       }
       BPM_avg = BPM_sum / 10;
       gsr_average = GSR_sum / 10;
    }
   
   int GSR_diff = gsr_average - skin;
   
   if (-gsrRange > GSR_diff || GSR_diff > gsrRange)
   {
    isLie = 1;
    return;
   }
   else if (BPM_range < diff_BPM)
   {
     isLie = 1;
     return;
   }
   else
   {
    return;
   }
  }

  if (rB == 1) // reset버튼 클릭
  {
    if (pulseSensor.sawStartOfBeat()&& myBPM > 50 && myBPM < 160 )
    {
      delay(5000); // 안정 기간
    
      for (int i = 0; i < 10; i++)
     {
      sensorValue = analogRead(GSR);
      GSR_sum += sensorValue;
      BPM_sum += myBPM;
      delay(30);
     }
    }
    
   BPM_avg = BPM_sum / 10;
   beat = BPM_avg;
   gsr_average = GSR_sum/10;
   skin = gsr_average; // 피부 전도율 기록
   return;
  }
}

 void setColor(int r,int g, int b)
{
  analogWrite(RED,r);
  analogWrite(BLUE,b);
  delay(1500);
  
  return;
}

void servoM(int n)
{
  if (n == 1)
  {
    servo.write(5);
    delay(500);
    
    for (angle = 5; angle < 30; angle++)
    {
      servo.write(angle);
      delay(20);
    }
  }
  
  else if (n == 2)
  {
    servo.write(30);
    delay(500);
    
    for (angle = 30; angle < 55; angle++)
    {
      servo.write(angle);
      delay(20);
    }
  }

  else if (n == 3)
  {
    servo.write(0);
    delay(500);
    servo.write(100);
  }

  return;
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(START, INPUT);
  pinMode(RESET, INPUT);
  pulseSensor.analogInput(PulseWire);   
  //LED는 일단 냅둠
  pulseSensor.blinkOnPulse(LED13);      
  pulseSensor.setThreshold(Threshold); 
  servo.attach(servoPin); 
  pinMode(buttonpin,INPUT);
  pinMode(RED,OUTPUT);
  pinMode(BLUE,OUTPUT);

  if (pulseSensor.begin()) {
    Serial.println("START!");  //This prints one time at Arduino power-up,  or on Arduino reset.  
  }
}

void loop() 
{
  // put your main code here, to run repeatedly:
  int startB = digitalRead(START);
  int resetB = digitalRead(RESET);

  if (startB == 1)
  {
    GSR_BPM(1, 0);
    if (isLie == 1) // LED, 알림 소리, 서보 모터
    {
      lieNum++;
      tone(speakerpin,500,500);
      setColor(255, 0, 0);
      servoM(lieNum);
      setColor(0, 0, 0);
    }
    else //(isLie == 0) -> LED
    {
      setColor(0, 0, 255);
      setColor(0, 0, 0);
    }
  }

  if (resetB == 1)
  {
    GSR_BPM(0, 1);
    tone(speakerpin,500,500);
  }

  //if (게임 종료(3번 거짓말) == 1) -> 게임 종료, reset버튼으로 다시 시작. 거짓말 횟수 초기화 필요
  if (lieNum == 3)
  {
    tone(speakerpin, 500, 500);
    setColor(200, 0, 200);
    lieNum = 0;
  }  
  startB = 0; // 초기화
  resetB = 0; // 초기화
  isLie = 0;
}```

That means that two libraries are both using the same timer interrupt. I suggest you find the ServoTimer2 library and use that in place of the Servo library.

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