RC Bluetooth car

Hello i want to modify my old rc car with the arduino uno board and i want your help on the code.

my code is

int const PWMA = 6; 
int const PWMB = 5; 
int const dirA = 7; 
int const dirB = 4; 


void setup() {
  pinMode(PWMA, OUTPUT);
  pinMode(PWMB, OUTPUT);
  pinMode(dirA, OUTPUT);  
  pinMode(dirB, OUTPUT);
  
  //initial set up straight forward, no speed
  digitalWrite(dirA, HIGH);
  digitalWrite(dirB, HIGH);
  analogWrite(PWMA, 0);
  analogWrite(PWMB, 0);
  
  Serial.begin(9600); 
}

void loop() {
  
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    int incomingByte = Serial.read();
    
    // action depending on the instruction
    // as well as sending a confirmation back to the app
    switch (incomingByte) {
      case 'F':
        moveForward(255, true);
        Serial.println("Going forward");
        break;
      case 'R':
        turn(255, true);
        Serial.println("Turning right");
        break;
      case 'L':
        turn(255, false);
        Serial.println("Turning left");
        break;
      case 'B':
        moveForward(255, false);
        Serial.println("Going backwards");
        break;
      case 'S':
        moveForward(0, true);
        Serial.println("Stopping");
        break;
      default: 
        // if nothing matches, do nothing
        break;
    }
  }
}

void moveForward(int speedBot, boolean forward){
//boolean forward controls motor direction
  if (forward){
      digitalWrite(dirA, HIGH);
      digitalWrite(dirB, HIGH);
    }
    else{
      digitalWrite(dirA, LOW);
      digitalWrite(dirB, LOW);
    }
    analogWrite(PWMA, speedBot);
    analogWrite(PWMB, speedBot);

}

void turn(int speedBot, boolean right){
  //boolean right controls motor direction
    if (right){
      digitalWrite(dirA, HIGH);
      digitalWrite(dirB, LOW);
    }
    else{
      digitalWrite(dirA, LOW);
      digitalWrite(dirB, HIGH);
    }
    analogWrite(PWMA, speedBot);
    analogWrite(PWMB, speedBot);
}

My rc car is similat to this https://www.google.gr/search?q=rc+car+arduino&biw=1680&bih=949&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjbo-ypo_LJAhVJExoKHY1EAVcQ_AUIBigB#imgrc=Hyt7mC-mC1NBRM%3A

I upload the code but the steering motors doesn't work only go forward and backward.How to modify the code in order to work with steering motors?

My motor controller is this 2x1A DC Motor Shield for Arduino - DFRobot

Thanks for your time.

Do the appropriate messages appear when you try to turn left or right?

PaulS:
Do the appropriate messages appear when you try to turn left or right?

How can i do that?

jack1992:
How can i do that?

Do what? The code you posted does Serial.print()s now. Where does that data go?

PaulS:
Do what? The code you posted does Serial.print()s now. Where does that data go?

My car controlled by tablet via bluetooth.I am new in this.

My car controlled by tablet via bluetooth.I am new in this.

So, you can send data from the tablet, but not get data back? That sounds like a tablet problem.

When you can see what the Arduino is doing, you can make progress. Until then, it's hopeless.

Get things working with the IDE's terminal window before worrying about trying to use BT.

Put the car up on blocks and connect the Arduino to the computer. Type the various commands into the terminal window and observe the messages you get back from the program.

DuaneDegn:
Get things working with the IDE's terminal window before worrying about trying to use BT.

Put the car up on blocks and connect the Arduino to the computer. Type the various commands into the terminal window and observe the messages you get back from the program.

So much THIS. Same thing I wanted to post.

OP would also do well to try hooking up the steering actuator motor and make sure that it actually works. OP didn't say whether they bought the car used, or new. If used, there's a small possibility that the steering motor and/or actuator mechanism is broken and would need to be repaired.

Something else - I think OP's code is designed for a differential (tank-like) steer platform, and not standard (Ackermann) steering. This should be a more workable code (note - I have not tested this to compile or work!):

int const pwm_drive = 6; 
int const dir_drive = 7; 

int const pwm_steer = 5; 
int const dir_steer = 4; 


void setup() {
  pinMode(pwm_drive, OUTPUT);
  pinMode(pwm_steer, OUTPUT);
  pinMode(dir_drive, OUTPUT);  
  pinMode(dir_steer, OUTPUT);
  
  turnNone();
  moveNone();
  
  Serial.begin(9600); 
}

void loop() {
  
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    int incomingByte = Serial.read();
    
    // action depending on the instruction
    // as well as sending a confirmation back to the app
    switch (incomingByte) {
      case 'F':
        moveForward(255);

        Serial.println("Going forward");

        break;

      case 'R':
        turnRight();

        Serial.println("Turning right");

        break;
      case 'L':
        turnLeft();

        Serial.println("Turning left");

        break;

      case 'B':
        moveBackward(255);

        Serial.println("Going backwards");

        break;

      case 'N':
        turnNone();

        Serial.println("Turning centered");

        break;

      case 'S':
        moveNone();

        Serial.println("Stopping");

        break;

      default: 
        // if nothing matches, do nothing
    }
  }
}

void moveForward(int speedBot) {
    // turn the driving motor on to go forwards at set speed
    digitalWrite(dir_drive, HIGH);

    analogWrite(pwm_drive, speedBot);
}

