I am able to send data from my Android phone to my Arduino Uno using the HC-05 module. I also want to send data from the Arduino to my Android phone and I'm unable to do that.
Question: I will send a number from 0-9 using my android app to my Arduino Uno, the Arduino will send back the same number to my app, in words. For now, I am able to send numbers/letters to my Arduino from my app. I want help with the second part of the problem.
This is, in fact, a perfect duplicate of this question Android - receive bluetooth data from Arduino, but, unfortunately, this remains unanswered.
Pair your phone with HC-05. for doing this go to Settings->Bluetooth->Scan device->select HC-05 and pair it. Pass code to pair is '1234'.
Before being able to use the Android application, you need to pair the Bluetooth module with your smartphone. Power the Arduino board, turn on Bluetooth on the Android phone and search for Bluetooth devices nearby: the JY-MCU module will present itself as HC-06, the pairing password is 1234.
for receiving data from the arduino
UsbSerialInterface.UsbReadCallback mCallback = new UsbSerialInterface.UsbReadCallback() {
//Defining a Callback which triggers whenever data is read.
@Override
public void onReceivedData(byte[] arg0) {
String data = null;
try {
data = new String(arg0, "UTF-8");
data.concat("/n");
tvAppend(textView, data);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
};
and to send data from the arduino
serialPort.write(string.getBytes());
check the full tutorial
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With