I am using -hc 05 Bluetooth module,arduino UNO and AMR android app.
Here is my code:
#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:
- When i say anything(not only forward),led turns on.
- When i add second command to code(like for turning off),it didnt work,led only SPARKS...like.
//I know I have written wrongly in code - ';'with if
if (readData=="*forward#");
But if I remove it even the above one will not be there,means it not even sparks.(no any effect)
Reply pls where is the fault and the solution for it.
Thanks
I will be thankful if anyone gives me the correct code for voice control using hc05.
NOTE:As I have searched almost every site and video on internet and seen code similar to this code only,but it is not working for me:confused:
How all are able to show correctly that on youtube video ?  -Pls check any video on youtube for voice control HC05
if (readData=="*forward#");
{
digitalWrite(7,HIGH);
}
if (readData=="*off#");
{
digitalWrite(7,LOW);
}
remove the ; from after the if statements
What does the serial print statement tell you. Is the received string from the App identical to what you are testing for? Correct start and end characters and case?
@Tmkocgsociety
Please stop cross posting!!!
four threads removed, follow your thread here.
Read How to use this forum by Nick Gammon. First item each Section.
I'm not familiar with String objects and what your app is actually passing, but it looks like you need to explicitly break from the reading routine. I tested this code with sending *forward# and *off# and it works with the onboard led. Without the break it does not.
There are more robust ways to receive Serial data as character arrays with start and end markers. See Serial Input Basics - updated - Introductory Tutorials - Arduino Forum
#include <SoftwareSerial.h>
SoftwareSerial BT(10, 11);
String readData;
void setup()
{
BT.begin(9600);
Serial.begin(9600);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
}
void loop()
{
while (BT.available())
{
delay(10);
char c = BT.read();
readData += c;
if(c =='#') break;//add this line
}
if (readData.length() > 0)
{
Serial.println(readData);
if (readData == "*forward#")
{
digitalWrite(13, HIGH);
}
if (readData == "*off#")
{
digitalWrite(13, LOW);
}
readData = "";
}
}