Problem combining the ultrasonic sensor arduino code with another code

Hello i’m doing a project on controlling an RC toy car using android application , the arduino receives a command from the app via bluetooth (F, B, R, or L) and the car moves forward , backwards , left or right. the project also includes the app receiving data taken from an ultrasonic sensor connected on a servo motor above the car and data from a temperature sensor. the project works just fine without adding the ultrasonic sensor code or the temp sensor code , when i add any of them ( for the ultrasonic i used the one in the built in examples in arduino) i receive the data on the app but the car goes haywire … i disconnect the bluetooth and it moves forward , backwards left or right without any commands !!
i’m new to using arduino and i used chunks of online codes to make this program
this is the code with the ultrasonic sensor
#include <Servo.h>
#include <L293.h>
#define pinLeft 10
#define pinRight 11

#define pinForward 5
#define pinBack 6

//L293(pinLeft, pinRight, pinLftRgtEn, pinForward, pinBack, pinFwdBakVel);
L293 yellowCar(pinLeft,pinRight,0,pinForward,pinBack,0);
char command = ‘S’;
char prevCommand = ‘A’;
int velocity = 0;
unsigned long timer0 = 2000; //Stores the time (in millis since execution started)
unsigned long timer1 = 0; //Stores the time when the last command was received from the phone
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos;
int pos1 = 0; // variable to store the servo position
const int pingPin = 7;
long duration, cm;
void setup(){
Serial.begin(9600); //Set the baud rate to that of your Bluetooth module.

myservo.attach(4); // attaches the servo on pin 4 to the servo object
}

void loop(){
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);

// convert the time into a distance

cm = microsecondsToCentimeters(duration);

Serial.print(cm);
Serial.print(“cm”);
Serial.println();

delay(1000);
if(Serial.available() > 0){
timer1 = millis();
prevCommand = command;
command = Serial.read();
//Change pin mode only if new command is different from previous.
if(command!=prevCommand){
//Serial.println(command);
switch(command){
case ‘F’:
yellowCar.forward_4W(velocity);
break;
case ‘B’:
yellowCar.back_4W(velocity);
break;
case ‘L’:
yellowCar.left_4W();
break;
case ‘R’:
yellowCar.right_4W();
break;
case ‘S’:
yellowCar.stopped_4W();
break;

}
}
if (command ==‘F’)
{ pos = pos1;// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15);

} else if (command ==‘R’)
{ pos = pos1-45;// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15);
} // waits 15ms for the servo to reach the position
else if (command== ‘L’)
{
pos=pos1+45;
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
}
else{
timer0 = millis(); //Get the current time (millis since execution started).
//Check if it has been 500ms since we received last command.
if((timer0 - timer1)>500){
//More tan 500ms have passed since last command received, car is out of range.
//Therefore stop the car and turn lights off.

yellowCar.stopped_4W();
}
}
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}

Why have you got a switch/case for the control of the H-bridge, then a separate if/else chain for the control of the servo?

Please use code tags when posting code.