Servo motor stops working after audio output using Bluetooth

Guys I am having a problem with servo motor.
I am using a Bluetooth module, a sd card module and a speaker to play wav files from mobile commands. I am also using a servo motor with a seperate battery of 5v. My problem is that whever after playing wav file the servo stops working. Before playing the wav file the servo works properly. I am using mg995 servo motor. A hc 05 bluetooth module.
Please help me

one more thing i need to tell is that , iam also using a l298 motor driver to run dc motors.i using the power supply to driver to run arduino also y using vin pin and a seperate power supply to run the dc motor.as as soon as i play audio the motor stops working. iam also providing the. maye there is problem in code.
please help me

#include <Servo.h>; 
Servo myservo;

#include "SD.h"
#define SD_ChipSelectPin 10
#include "TMRpcm.h"
#include "SPI.h"

TMRpcm music;
String voice;
const int IN1 = 7;
const int IN2 = 4;
const int IN3 = 8;
const int IN4 = 2;


const int ENA = 5;
const int ENB = 6;


void setup() {

  myservo.attach(3);
music.speakerPin=9;
Serial.begin(38400);
if(!SD.begin(SD_ChipSelectPin))
{
  Serial.println("SD fail");
  return;
}
music.setVolume(5);

pinMode (IN1, OUTPUT);
  pinMode (IN2, OUTPUT);
  pinMode (IN3, OUTPUT);
  pinMode (IN4, OUTPUT);
  pinMode (ENA, OUTPUT);
  pinMode (ENB, OUTPUT);
 

   const int ENA = 5;
const int ENB = 6;

}
//-----------------------------------------------------------------------//  
void loop() {
  while (Serial.available()){  //Check if there is an available byte to read
  delay(10); //Delay added to make thing stable 
  char c = Serial.read(); //Conduct a serial read
  if (c == '#') {break;} //Exit the loop when the # is detected after the word
  voice += c; //Shorthand for voice = voice + c
 

  }  


    
   analogWrite(ENA, 100);
  analogWrite(ENB, 100); 
  
  if (voice.length() > 0) {
    Serial.println(voice);

  if(voice == "play faded") 
  {
    music.play("faded.wav");
  } 
  
  if(voice == "play hello") 
  {
    music.play("hello.wav");
  } 
  
  if(voice == "play alone") 
  {
    music.play("alone.wav");
  } 
   if(voice == "what is your name") 
  {
    music.play("name.wav");
  } 
   if(voice == "who created you") 
  {
    music.play("creator.wav");
  } 
   if(voice == "which is his class") 
  {
    music.play("class.wav");
  } 
   if(voice == "who are you") 
  {
    music.play("anvayrobot.wav");
  } 
   if(voice == "play midnight") 
  {
    music.play("midnight.wav");
  }  
  if(voice == "play fat rat") 
  {
    music.play("fatrat.wav");
  } 
  if(voice == "play animals") 
  {
    music.play("animals.wav");
  } 
  if(voice == "45"){myservo.write(45);
}
  if(voice == "90"){myservo.write(90);
  }

   if(voice == "0"){myservo.write(0);
  }
   if(voice == "180"){myservo.write(180);
 }
  if(voice == "down") 
  {
     digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  } 

   if(voice == "front") 
  {
    digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  } 

   if(voice == "stop") 
  {
    digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
  } 

    if(voice == "front1") 
  {
    digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
  } 
  if(voice == "down1") 
  {
    digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
  } 
  if(voice == "left1") 
  {
    digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
  } 
  if(voice == "right1") 
  {
    digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
  } 
  if(voice == "right") 
  {
    digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
  } 
  if(voice == "left") 
  {
    digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  } 
voice="";}}

My wild guess is that the code to play the WAV file is using the Hardware Timer that is normally used for producing the servo signal. Maybe try the ServoTimer2 library.

...R

thanks for replying. i am not quite experienced in arduino. can u please do the changes in the code to include servotimer2 library . i have installed the library in my laptop.

Have you studied the example that comes with the library?

I think all you need to do is change

#include <Servo.h>;
Servo myservo;
to
#include <ServoTimer2.h>;
ServoTimer2  myservo;

and then you need to change the values in myservo.write() from degrees to microseconds. 0 deg is about 1000 microsecs and 180 deg is about 2000 microsecs.

...R

thanks it worked. however i am not getting correct roation. i kept 0 as 1000, 45 as 1250, 90 as 1500 and 180 as 2000. any suggestion?

Anvay:
thanks it worked. however i am not getting correct roation. i kept 0 as 1000, 45 as 1250, 90 as 1500 and 180 as 2000. any suggestion?

Is 1500 about 90 though? If so, maybe it's just backwards- try 0 for 180 and 2000 for 0 degrees.

And/or. describe what seems to be happening.