Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 706
Diptangsu Goswami Avatar asked Jul 05 '17 13:07

Diptangsu Goswami


People also ask

How do I transfer data from HC-05 to mobile?

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'.

How connect Bluetooth Arduino Uno to Android?

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.


1 Answers

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

like image 144
Oussema Aroua Avatar answered Oct 26 '22 11:10

Oussema Aroua