Go Down

Topic: Problem in voice control using HC05 module and Android app. (Read 47 times) previous topic - next topic

Tmkocsociety

I am using -hc 05 Bluetooth module and AMR android app.

Here is my code:
Code: [Select]
#include <SoftwareSerial.h>
SoftwareSerial BT(10,11);
String readData;
void setup()
{
 BT.begin(9600);
 Serial.begin(9600);
 pinMode(7,OUTPUT);
}
void loop()
{
 while (BT.available())
 {
  delay(10);
  char c=BT.read();
  readData +=c;
 }
 if(readData.length()>0)
{
Serial.println(readData);
if (readData=="*forward#");
{
  digitalWrite(7,HIGH);
}
if (readData=="*off#");
{
  digitalWrite(7,LOW);
}
readData="";
}
}



Problem:
1. When i say anything(not only forward),led turns on.
2. When i add second command to code,it didnt work,led only SPARKS...like.
Reply pls where is the fault and the solution for it.
Thanks

PaulS

Code: [Select]
while (BT.available())
 {
  delay(10);
  char c=BT.read();
  readData +=c;
 }

While you KNOW that there is data to read, stuff your head in the sand for 99.9% of the time. Why?

That delay() is absolutely the wrong way of ensuring that you get a complete packet.

Apparently all of the packets contain start ('*') and end ('#') markers. Read the data this way, using char arrays, NOT Strings:
Serial input basics - updated

I've never understand why anyone would do anonymous printing. I've never understood why anyone would print a string without some kind of markers before and after the text, so that they could see if there were non-printable characters in the string.
The art of getting good answers lies in asking good questions.

Tmkocsociety

Thanks for you help  :)
But being new, i didnt understand properly everything.
What exactly i have to do ??pls tell

vinceherman

What exactly i have to do ??pls tell
One of the things you should do is read through the well thought out tutorial that PaulS linked to for you.
Here is that link again
Serial input basics - updated
Go read through it.  It is a fantastic way for someone who is new to learn.

Go Up