My 4WD Programmable Car is not responding to inputs without USB

Hello, I am new to programming with arduino and I am working on a project with a 4WD programmable car with a L298N motor drive along with a Arduino Uno.

Right now I uploaded the code and wired it up.

Problem: It won’t respond to any of my inputs via bluetooth on my phone, unless connected to USB from my PC. Even when connected by USB when right motors are the only ones responding to my inputs.

below is the code and pictures of how the RC car is set up.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(A4, A5); // RX, TX

//L298 Connection   
  const int motorA1  = 6;  
  const int motorA2  = 7;  
  const int motorB1  = 10; 
  const int motorB2  = 9;  
//Leds connected to Arduino UNO Pin A0, A1
  const int light_FL  = A0;
  const int light_FR  = A1;
  const int light_RL  = A2;
  const int light_RR  = A3;
//Buzzer / Speaker to Arduino UNO Pin 3
  const int buzzer = 11 ;   
//Useful Variables
  int state;
  int vSpeed=255;     // Default speed, from 0 to 255

void setup() {
    // Set pins as outputs:
    pinMode(motorA1, OUTPUT);
    pinMode(motorA2, OUTPUT);
    pinMode(motorB1, OUTPUT);
    pinMode(motorB2, OUTPUT);
    pinMode(light_FL, OUTPUT); 
    pinMode(light_FR, OUTPUT); 
    pinMode(light_RL, OUTPUT); 
    pinMode(light_RR, OUTPUT); 
    pinMode(buzzer, OUTPUT);
    digitalWrite(buzzer, HIGH);
//    pinMode(BTState, INPUT);    
    // Initialize serial communication at 9600 bits per second:
    Serial.begin(115200);
    mySerial.begin(9600);
}
 
void loop() {

  //Save income data to variable 'state'
    if(mySerial.available() > 0){     
      state = mySerial.read();
      Serial.println(state);   
    }
  
  //Change speed if state is equal from 0 to 4. Values must be from 0 to 255 (PWM)
    if (state == '0'){
      vSpeed=0;}
    else if (state == '1'){
      vSpeed=100;}
    else if (state == '2'){
      vSpeed=127;}
    else if (state == '3'){
      vSpeed=150;}
    else if (state == '4'){
      vSpeed=180;}
      else if (state == '5'){
      vSpeed=200;}
      else if (state == '6'){
      vSpeed=210;}
      else if (state == '7'){
      vSpeed=220;}
      else if (state == '8'){
      vSpeed=230;}
      else if (state == '9'){
      vSpeed=240;}
      else if (state == 'q'){
      vSpeed=255;}
 	  
  /***********************Forward****************************/
  //If state is equal with letter 'F', car will go forward!
    if (state == 'F') {
    	analogWrite(motorA1, vSpeed); analogWrite(motorA2, 0);
        analogWrite(motorB1, vSpeed);      analogWrite(motorB2, 0); 
    }
  /**********************Forward Left************************/
  //If state is equal with letter 'G', car will go forward left
    else if (state == 'G') {
    	analogWrite(motorA1, 0); analogWrite(motorA2, 0);  
        analogWrite(motorB1, vSpeed);    analogWrite(motorB2, 0); 
    }
  /**********************Forward Right************************/
  //If state is equal with letter 'I', car will go forward right
    else if (state == 'I') {
      	analogWrite(motorA1, vSpeed); analogWrite(motorA2, 0); 
        analogWrite(motorB1, 0);      analogWrite(motorB2, 0); 
    }
  /***********************Backward****************************/
  //If state is equal with letter 'B', car will go backward
    else if (state == 'B') {
    	analogWrite(motorA1, 0);   analogWrite(motorA2, vSpeed); 
        analogWrite(motorB1, 0);   analogWrite(motorB2, vSpeed); 
    }
  /**********************Backward Left************************/
  //If state is equal with letter 'H', car will go backward left
    else if (state == 'H') {
    	analogWrite(motorA1, 0);   analogWrite(motorA2, 0); 
        analogWrite(motorB1, 0); analogWrite(motorB2, vSpeed); 
    }
  /**********************Backward Right************************/
  //If state is equal with letter 'J', car will go backward right
    else if (state == 'J') {
    	analogWrite(motorA1, 0);   analogWrite(motorA2, vSpeed); 
        analogWrite(motorB1, 0);   analogWrite(motorB2, 0); 
    }
  /***************************Left*****************************/
  //If state is equal with letter 'L', wheels will turn left
    else if (state == 'L') {
    	analogWrite(motorA1, 0);   analogWrite(motorA2, vSpeed); 
        analogWrite(motorB1, vSpeed); analogWrite(motorB2, 0); 
    }
  /***************************Right*****************************/
  //If state is equal with letter 'R', wheels will turn right
    else if (state == 'R') {
    	analogWrite(motorA1, vSpeed);   analogWrite(motorA2, 0); 
        analogWrite(motorB1, 0);   analogWrite(motorB2, vSpeed); 		
    }
  /************************Lights*****************************/
  //If state is equal with letter 'W', turn leds on or of off
    else if (state == 'W') {
         digitalWrite(light_FL, HIGH); 
         digitalWrite(light_FR, HIGH); 
      }
    else if (state == 'w') {
         digitalWrite(light_FL, LOW); 
         digitalWrite(light_FR, LOW);
      }
    else if (state == 'U') {
         digitalWrite(light_RL, HIGH); 
         digitalWrite(light_RR, HIGH); 
      }
    else if (state == 'u') {
         digitalWrite(light_RL, LOW); 
         digitalWrite(light_RR, LOW);
      }
  /**********************Horn sound***************************/
  //If state is equal with letter 'V', play (or stop) horn sound
    else if (state == 'V'){
      digitalWrite(buzzer, LOW);
      }
    else if (state == 'v'){
      digitalWrite(buzzer, HIGH);
      }
  /************************Stop*****************************/
  //If state is equal with letter 'S', stop the car
    else if (state == 'S'){
        analogWrite(motorA1, 0);  analogWrite(motorA2, 0); 
        analogWrite(motorB1, 0);  analogWrite(motorB2, 0);
    }
    
}

