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
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
}