Hi!
I have managed to make a app on Android Studio in order to send commands from the app to Arduino by using a HC-06. But I have no idea how to send analog value from Arduino to Bluetooth.
We have been looking for tutorials by searching on Google, but did not manage to find anything that helped us.
If somebody could help me with the code or instructions, that will be great.
Thank You
How are you sending data TO the Arduino? How are you reading that data ON the Arduino? Sending data FROM the Arduino is a simple matter of using Serial.print().
For receiving data on the Arduino have a look at serial input basics
And it would probably be a good idea to use the same techniques on the Android side.
You may be interested in this RemoteXY Thread
...R
I am sending data to the Arduino by using this (Android code):
private void turnonStep()
- {*
- if (btSocket!=null)*
- {*
- try*
- {*
- btSocket.getOutputStream().write("SO".toString().getBytes());*
- }*
- catch (IOException e)*
- {*
- msg("Error");*
- }*
- }*
- }*
And reading data on Arduino by using this:
-
if (Serial.available() > 0)*
-
{*
-
string = "";*
-
}*
-
while(Serial.available() > 0)*
-
{*
-
command = ((byte)Serial.read());*
-
if(command == ':')*
-
{*
-
break; *
-
}*
-
else*
-
{*
-
string += command;*
-
}*
-
}*
-
//OM STRÄNGEN "AUTO" SKICKAS FRÅN APPLIKATIONEN TILL ARDUINO, DÅ KOMMER VÄDERANORDNINGAR STYRAS AUTOMATISKT.*
-
if(string == "SO")*
-
{*
Use the code button "</>" when posting code so it soes not appear as italics
Think about this line
while(Serial.available() > 0)
what will happen if 3 characters have arrived but you are expecting 5 ?
The rest of your WHILE loop will finish long before the 4th character arrives.
Have a look at the examples in serial input basics
...R