having problems with my arduino bluetooth car project(with L298n Motor Driver)
The code seems to have a few missing lines for logic. Here's a corrected version from my understanding.
#include &lt;NewPing.h&gt;

#include&lt;Servo.h&gt;

#define TRIGGER_PIN A1
#define ECHO_PIN A0
#define MAX_DISTANCE 300
#define IR A2

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

Servo myservo;

String voice;

void setup() {
  Serial.begin(9600);
  myservo.attach(8);
  myservo.write(90);
  pinMode(IR, INPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);

}

void loop() {
  int distance = sonar.ping_cm();

  if (Serial.available() &gt; 0) {
    voice = &quot;&quot;;
    delay(2);
    voice = Serial.readString();
    delay(2);
    Serial.println(voice);

    if (voice == &quot;turn left&quot;) {
      left();
    } else if (voice == &quot;left&quot;) {
      left();
    } else if (voice == &quot;turn right&quot;) {
      right();
    } else if (voice == &quot;right&quot;) {
      right();
    } else if(voice == &quot;move forward&quot;){
      forward();
    } else if(voice == &quot;move backward&quot;){
      backward();
    }
    
  }

}

void forward() {
  int distance = sonar.ping_cm();

  if (distance &lt; 10) {
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
    digitalWrite(9, LOW);
    voice = &quot;&quot;;
  } else {
    digitalWrite(12, HIGH);
    digitalWrite(10, HIGH);
  }
}
void backward() {
  int IR_Sensor = digitalRead(IR);
  if (IR_Sensor == 0) {
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
    digitalWrite(9, LOW);
    voice = &quot;&quot;;
  } else {
    digitalWrite(11, HIGH);
    digitalWrite(9, HIGH);
  }
}
void left() {
  myservo.write(180);
  delay(500);
  myservo.write(90);
  delay(500);
  int distance = sonar.ping_cm();

  if (distance &lt; 10) {
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
    digitalWrite(9, LOW);
    voice = &quot;&quot;;
  } else {
    digitalWrite(12, HIGH);
    delay(700);
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
    digitalWrite(9, LOW);

  }
}

void right() {
  myservo.write(0);
  delay(500);
  myservo.write(90);
  delay(500); {
    int distance = sonar.ping_cm();

    if (distance &lt; 10) {
      digitalWrite(12, LOW);
      digitalWrite(11, LOW);
      digitalWrite(10, LOW);
      digitalWrite(9, LOW);
      voice = &quot;&quot;;
    } else {
      digitalWrite(10, HIGH);
    }
    delay(700);
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
    digitalWrite(9, LOW);
  }
}

void Stop() {
  digitalWrite(12, LOW);
  digitalWrite(11, LOW);
  digitalWrite(10, LOW);
  digitalWrite(9, LOW);
}