OAR - Analog write on pin 10 won't work

Hi, I’ve built a classic Obstacle Avoidance Robot with the Elegoo kit and I’m having trouble getting it to work properly. Everything seems to work with a simple sketch from the disc that correctly operates all wheels. I then load the obstacle avoidance sketch and notice the wheels on the right side do not operate. (It’s as if my bot has a stroke.) I re-examined all of my connections and verified everything is properly connected. After all the AUTO_GO sketch works without issue. I started to debug by comparing the sketch to another working sketch from the disc which correctly operates all wheels. That’s when I realized the code from the disc included in my kit had an error. It was sending analogWrite(ENA,ABS); and ENA was set to pin 11 instead of pin 10 which is the pin connected to my L298 motor driver board.

Here’s where it is weird. When I use digitalWrite to the same pin 10, it works fine. It just doesn’t seem to respect the analogWrite. I thought there may be a voltage shortage or weak batteries so I tried disabling everything in the sketch except for the analogWrite to pin 10 and I still have the same behavior. I don’t understand why changing from digital to analog does not work. I would like to use analog as in the example for speed control. I’m including my sketch below as well as pages from the assembly guide which I followed completely.

I am brand new to robotics and this is my first bot. My kit is brand new purchased 1 week ago. Please advise how to diagnose these issues and/or what could be wrong in my case.

#include <Servo.h> //servo library
Servo myservo; // create servo object to control servo
int Echo = A4;  
int Trig = A5; 
/*define logic control output pin*/
int in1=9;
int in2=8;
int in3=7;
int in4=6;
/*define channel enable output pins*/
int ENA=10;
int ENB=5;
int ABS = 130;
int rightDistance = 0,leftDistance = 0,middleDistance = 0 ;

void enableMotors()
{
//  digitalWrite(ENA,HIGH);
//  digitalWrite(ENB,HIGH);
  analogWrite(ENA,ABS);
  analogWrite(ENB,ABS);
}
void _mForward()
{
 enableMotors();
// digitalWrite(in3,LOW);
// digitalWrite(in4,HIGH);
 digitalWrite(in1,LOW);
 digitalWrite(in2,HIGH);
 Serial.println("go forward!");
}

void _mBack()
{
 enableMotors();
 digitalWrite(in1,HIGH);
 digitalWrite(in2,LOW);
 digitalWrite(in3,HIGH);
 digitalWrite(in4,LOW);
 Serial.println("go back!");
}

void _mleft()
{
 enableMotors();
 digitalWrite(in1,LOW);
 digitalWrite(in2,HIGH);
 digitalWrite(in3,HIGH);
 digitalWrite(in4,LOW);
 Serial.println("go left!");
}

void _mright()
{
 enableMotors();
 digitalWrite(in1,HIGH);
 digitalWrite(in2,LOW);
 digitalWrite(in3,LOW);
 digitalWrite(in4,HIGH);
 Serial.println("go right!");
} 
void _mStop()
{
  digitalWrite(ENA,LOW);
  digitalWrite(ENB,LOW);
  Serial.println("Stop!");
} 
 /*Ultrasonic distance measurement Sub function*/
int Distance_test()   
{
  digitalWrite(Trig, LOW);   
  delayMicroseconds(2);
  digitalWrite(Trig, HIGH);  
  delayMicroseconds(20);
  digitalWrite(Trig, LOW);   
  float Fdistance = pulseIn(Echo, HIGH);  
  Fdistance= Fdistance/58;       
  return (int)Fdistance;
}  

void setup() 
{ 
  myservo.attach(3);// attach servo on pin 3 to servo object
  Serial.begin(9600);     
  pinMode(Echo, INPUT);    
  pinMode(Trig, OUTPUT);  
  pinMode(in1,OUTPUT);
  pinMode(in2,OUTPUT);
  pinMode(in3,OUTPUT);
  pinMode(in4,OUTPUT);
  pinMode(ENA,OUTPUT);
  pinMode(ENB,OUTPUT);
  _mStop();
} 

void loop() 
{ 
    myservo.write(90);//setservo position according to scaled value
    delay(500); 
    middleDistance = Distance_test();
    #ifdef send
    Serial.print("middleDistance=");
    Serial.println(middleDistance);
    #endif

    if(middleDistance<=20)
    {     
      _mStop();
      delay(500);                         
      myservo.write(5);          
      delay(1000);      
      rightDistance = Distance_test();

      #ifdef send
      Serial.print("rightDistance=");
      Serial.println(rightDistance);
      #endif

      delay(500);
       myservo.write(90);              
      delay(1000);                                                  
      myservo.write(180);              
      delay(1000); 
      leftDistance = Distance_test();

      #ifdef send
      Serial.print("leftDistance=");
      Serial.println(leftDistance);
      #endif

      delay(500);
      myservo.write(90);              
      delay(1000);
      if(rightDistance>leftDistance)  
      {
        _mright();
        delay(180);
       }
       else if(rightDistance<leftDistance)
       {
        _mleft();
        delay(180);
       }
       else if((rightDistance<=20)||(leftDistance<=20))
       {
        _mBack();
        delay(180);
       }
       else
       {
        _mForward();
       }
    }  
    else
        _mForward();                     
}

From: https://www.arduino.cc/en/Reference/Servo

On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins.

Thank you sooo much! That was it! It also explains why the original code was modified to work with pin 11!! I was confused because the instructions clearly detail using pin 11 for the line tracers on the bottom of the bot. Thanks tremendously!!!

Glad to hear it's working now. Enjoy! Per