Bluetooth Controlled Car Problems

Hello Community,
you can Answer in English and German. Thanks

i want to build a small RC Car for a school project.
It's controlled with an HC-05 and the moters with an L298N Motor Board.

Here is my circuit:

The Problem is: When i Power everything with 5V its working, you can connect your phone with the bluetooth device, you can steer and go forwards and backwards and you can turn the lights on and off, but the voltage drops when i want to drive and steer at the same time. So there should not be a Problem with the code.

The L298N is specified to work with 7-12V , so im using a bigger battery with 7.2V or 11.1V. When the new Powersource is connected, everything turns on and you can connect your phone with the bluetooth device, but now nothing works, you can press any button on your mobile phone but nothing happened.

If anyone has an idea why it might be, write to me. Thanks!

Code:

 #include <Servo.h>
Servo servo1;

#define SERVOMIN  30
#define SERVOMID  90
#define SERVOMAX  150
#define TurnLeft servo1.write(SERVOMIN)
#define TurnMid servo1.write(SERVOMID)
#define TurnRight servo1.write(SERVOMAX)

 int motorA1  = 5;
   int motorA2  = 6;
   int motorB1  = 9;
   int motorB2  = 10;
   int buzzer  = 4;   
   int light1  = 12;
   int light2  = 13;
   int light3  = 11;
   int state;
   int vSpeed;
   char ch;
   int pos = 0;

void setup() {
servo1.attach(3);
    pinMode(motorA1, OUTPUT);
    pinMode(motorA2, OUTPUT);
    pinMode(motorB1, OUTPUT);
    pinMode(motorB2, OUTPUT);
    pinMode(light1, OUTPUT); 
    pinMode(light2, OUTPUT);
    pinMode(light3, OUTPUT);     
    // Initialize serial communication at 9600 bits per second:
    Serial.begin(9600);
}

void loop() {

  //Save income data to variable 'state'
    if(Serial.available() > 0){     
      state = Serial.read();
      ch = state;
     // Serial.print("state:");Serial.print(state);
     // Serial.print(" ch:");Serial.println(ch);
    }


    if(state == '0')
     vSpeed = 0;
    if(state == '1')
     vSpeed = 120;
    if(state == '2')
     vSpeed = 140;
    if(state == '3')
     vSpeed = 160;
    if(state == '4')
     vSpeed = 180;
    if(state == '5')
     vSpeed = 200;
    if(state == '6')
     vSpeed = 210;
    if(state == '7')
     vSpeed = 220;
    if(state == '8')
     vSpeed = 230;
    if(state == '9')
     vSpeed = 240;
    if(state == 'q')
     vSpeed = 255;
     

  /***********************Forward****************************/
  //If state is equal with number 'F', car will go forward!
    if (state == 'F') {
      analogWrite(motorA1, vSpeed); analogWrite(motorA2, 0);
      TurnMid;

    }  
  
  /***********************Backward****************************/
  //If state is equal with number 'B', car will go backward
    else if (state == 'B') {
      analogWrite(motorA1, 0); analogWrite(motorA2, vSpeed); 
      TurnMid;

    }

  /***************************Right*****************************/
  //If state is equal with number 'R', wheels will turn right
    else if (state == 'R') {
      analogWrite(motorA1, 0); analogWrite(motorA2, 0); 
      TurnRight;
     

              

    }
    
  /***************************Left*****************************/
  //If state is equal with number 'L', wheels will turn left
    else if (state == 'L') {
      analogWrite(motorA1, 0);   analogWrite(motorA2, 0); 
      TurnLeft;
       

    }

  /**********************Forward Right************************/
  //If state is equal with number 'I', car will go forward right
    else if (state == 'I') {
      analogWrite(motorA1, vSpeed); analogWrite(motorA2, 0); 
      TurnRight;
     

    }
    
  /**********************Forward Left************************/
  //If state is equal with number 'G', car will go forward left
    else if (state == 'G') {
      analogWrite(motorA1, vSpeed); analogWrite(motorA2, 0);  
      TurnLeft;
       

    }
    
  /**********************Backward Right************************/
  //If state is equal with number 'J', car will go backward right
    else if (state == 'J') {
      analogWrite(motorA1, 0); analogWrite(motorA2, vSpeed); 
      TurnRight;

    }
    
  /**********************Backward Left************************/
  //If state is equal with number 'H', car will go backward left
    else if (state == 'H') {
      analogWrite(motorA1, 0);   analogWrite(motorA2, vSpeed); 
      TurnLeft;

    }
    
  /***************************Stop*****************************/
  //If state is equal with number 'S', stop the car
    else if (state == 'S') {
      analogWrite(motorA1, 0); analogWrite(motorA2, 0);  
      analogWrite(motorB1, 0); analogWrite(motorB2, 0);
    }
    
  /***************************light1*****************************/
  //If state is equal with letter 'W', light1 turn on
    if (state == 'W') {
      digitalWrite(light1, HIGH); 
    }
    if (state == 'w') {
      digitalWrite(light1, LOW); 
    }
    
  /***************************light2*****************************/
  //If state is equal with letter 'U', light2 turn on
    if (state == 'U') {
      digitalWrite(light2, HIGH); 
    }
    if (state == 'u') {
      digitalWrite(light2, LOW); 
    }

  /***************************light3*****************************/
  //If state is equal with letter 'X', light3 turn on
    if (state == 'X') {
      digitalWrite(light3, HIGH); 
    }
    if (state == 'x') {
      digitalWrite(light3, LOW); 
    }
    
  /***************************buzzer*****************************/
  //If state is equal with letter 'N', buzzer turn on
    if (state == 'V') {
      tone(buzzer, 500); 
    }
    if (state == 'v') {
      noTone(buzzer); 
    }

}>`Vorformatierter Text`

Your post was MOVED to its current location as it is more suitable.

Please follow the advice given in the link below when posting code. Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

ok i changed my post

Hi, @daxe
Welcome to the forum.

What is your servo?
Have you got a DMM?
What does your 5V pin measure in volts now that you have the bigger battery fitted?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Hey @TomGeorge

Its a Carson Speedy Servo 24 ,it to the model car i use.

With 7.2V battery i measure 4.8V and with 11.1V i measure 5V.

When you are using the 7.2 or 12Vbattery for the motors what exactly is powering the servo and the Arduino?

It is a bad idea to power servos, particularly high power ones, from the Arduino 5V pin. You may get away with it when the Arduino is powered from USB but if you try to power it via the barrel plug or Vin then the onboard regulator cannot supply enough current.

Steve

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.