I am working on a small robot that would have 3 wheels 2 dc motors on the back for steering and a wheel in frint just for balance. I am using arduino uno with the adafruit motor shield and hc-05 and i have made a code.When i connect the robot to the computer with the cable and input the commands everything works fine but when i try to do the same with my mobile phone via bluetooth and an android application nothing happens i also tried using bluetooth adapter on the pc and connecting that way but i came across same results. The mobile application basicaly just sends characters to the arduino to control it. Can someone help me fix the problem here is the code
#include <AFMotor.h>
AF_DCMotor desniMotor ( 1 ); // right dc motor
AF_DCMotor lijeviMotor ( 2 ); //left dc motor
char dataIn = 'S'; //data comming from the phone
char determinant; //used in the check function
char det; //used in the loop function
int velocity = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
det = check();
while (det == 'F') //if incoming data is a F, move foward
{
desniMotor.run (FORWARD); //right motor moves forward
desniMotor.setSpeed (velocity); // rotational speed of the motor
lijeviMotor.run (FORWARD); // -||-
lijeviMotor.setSpeed (velocity); // -||-
det = check();
}
while (det == 'B') //if incoming data is a B, move back
{
desniMotor.run (BACKWARD); //
desniMotor.setSpeed (velocity); //
lijeviMotor.run (BACKWARD); // -||-
lijeviMotor.setSpeed (velocity); //-||-
det = check();
}
while (det == 'L') //if incoming data is a L, move wheels left
{
desniMotor.run (FORWARD);
desniMotor.setSpeed (velocity);
lijeviMotor.run (BACKWARD);
lijeviMotor.setSpeed (velocity);
det = check();
}
while (det == 'R') //if incoming data is a R, move wheels right
{
desniMotor.run (BACKWARD);
desniMotor.setSpeed (velocity);
lijeviMotor.run (FORWARD);
lijeviMotor.setSpeed (velocity);
det = check();
}
while (det == 'I') //if incoming data is a I, turn right forward
{
desniMotor.run (FORWARD);
desniMotor.setSpeed (velocity);
lijeviMotor.run (FORWARD);
lijeviMotor.setSpeed (velocity);
det = check();
}
while (det == 'J') //if incoming data is a J, turn right back
{
desniMotor.run (BACKWARD);
desniMotor.setSpeed (velocity);
lijeviMotor.run (BACKWARD);
lijeviMotor.setSpeed (velocity);
det = check();
}
while (det == 'G') //if incoming data is a G, turn left forward
{
desniMotor.run (FORWARD);
desniMotor.setSpeed (velocity);
lijeviMotor.run (FORWARD);
lijeviMotor.setSpeed (velocity);
det = check();
}
while (det == 'H') //if incoming data is a H, turn left back
{
desniMotor.run (BACKWARD);
desniMotor.setSpeed (velocity);
lijeviMotor.run (BACKWARD);
lijeviMotor.setSpeed (velocity);
det = check();
}
while (det == 'S') //if incoming data is a S, stop
{
desniMotor.run (RELEASE);
lijeviMotor.run (RELEASE);
det = check();
}
}
int check()
{
if (Serial.available() > 0) //Check for data on the serial lines.
{
dataIn = Serial.read(); //Get the character sent by the phone and store it in 'dataIn'.
if (dataIn == 'F')
{
determinant = 'F';
}
else if (dataIn == 'B')
{
determinant = 'B';
}
else if (dataIn == 'L')
{
determinant = 'L';
}
else if (dataIn == 'R')
{
determinant = 'R';
}
else if (dataIn == 'I')
{
determinant = 'I';
}
else if (dataIn == 'J')
{
determinant = 'J';
}
else if (dataIn == 'G')
{
determinant = 'G';
}
else if (dataIn == 'H')
{
determinant = 'H';
}
else if (dataIn == 'S')
{
determinant = 'S';
}
else if (dataIn == '0')
{
velocity = 0;
}
else if (dataIn == '1')
{
velocity = 25;
}
else if (dataIn == '2')
{
velocity = 50;
}
else if (dataIn == '3')
{
velocity = 75;
}
else if (dataIn == '4')
{
velocity = 100;
}
else if (dataIn == '5')
{
velocity = 125;
}
else if (dataIn == '6')
{
velocity = 150;
}
else if (dataIn == '7')
{
velocity = 175;
}
else if (dataIn == '8')
{
velocity = 200;
}
else if (dataIn == '9')
{
velocity = 225;
}
else if (dataIn == 'q')
{
velocity = 255;
}
}
return determinant;
}