Problem with Arduino Sensor Car

Well, I tried making said changes that you told me but the robot just went entirely mad, it would have similar problems to the ones I had at the start so I tried to remake the whole code entirely, and tested it out one step at a time to see if I could find the source of my problems.

I just ended up changing a bit the app by replacing the letters it was supposed to send from the app (F, R, L, B, S....) to numbers. The result? The app wouldn't stop malfunctioning and freezing on its own. I went back to the initial app and the initial code to undo everything but now the robot doesn't even respond correctly, it does just the same as it did with the newer app.

This is the code I'm actually working on, I don't understand why this is happening, maybe I've messed up big time somewhere in there but I cannot see it.

int state=0;
long duration;
int distance;
int Fobstacle;

const int trigPin1 = 10;
const int echoPin1 = 7;
const int LeftMotor= 12;
const int RightMotor= 13;
const int LeftBrake= 9;
const int RightBrake= 8;
const int LeftGo= 3;
const int RightGo= 11;

void setup() {
  //Setup Channels
  pinMode(LeftMotor, OUTPUT); //Motor Channel A
  pinMode(LeftBrake, OUTPUT); //Brake Channel A 
  pinMode(RightMotor, OUTPUT); //Motor Channel B
  pinMode(RightBrake, OUTPUT); //Brake Channel B
  pinMode(trigPin1, OUTPUT); 
  pinMode(echoPin1, INPUT); 

  digitalWrite(LeftMotor, HIGH);
  digitalWrite(RightMotor, LOW); // Connection is inverted.
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

void loop() {




  checkFrontObstacle();
  checkDirection();
  
  moveForward();
  moveBackwards();
  moveRight();
  moveLeft();
  nowStop();
  turnRight();
  turnLeft();


  
}


void moveForward() {
  if (state == '1' && Fobstacle == 'N') {
     delayMicroseconds(100);
     digitalWrite(LeftMotor, HIGH);
     digitalWrite(LeftBrake, LOW); //Brake is off
     digitalWrite(RightBrake, LOW); // Brake is off
     digitalWrite(RightMotor, LOW);
         
     analogWrite(LeftGo, 255);   //Spins the motor on Channel A at full speed
     analogWrite(RightGo, 255);   //Spins the motor on Channel B at full speed
     }
  }
   
void moveBackwards() {
  if (state == '2' && Fobstacle == 'N'){
     delayMicroseconds(100); 
     digitalWrite(LeftMotor, LOW);
     digitalWrite(LeftBrake, LOW); 
     digitalWrite(RightBrake, LOW);
     digitalWrite(RightMotor, HIGH);

     analogWrite(LeftGo, 255);   //Spins the motor on Channel A at full speed
     analogWrite(RightGo, 255);   //Spins the motor on Channel B at full speed 
     }

  }

void moveLeft() {
  if (state == '3' && Fobstacle == 'N'){
      delayMicroseconds(100);
      digitalWrite(LeftMotor, HIGH); //A
      digitalWrite(LeftBrake, LOW); //A
      digitalWrite(RightBrake, LOW);//B
      digitalWrite(RightMotor, LOW);//B
 
      analogWrite(LeftGo, 90);   //Spins the motor on Channel A at low speed
      analogWrite(RightGo, 255);   //Spins the motor on Channel B at full speed  
     }
  }
   
void moveRight() {
  if (state == '4' && Fobstacle == 'N'){
      delayMicroseconds(100);
      digitalWrite(LeftMotor, HIGH);
      digitalWrite(LeftBrake, LOW); //A
      digitalWrite(RightBrake, LOW);//B
      digitalWrite(RightMotor, LOW);//B
        
      analogWrite(RightGo, 90);   //Spins the motor on Channel B at full speed  
      analogWrite(LeftGo, 255);   //Spins the motor on Channel A at low speed
      }
   }
   
void turnRight() {
   if(state == '5' && Fobstacle == 'N'){
      delayMicroseconds(100);
      digitalWrite(LeftMotor, HIGH); //A
      digitalWrite(LeftBrake, LOW); //A
      digitalWrite(RightBrake, LOW);//B
      digitalWrite(RightMotor, HIGH);//B
 
      analogWrite(LeftGo, 255);   //Spins the motor on Channel A at full speed
      analogWrite(RightGo, 255);   //Spins the motor on Channel B at full speed 
     }
   }

   void turnLeft() {
   if(state == '6' && Fobstacle == 'N'){
      delayMicroseconds(100);
      digitalWrite(LeftMotor, LOW); //A
      digitalWrite(LeftBrake, LOW); //A
      digitalWrite(RightBrake, LOW);//B
      digitalWrite(RightMotor, LOW);//B
 
      analogWrite(LeftGo, 255);   //Spins the motor on Channel A at full speed
      analogWrite(RightGo, 255);   //Spins the motor on Channel B at full speed  
     }
   }



   
void nowStop() {
   if(state == '9'){
     delayMicroseconds(100);
     digitalWrite(LeftBrake, HIGH); 
     digitalWrite(RightBrake, HIGH);
     }

   }

   

   
void checkDirection(){
  if(Serial.available() >= 0)
    {     
      state = Serial.read();   
    }   
   }
   



void checkFrontObstacle() {
  
     // Clears the trigPin1
  digitalWrite(trigPin1, LOW);
  delayMicroseconds(200);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin1, HIGH);
  delayMicroseconds(100);
  digitalWrite(trigPin1, LOW);
  // Reads the echoPin1, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin1, HIGH);
  // Calculating the distance
  distance= duration*0.034/2;
    //if some data is sent, reads it and saves in distance

Serial.println(distance);

   if (distance >= 40) {
     Fobstacle = 'N'; // N for none
    }
   if (distance < 40 && distance >= 20 ) {
     Fobstacle = 'C';  // C for close
    }
   if (distance < 20 ) {
     Fobstacle = 'A'; // A for approaching
    }

   }

Also, I've considered the possibility that the problem comes from the app, which would make a lot of sense. If so, does anybody know anywhere where I can build an app like MIT App Inventor? If not I will have to get into code as well.

By the way, the motors are inverted because when I welded them to the cables I didn't notice my mistake until the very end.

Thanks