How to send data from Arduino-uno using the HC-05 Bluetooth module and read it on Android?

I can send data from my Android phone to my Arduino Uno using the HC-05 module. I also want to send data from Arduino to my Android phone, and I cannot do this.

Question:. I will send a number from 0-9 using my Android application in Arduino Uno, Arduino will send back the same number to my application, in words. At the moment, I can send numbers / letters to Arduino from my application. I need help in the second part of the problem.

This is essentially the perfect duplicate of this Android question - receiving Bluetooth data from Arduino , but unfortunately this remains unanswered.

+5
source share
2 answers

for receiving data from 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 send data from arduino

 serialPort.write(string.getBytes()); 

check out the full tutorial

+3
source

Your connection seems to work fine:
In Arduino you need to use btSerial.readStringUntil('#')
You can change # with any character you want.
Then on Android, add "#" to any line you send.
Also replace btSerial with your serial bluetooth object

0
source

Source: https://habr.com/ru/post/1269523/


All Articles