Arduino Car Trouble

I am making a car that will be controlled by a wired controller with 4 buttons that control each wheel individually. (The back wheels rotate backwards) I want to add a servo that will tilt from 30 degrees to 150 degrees. I will mount a wireless camera on it. Could somebody please revise my code with the servo, please? :smiley:

int pos = 0;

const int motor_A_1 = 1;
const int motor_A_2 = 2;
const int motor_B_1 = 3;
const int motor_B_2 = 4;
const int FRONT_LEFT = 5;
const int FRONT_RIGHT = 6;
const int BACK_LEFT = 7;
const int BACK_RIGHT = 8;
const int Head_light = 13;

void setup() {
  
  #include <Servo.h>
  myservo.attach(9);
  pinMode(motor_A_1, OUTPUT);
  pinMode(motor_A_2, OUTPUT);
  pinMode(motor_B_1, OUTPUT);
  pinMode(motor_B_2, OUTPUT);
  pinMode(FRONT_LEFT, INPUT);
  pinMode(FRONT_RIGHT, INPUT);
  pinMode(BACK_LEFT, INPUT);
  pinMode(BACK_RIGHT, INPUT);
  pinMode(Head_light, OUTPUT);

}

void loop() {
  
  
  for(pos = 20; pos < 160; pos += 1)   
    myservo.write(pos);               
    delay(15); 
  for(pos = 160; pos>=20; pos-=1)     
    myservo.write(pos);               
    delay(15);
  
  digitalWrite(Head_light, HIGH);
  
  while (FRONT_LEFT == HIGH);
     digitalWrite(motor_A_1, HIGH);
  if (FRONT_LEFT == LOW);
     digitalWrite(motor_A_1, LOW);
     
     
  while (FRONT_RIGHT == HIGH);
     digitalWrite(motor_A_2, HIGH);
  if (FRONT_RIGHT == LOW);
     digitalWrite(motor_A_2, LOW);
     
     
  while (BACK_LEFT == HIGH);
     digitalWrite(motor_B_1, HIGH);
  if (BACK_LEFT == LOW);
     digitalWrite(motor_B_1, LOW);
     
     
  while (BACK_RIGHT == HIGH);
     digitalWrite(motor_B_2, HIGH);
  if (BACK_RIGHT == LOW);
     digitalWrite(motor_B_2, LOW);
     
  }

You have more problems than the servo. Forget about it for now.

  digitalWrite(Head_light, HIGH);

You never turn the head light off, do this should be done in setup().

  while (FRONT_LEFT == HIGH);

The ; on the end forms the body of the while loop. In other words, do nothing. FRONT_LEFT is a pin number. The number of the pin is completely independent of the state of the pin. FRONT_LEFT is not defined the same as HIGH, so this while loop will never actually execute (which is a good thing).

  if (FRONT_LEFT == LOW);
     digitalWrite(motor_A_1, LOW);

Same problem. FRONT_LEFT is a pin number, not a state, so the motor pin will never be set.

The rest of the code has the same problems.

OK, now, about that servo. Exactly what is it you want it to do? Right now, you are issuing move commands faster than the servo can physically move. Then, you wait 15 microseconds, and issue a bunch more move commands faster then the servo can physically execute them, and then wait another 15 microseconds.

Could you fix the code to give me an idea? This is my first real project.

I am making a car that will be controlled by a wired controller with 4 buttons that control each wheel individually.

You have the controller. We don't. You need to read whether the buttons have been pressed, using digitalRead(). It is the output of the digitalRead() function, the switch state, that the decisions should be based on, not the pin numbers.

  while (FRONT_LEFT == HIGH);
     digitalWrite(motor_A_1, HIGH);
  if (FRONT_LEFT == LOW);
     digitalWrite(motor_A_1, LOW);

becomes

  int frontLeftState = digitalRead(FRONT_LEFT);
  if (frontLeftState == HIGH)
     digitalWrite(motor_A_1, HIGH);
  else
     digitalWrite(motor_A_1, LOW);

Similar changes to the other sections are required.

You need to provide more details about when/how the servo should be moved.