Collision avoidance robot code

This has been a frustrating problem for a while. I have ran several different sketches all resulting in the failure of the motors to run, with the exception of one sketch. With this sketch the robots doesn’t change direction when an obstacle is encountered. The ultrasonic sensor and servos functionality has been verified. I appreciate any help from the community, perhaps someone has an explanation as to why the motors run in the one sketch, but not the other,

Obstacle_Avoid_robot.ino (6.91 KB)

And what do the debug prints tell you?

     delay(100);                                      //Pause the program for half a second to let the robot turn

Comments that don't describe the code accurately are just noise.

    RightDistance = distance;                        //Set the variable RightDistance to the distance on the rightComments that just repeat what the code says are also simply noise.

When you use one Servo, PWM on two pins is disabled.

When you add more Servo instances, at some point PWM on two more pins is disabled.

The first two pins to lose PWM capability are 9 and 10.

You are trying to use PWM on pin 10 to control the speed of one motor. That is not going to work.