Voice recognizition not working

int leftmotorForward=A3;
int leftmotorBackward=A0;
int rightmotorForward=A1;
int rightmotorBackward=A2;
char data=0;
void setup() {
Serial.begin(9600);

pinMode(A0,OUTPUT);
pinMode(A1,OUTPUT);
pinMode(A2,OUTPUT);
pinMode(A3,OUTPUT);
}
void go() {
analogWrite(A0,0);
analogWrite(A1,255);
analogWrite(A2,0);
analogWrite(A3,255);
}
void
comeback() {
analogWrite(A0,255);
analogWrite(A1,0);
analogWrite(A2,255);
analogWrite(A3,0);
}

char c;
String voice;
void loop(){

while(Serial.available()) {
delay(10);
char c=Serial.read();
if(c=='#')
{break; }
voice += c;
}

if (voice.length() > 0) {
Serial.println(voice);
if (voice=='go'){
analogWrite(A0,0);
analogWrite(A1,255);
analogWrite(A2,0);
analogWrite(A3,255);
}
else if (voice=='comeback'){
analogWrite(A0,255);
analogWrite(A1,0);
analogWrite(A2 c,255);
analogWrite(A3,0);
}

voice="";
}
}

This is my code. It gets compiled and uploaded to the arduino properly. But when I command through my android bt voice controller app, nothing works. I'm unable to understand what's the problem.

It's hard to see how this post qualifies as

Suggestions for the Arduino Project -
What do you think should be improved, features for the hard/software, bugs you found

Please remember to use code tags when posting code.

if (voice=='comeback') Oops

if (voice=='comeback')

Single quotes are for single characters. Can you post a picture of your keyboard with the comeback key circled?

int leftmotorForward=A3;
int leftmotorBackward=A0;
int rightmotorForward=A1;
int rightmotorBackward=A2;
char data=0;
void setup() {
Serial.begin(9600);

pinMode(A0,OUTPUT);
pinMode(A1,OUTPUT);
pinMode(A2,OUTPUT);
pinMode(A3,OUTPUT);
}
void go() {
analogWrite(A0,0);
analogWrite(A1,255);
analogWrite(A2,0);
analogWrite(A3,255);
}
void
comeback() {
analogWrite(A0,255);
analogWrite(A1,0);
analogWrite(A2,255);
analogWrite(A3,0);
}

char c;
String voice;
void loop(){

while(Serial.available()) {
delay(10);
char c=Serial.read();
if(c=='#')
{break; }
voice += c;
}

if (voice.length() > 0) {
Serial.println(voice);
if (voice=='go'){
analogWrite(A0,0);
analogWrite(A1,255);
analogWrite(A2,0);
analogWrite(A3,255);
}
else if (voice=='comeback'){
analogWrite(A0,255);
analogWrite(A1,0);
analogWrite(A2 c,255);
analogWrite(A3,0);
}

voice="";
}
}

This is my code. It gets compiled and uploaded to the arduino properly. But when I command through my android bt voice controller app, nothing works. I'm unable to understand what's the problem.

Please use code tags when posting code.

Single quotes are for single byte character constants, not character strings. Use double quotes instead.

if (voice=='go')

On Arduino, Strings cause memory problems and program crashes. It is better and safer to use C-strings and character functions like strcmp().

Cross-posting gets really irritating, really fast.

Threads merged