I posted something else about this a while ago. Basically, I was trying to establish a Bluetooth connection between an Android phone and an Arduino. This was to get a remote control car working wirelessly.
I decided to get an HC-06 Bluetooth module instead of the HC-08 I had. This seemed to work for part of it. I can send a string from an Android phone to an Arduino but nothing happens. When testing this I have my Arduino hooked up to my computer and have the serial monitor displayed. When I send the string, the Arduino receives this string then activates a certain piece of code. The forward code works and has a serial print line in it, and when the certain string is sent the word forward is printed on the serial monitor. So I know it's being received but it's just not activating the other part of the function for some reason.
Can anybody help?
I'm pretty sure it's the Arduino code so here it is:
if (Serial.available() > 0) {
string = "";
}
while (Serial.available() > 0) {
command = ((byte)Serial.read());
if (command == ':') {
break;
} else {
string += command;
}
delay(1);
}
if (string == "F") {
forward();
}
if (string == "B") {
back();
}
if (string == "R") {
right();
}
if (string == "L") {
left();
}
if (string == "S") {
stop();
}
}
void forward() {
digitalWrite(ENA, HIGH);
digitalWrite(ENB, HIGH);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
Serial.println("Forward");
}