void moveBackward(int speedBot) {
    // turn the driving motor on to go backwards at set speed
    digitalWrite(dir_drive, LOW);

    analogWrite(pwm_drive, speedBot);
}

void moveNone() {
    // turn the driving motor off
    digitalWrite(dir_drive, LOW);

    analogWrite(pwm_drive, 0);
}

void turnRight() {
    // slam it to the right
    digitalWrite(dir_steer, HIGH);

    analogWrite(pwm_steer, 255);
}

void turnLeft() {
    // slam it to the left
    digitalWrite(dir_steer, LOW);

    analogWrite(pwm_steer, 255);
}

void turnNone() {
    // turn steering motor off - spring centering takes effect
    digitalWrite(dir_steer, LOW);

    analogWrite(pwm_steer, 0);
}

cr0sh:
So much THIS. Same thing I wanted to post.

OP would also do well to try hooking up the steering actuator motor and make sure that it actually works. OP didn't say whether they bought the car used, or new. If used, there's a small possibility that the steering motor and/or actuator mechanism is broken and would need to be repaired.

Something else - I think OP's code is designed for a differential (tank-like) steer platform, and not standard (Ackermann) steering. This should be a more workable code (note - I have not tested this to compile or work!):

int const pwm_drive = 6; 

int const dir_drive = 7;

int const pwm_steer = 5;
int const dir_steer = 4;

void setup() {
  pinMode(pwm_drive, OUTPUT);
  pinMode(pwm_steer, OUTPUT);
  pinMode(dir_drive, OUTPUT); 
  pinMode(dir_steer, OUTPUT);
 
  turnNone();
  moveNone();
 
  Serial.begin(9600);
}

void loop() {
 
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    int incomingByte = Serial.read();
   
    // action depending on the instruction
    // as well as sending a confirmation back to the app
    switch (incomingByte) {
      case 'F':
        moveForward(255);

Serial.println("Going forward");

break;

case 'R':
        turnRight();

Serial.println("Turning right");

break;
      case 'L':
        turnLeft();

Serial.println("Turning left");

break;

case 'B':
        moveBackward(255);

Serial.println("Going backwards");

break;

case 'N':
        turnNone();

Serial.println("Turning centered");

break;

case 'S':
        moveNone();

Serial.println("Stopping");

break;

default:
        // if nothing matches, do nothing
    }
  }
}

void moveForward(int speedBot) {
    // turn the driving motor on to go forwards at set speed
    digitalWrite(dir_drive, HIGH);

analogWrite(pwm_drive, speedBot);
}

void moveBackward(int speedBot) {
    // turn the driving motor on to go backwards at set speed
    digitalWrite(dir_drive, LOW);

analogWrite(pwm_drive, speedBot);
}

void moveNone() {
    // turn the driving motor off
    digitalWrite(dir_drive, LOW);

analogWrite(pwm_drive, 0);
}

void turnRight() {
    // slam it to the right
    digitalWrite(dir_steer, HIGH);

analogWrite(pwm_steer, 255);
}

void turnLeft() {
    // slam it to the left
    digitalWrite(dir_steer, LOW);

analogWrite(pwm_steer, 255);
}

void turnNone() {
    // turn steering motor off - spring centering takes effect
    digitalWrite(dir_steer, LOW);

analogWrite(pwm_steer, 0);
}

Hello sir i tried your code and it works but when i go forward and push the forward and right it doesn't turn. How to solve this?Thanks in advance

jack1992:
Hello sir i tried your code and it works but when i go forward and push the forward and right it doesn't turn. How to solve this?Thanks in advance

Here's a simple sketch to test the steering motor.

int const pwm_steer = 5; 
int const dir_steer = 4; 


void setup() {
  pinMode(pwm_steer, OUTPUT);
  pinMode(dir_steer, OUTPUT);
  
  turnNone();
   
  Serial.begin(9600); 
}

void loop() {

  Serial.println("Turning right for one second.");
  turnRight();
  delay(1000);
  Serial.println("Allow steering to center for two seconds.");
  turnNone();
  delay(2000);
  Serial.println("Turning left for one second.");
  turnLeft();      
  delay(1000);
  Serial.println("Allow steering to center for two seconds.");
  turnNone();
  delay(2000);
  Serial.println("Repeating loop.");   
}

void turnRight() {
    // slam it to the right
    digitalWrite(dir_steer, HIGH);

    analogWrite(pwm_steer, 255);
}

void turnLeft() {
    // slam it to the left
    digitalWrite(dir_steer, LOW);

    analogWrite(pwm_steer, 255);
}

void turnNone() {
    // turn steering motor off - spring centering takes effect
    digitalWrite(dir_steer, LOW);

    analogWrite(pwm_steer, 0);
}

Have the car up on a block and watch the output to the serial terminal. Does the steering motor move when the steering commands are given?

If the program does behave as expected. Take a clear photo of your car which shows how the steering motor connects with the motor controller.

jack1992:
Hello to everyone.I have modified an RC car in order to work with Arduino UNO R3 and bluetooth(HC-05).It works very well but i have a problem with the power supply.I have 6 AA Rechargeable Batteries 2400mAh connected directly to Arduino power jack.My problem is that the car last only a few minutes.There is a way to last longer?

Apparently you got the issue with the steering motor figured out?

It's possible the code you're using isn't as efficient as it could be. It would probably be a good idea to post the code you're using.

You say the battery pack is connected directly to the Arduino. How is the motor shield getting power?

I think you'll likely need a better battery pack but there may be was to improve the performance of your current setup.