So I'm making a robotic dog and I'm using the Bluetooth HC-05 module to try to control the robot. It works perfectly fine when plugged into USB, but when I unplug it, the commands from the Bluetooth module no longer seem to do anything. I'm using a 4S li-po battery stepped down with a voltage and amperage regulator to which everything that needs power is connected, so I don't think it's a power or grounding issue. I'm thinking it has something to do with serial commands and not being plugged into the computer? The BT.available()>0 command only works when connected to the pc maybe? I'm basically trying to get the robot to only walk forward when it receives the command "F" from the Bluetooth module. From the programming in the app it will receive the "F" command once when the button is pressed, and when I let go it will send "." once.
Code below...
#include <Servo.h>
#include <SoftwareSerial.h>
SoftwareSerial BT(3,4);
bool FL = false;
bool BL = false;
bool FR = false;
bool BR = false;
float v;
float w;
float x;
float y;
float z;
float A;
float B;
float L;
float D;
float Adeg;
float Bdeg;
float Ddeg;
char data;
Servo TFL;
Servo BFL;
Servo TWFL;
Servo TFR;
Servo BFR;
Servo TWFR;
Servo TBL;
Servo BBL;
Servo TWBL;
Servo TBR;
Servo BBR;
Servo TWBRR;
void setup() {
// put your setup code here, to run once:
TFL.attach(12);
BFL.attach(13);
TWFL.attach(8);
TFR.attach(A1);
BFR.attach(A2);
TWFR.attach(A0);
TBL.attach(10);
BBL.attach(9);
TWBL.attach(7);
TBR.attach(2);
BBR.attach(A5);
TWBRR.attach(A3);
BT.begin(9600);
BFR.write(178);
TFR.write(100);
TFL.write(90);
BFL.write(7);
TWFL.write(70);
TWFR.write(65);
TBL.write(98);
BBL.write(2);
TWBL.write(110);
TBR.write(90);
BBR.write(180);
TWBRR.write(105);
delay(5000);
v = -40;
w = 40;
x = 40;
y = -40;
}
void loop() {
if(BT.available()>0){
data = BT.read();
}
if(data == 'F'){
//Front Left Leg Foward
if(v >= -40 && FL == false){
v = v + 0.25;
z = -pow((-(v*v)+1600),0.25)+115;
L = sqrt(z*z+v*v);
A = acos(L/180);
D = atan(v/z);
Adeg = A * (180/3.14159); //Angle for A
Bdeg = 180-2*Adeg; //Angle for B
Ddeg = D * (180/3.14159); //Angle for D
TFL.write(90+Adeg-Ddeg);
BFL.write(Bdeg+7);
delay(0.5);
if (v == 40 && FL == false){
FL = !FL;
}
}
//Front Left Leg Backward
if(v <= 40 && FL == true){
v = v - 0.25;
z = 125;
L = sqrt(z*z+v*v);
A = acos(L/180);
D = atan(v/z);
Adeg = A * (180/3.14159); //Angle for A
Bdeg = 180-2*Adeg; //Angle for B
Ddeg = D * (180/3.14159); //Angle for D
TFL.write(90+Adeg-Ddeg);
BFL.write(Bdeg+7);
delay(0.5);
if (v == -40 && FL == true){
FL = !FL;
}
}
//Back Left Leg Foward
if(w >= -40 && BL == true){
w = w + 0.25;
z = -pow(-(w*w)+1600,0.25)+115;
L = sqrt(z*z+w*w);
A = acos(L/180);
D = atan(w/z);
Adeg = A * (180/3.14159); //Angle for A
Bdeg = 180-2*Adeg; //Angle for B
Ddeg = D * (180/3.14159); //Angle for D
TBL.write(98+Adeg-Ddeg);
BBL.write(Bdeg+2);
delay(0.5);
if (w == 40 && BL == true){
BL = !BL;
}
}
//Back Left Leg Backward
if(w <= 40 && BL == false){
w = w - 0.25;
z = 125;
L = sqrt(z*z+w*w);
A = acos(L/180);
D = atan(w/z);
Adeg = A * (180/3.14159); //Angle for A
Bdeg = 180-2*Adeg; //Angle for B
Ddeg = D * (180/3.14159); //Angle for D
TBL.write(98+Adeg-Ddeg);
BBL.write(Bdeg+2);
delay(0.5);
if (w == -40 && BL == false){
BL = !BL;
}
}
//Front Right Leg Foward
if(x >= -40 && FR == true){
x = x + 0.25;
z = -pow(-(x*x)+1600,0.25)+115;
L = sqrt(z*z+x*x);
A = acos(L/180);
D = atan(x/z);
Adeg = A * (180/3.14159); //Angle for A
Bdeg = 180-2*Adeg; //Angle for B
Ddeg = D * (180/3.14159); //Angle for D
TFR.write(100-Adeg+Ddeg);
BFR.write(178-Bdeg);
delay(0.5);
if (x == 40 && FR == true){
FR = !FR;
}
}
//Front Right Leg Backward
if(x <= 40 && FR == false){
x = x - 0.25;
z = 125;
L = sqrt(z*z+x*x);
A = acos(L/180);
D = atan(x/z);
Adeg = A * (180/3.14159); //Angle for A
Bdeg = 180-2*Adeg; //Angle for B
Ddeg = D * (180/3.14159); //Angle for D
TFR.write(100-Adeg+Ddeg);
BFR.write(178-Bdeg);
delay(0.5);
if (x == -40 && FR == false){
FR = !FR;
}
}
//Back Right Leg Foward
if(y >= -40 && BR == false){
y = y + 0.25;
z = -pow(-(y*y)+1600,0.25)+115;
L = sqrt(z*z+y*y);
A = acos(L/180);
D = atan(y/z);
Adeg = A * (180/3.14159); //Angle for A
Bdeg = 180-2*Adeg; //Angle for B
Ddeg = D * (180/3.14159); //Angle for D
TBR.write(98-Adeg+Ddeg);
BBR.write(180-Bdeg);
delay(0.5);
if (y == 40 && BR == false){
BR = !BR;
}
}
//Back Right Leg Backward
if(y <= 40 && BR == true){
y = y - 0.25;
z = 125;
L = sqrt(z*z+y*y);
A = acos(L/180);
D = atan(y/z);
Adeg = A * (180/3.14159); //Angle for A
Bdeg = 180-2*Adeg; //Angle for B
Ddeg = D * (180/3.14159); //Angle for D
TBR.write(90-Adeg+Ddeg);
BBR.write(180-Bdeg);
delay(0.5);
if (y == -40 && BR == true){
BR = !BR;
}
}
}
}