Bluetooth_Car_Test.ino (5.26 KB)

Hi Luigimacs, welcome to the forum.
Read the sticky post at the top of this forum named How to use this forum - please read.
It will help you with the proper way to post code.

If you are having problems with your code, break it down into the smallest testable pieces and troubleshoot from there.

Motors not working in your big sketch? Write a small sketch that does nothing but make the right motors go forward for a bit. Stop for a bit, go backwards for a bit. stop for a bit.
Then repeat with the left motors.

This will let you confirm that your wiring for the motors is done properly and that your code for properly controlling the motors is correct.

Do this with no bluetooth code at all.

Then write a sketch that had no motor code it in at all. It should just receive bluetooth commands and display them on the serial monitor. When you can send commands from your phone and see them on the serial monitor, you will know that you have the communication side working correctly.

THEN combine the 2 into the overall project.

I am unable to see where your actually sending power to your Arduino from the batteries.

@Slumpert, here are more pictures, I tried to show how the power source is connected.

From what I see in your pictures, to get power to the Arduino you are going from the 4.8v battery pack to a switch, to the H-bridge controller, back to the battery pack.

Then from the H-bridge to the “output” pins for vcc and ground on the sensor shield.

Slumpert:
From what I see in your pictures, to get power to the Arduino you are going from the 4.8v battery pack to a switch, to the H-bridge controller, back to the battery pack.

Then from the H-bridge to the “output” pins for vcc and ground on the sensor shield.

Ok, but it is actually a 6v battey pack, is there any suggestions as to how I can fix my problem?

Have you done what was suggested back in #1? I.e. write a simple program with no bluetooth or other complications that just runs the motors forward/back/left and right for a couple of seconds each. When that part is working you can move on to testing the bluetooth.

My guess is that your batteries are too weak so you simply don't have enough power to run the motors and still provide power to everything else (that's why it more or less works when you provide extra power via USB). But it's only a guess.

Steve