help with code for autonomous vehicle using ultrasonic sensor

so i am trying to make a autonomous vehicle with obstacle detection and avoiding. for that i am using ultrasonic sensor module HC-SR04. i can get the sensor readings fine but the problem is when i try to control motors.i am using motor drivers to drive the motors.the problem is only the motor connected to pin 5 runs the one connected to pin 9 doesn’t. i have tried exchanging the pins but the one connected to pin 9 doesn’t run. is there some problem with my code? or is it just the way analogWrite works? here’s my code

#include<Servo.h>
#define trig 7
#define echo 4
#define left_motor_pin1 9
#define right_motor_pin1 5
#define servo_pin 11
unsigned long int duration;
Servo sweeper;

void setup() {
  // put your setup code here, to run once:
  pinMode(trig, OUTPUT);
  digitalWrite(echo, LOW);
  pinMode(echo, INPUT);
  sweeper.attach(servo_pin);
  sweeper.write(70);
  Serial.begin(9600);
}

//=================ULTRASONIC DISTANCE================
void trigger() {
  digitalWrite(trig, LOW);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(15);
  digitalWrite(trig, LOW);
  delayMicroseconds(5);
}
int convert_to_distance(unsigned long int time)
{
  return time / 58;
}
//=================MOTOR CONTROL======================
void default_speed() {
  analogWrite(left_motor_pin1, 200);
  analogWrite(right_motor_pin1, 200);

}

void reduce_speed() {
  analogWrite(left_motor_pin1, 100);
  analogWrite(right_motor_pin1, 100);

}

void right_turn() {
  analogWrite(left_motor_pin1, 200);
  analogWrite(right_motor_pin1, 100);

}

void left_turn() {
  analogWrite(left_motor_pin1, 100);
  analogWrite(right_motor_pin1, 200);

}

void sweep_n_read() {
  unsigned long int lefttime;
  unsigned long int righttime;
  sweeper.write(130);//left turn
  delay(100);
  trigger();
  lefttime = pulseIn(echo, HIGH);
  int left = convert_to_distance(lefttime);
  Serial.print("left: ");
  Serial.println(left);
  sweeper.write(30);//right turn
  delay(100);
  trigger();
  righttime = pulseIn(echo, HIGH);
  int right = convert_to_distance(righttime);
  Serial.print("right: ");
  Serial.println(right);

  if (left > right) { //more space to left
    left_turn();
  }
  else if (right > left) { //more space to right
    right_turn();
  }
}

void control(int dist) {

  if (dist <= 50 && dist > 20) { //normal action
    sweep_n_read();
    default_speed();
  }
  else if (dist <= 20) //emergency
  {
    reduce_speed();
    sweep_n_read();
    default_speed();
  }
  else
    default_speed();
}

void loop() {
  // put your main code here, to run repeatedly:
  sweeper.write(70);
  delay(100);
  trigger();
  duration = pulseIn(echo, HIGH);
  int dis = convert_to_distance(duration);
  Serial.println(dis);
  control(dis);
  //delay(1000);
}

When you attach a servo, you use a timer. The timers control PWM on pairs of pins. Using one for the servo means that you give up PWM control of two pins. The first pins to lose PWM capabilities are 9 and 10.

Try using 3, 5, 6, and/or 11 for the motor control pins.

Thanks!! this helped, i connected the motors to pins 5 and 3 and everything works fine