Go Down

Topic: RC CAR  (Read 907 times) previous topic - next topic

agbaiatu80

Hi all. I have a bit of a problem and I need some help please. First, I have to say that neither me nor my son have any knowledge in this type of projects (nothing new for you, I'm sure). Long story short: we took the chassis , gearbox and 12V DC motors connected them to Arduino MS Rev3, uploaded the code and controlling the robot via phone bluetooth. The problem is that the car goes only forward and backward, no turning right and when asked to go left it's just going straight. Also, when asked to go straight, the car doesn't stop until I push the back button. Other than that, the car goes just great :D. Could you please let me know what am I doing wrong? Thank you for your help :D

Materials used:
 2 dc  motors 12V
Bluetooth HC 05 master
Arduino UNO
Arduino Motor Shield Rev3.
App for controling the robot https://play.google.com/store/apps/details?id=braulio.calle.bluetoothRCcontroller&hl=en_GB

This is the code :

#include <MotorShield.h>

//*** 1- Documentation
//This program is used to control a robot car using an app that communicates with Arduino trough a bluetooth module HC 05
// Known issues: The car does not turn right,left command makes the car go forward, when told to go left it's just goind straight, when straight does not stop



//creates two objects to control the terminal 3 and 4 of motor shield
MS_DCMotor motor1(3);
MS_DCMotor motor2(4);

char command;

void setup()
{       
  Serial.begin(9600);
}

void loop(){
  if(Serial.available() > 0){
    command = Serial.read();
    Stop(); //initialize with motors stoped
    switch(command){
    case 'F': 
      forward();
      break;
    case 'B': 
       back();
      break;
    case 'L': 
      left();
      break;
    case 'R':
      right();
      break;
    }
  }
}

void forward()
{
  motor1.setSpeed(250); //Define maximum velocity
  motor1.run(FORWARD); //rotate the motor clockwise
  motor2.setSpeed(250); //Define maximum velocity
  motor2.run(FORWARD); //rotate the motor clockwise
}

void back()
{
  motor1.setSpeed(255);
  motor1.run(BACKWARD); //rotate the motor counterclockwise
  motor2.setSpeed(255);
  motor2.run(BACKWARD); //rotate the motor counterclockwise
}

void left()
{
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(FORWARD); //rotate the motor clockwise
  motor2.setSpeed(0);
  motor2.run(RELEASE); //turn motor2 off
}

void right()
{
  motor1.setSpeed(0);
  motor1.run(RELEASE); //turn motor1 off
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(FORWARD); //rotate the motor clockwise
}

void Stop()
{
  motor1.setSpeed(0);
  motor2.run(RELEASE); //turn motor1 off
  motor2.setSpeed(0);
  motor2.run(RELEASE); //turn motor2 off
}


Isaac96

What you need is it to send "S" when you release the forward button in the app. Otherwise, it receives the F and goes forward until receiving something else.
Do not PM me for help. I will delete immediately.
CONNECT THE GROUNDS!

After Tuesday, even the calendar goes W T F

PaulS

Quote
What you need is it to send "S" when you release the forward button in the app. Otherwise, it receives the F and goes forward until receiving something else.
Given that an "S" does nothing, how will that help? Sending anything else should stop the current movement, whether that is moving forward, backing up, or turning left or right.

OP: If the car won't turn, but does go forwards and backwards, it is not a software problem.
The art of getting good answers lies in asking good questions.

jremington

You need to find out what characters the phone is actually sending. Disconnect the Arduino from the motor driver and put in this print statement after the Serial.read():

Code: [Select]
Serial.print(command,HEX);

That will print out the hexadecimal value of each character received.

agbaiatu80



OP: If the car won't turn, but does go forwards and backwards, it is not a software problem.
[/quote]

I'm this close to give up; I've tried everything that I could think of. So, the software it's ok....then...what :((

jremington

What characters does the phone send?

kumantech

Do not give up, you are very close to the success.

Go Up