Hi,
with this program, if the arduino recieves "1" he turns LED 13 on, otherwise, he turns it off.
This works, when i use this app: https://play.google.com/store/apps/details?id=mBluetoothSerialController.nomal&hl=de
But i dont recieve any data. Do you know what could be wrong on this program?
char val;
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop() {
if( Serial.available() ) // if data is available to read
{
char val = (char)Serial.read(); // read it and store it in 'val'
if (val == '1')
{
digitalWrite(13, HIGH);
}
else
{
digitalWrite(13, LOW);
}
Serial.println(val + "OK");
Serial.flush();
}
}
Do you have the Arduino connected via USB cable to the same computer you are trying to communicate with via bluetooth. If so disconnect the cable. The alternative is to use a different computer for bluetooth comms.
Thx for your help.
The Arduino has a "HC-06" Bluetooth Modul connected and i want to communicate with my smartphone (Moto g).
I have linked the app which i use as serial monitor. Has the app maybe the wrong charset or baudrate?
Sending chars form the smartphone to the arduino works. But sending them from the arduino to the smarthpone doesn´t.
I don't think charset has anything to do with it, and 9600 is the default baudrate. If you are using a phone, you are absolved from making the USB cable mistake. One way traffic should be sufficient to prove the comms, are kosher but there may be a mechanical fault. You should be able to test the code with a PC with cable - no bluetooth.
You might find the following background notes useful
http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf
http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino
My program works over the serial usb connection with the pc. But it doesn´t work with the smartphone over bluetooth.
Maybe i am using the wrong app? Sometimes i recieve '?' symbols. But not everytime i sent data.
OK, you have proved the code is kosher. I would not have thought the app was a problem. I use Bluetooth Graphics Terminal.