# Android Bluetooth to Arduino and vice versa

**URL:** <https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578>\
**Category:** Processing for Android\
**Created:** [December 29, 2020, 8:52am UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578 "2020-12-29T08:52:21Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 2, 2021, 1:19pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/41 "2021-01-02T13:19:53Z")

</div>

ok

i well try it tonight and back to you with the result

i want to ask about APDE is it working with sound library  
i???

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 2, 2021, 1:21pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/42 "2021-01-02T13:21:54Z")

</div>

Yes, you can find an adapted version of the sound lib for the APDE on my Github repo.

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 2, 2021, 1:24pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/43 "2021-01-02T13:24:44Z")

</div>

The best thing you can do to see how to handle the String Str, is to println() it, and visualize it in the console.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 2, 2021, 1:26pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/44 "2021-01-02T13:26:23Z")

</div>

give me the link if you please of the sound library

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 2, 2021, 1:29pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/45 "2021-01-02T13:29:51Z")

</div>

[Here you go](https://github.com/EmmanuelPil/Android-java-code-utilities-widgets-for-Processing-for-Android/blob/master/sound.zip).

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 2, 2021, 1:32pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/46 "2021-01-02T13:32:45Z")

</div>

thanks 👌 👌 👌

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 3, 2021, 1:16pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/47 "2021-01-03T13:16:22Z")

</div>

hi sir

i have tried this sketch but did not work with me

what i miss ???

```auto
import ketai.net.bluetooth.*; 
import android.os.Bundle; 
import oscP5.*; 
import netP5.*; 

OscMessage m; 
KetaiBluetooth bt; 

String str = "myData"; 
int start_time; 

void setup() { 
  bt.start(); 
  m = new OscMessage(str);
} 

void draw() { 
  if (millis() - start_time > 300) { 
    bt.broadcast(m.getBytes()); 
    start_time = millis();
  }
} 

void onCreate(Bundle savedInstanceState) { 
  super.onCreate(savedInstanceState); 
  bt = new KetaiBluetooth(this);
}

```

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 3, 2021, 1:41pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/48 "2021-01-03T13:41:13Z")

</div>

> [@jafal](#):
>
> but did not work with me

Was there any error? Did you give the Bluetooth permissions? If on APDE did you run in App mode?

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 3, 2021, 1:45pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/49 "2021-01-03T13:45:08Z")

</div>

no error just white screen i run it in App mode and give Bluetooth permissions

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 3, 2021, 1:48pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/50 "2021-01-03T13:48:14Z")

</div>

That’s good, but now you have to pair your phone with another Android phone and install the app I mentioned above to visualize the bytes you are sending.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 3, 2021, 1:50pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/51 "2021-01-03T13:50:35Z")

</div>

i did

no result just white screen

i try the serial terminal on both tablets they send to each other ((with out the sketch))

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 3, 2021, 1:52pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/52 "2021-01-03T13:52:53Z")

</div>

Did the terminal app connect to the sender phone?

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 3, 2021, 2:03pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/54 "2021-01-03T14:03:30Z")

</div>

Just to get it right.

- On the sender phone both oscP5 and Ketai library are installed.
- Both phones are paired
- You start the sender sketch on sender phone,
- You tab on the connect icon in the terminal app.
- Only appears “Connected” nothing else?

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 3, 2021, 2:06pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/55 "2021-01-03T14:06:02Z")

</div>

> [@noel](#):
>
> - On the sender phone both oscP5 and Ketai library are installed.
> - Both phones are paired
> - You start the sender sketch on sender phone,
> - You tab on the connect icon in the terminal app.
> - Only appears “Connected” nothing else?

- On the sender phone both oscP5 and Ketai library are installed. yes
- Both phones are paired yes
- You start the sender sketch on sender phone, yes
- You tab on the connect icon in the terminal app.yes
- Only appears “Connected” nothing else? yes

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 3, 2021, 2:08pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/56 "2021-01-03T14:08:04Z")

</div>

I have to think about that, because I use this all the time to see what I am sending, and it doesn’t fail.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 3, 2021, 2:10pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/57 "2021-01-03T14:10:20Z")

</div>

ok

let us make the terminal send to the sketch do you have ready code for this ?

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 3, 2021, 2:29pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/58 "2021-01-03T14:29:14Z")

</div>

Try first to read the bytes send by your HC-05 to your phone with the terminal app.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 3, 2021, 2:31pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/59 "2021-01-03T14:31:39Z")

</div>

i am working on that

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 3, 2021, 3:00pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/60 "2021-01-03T15:00:50Z")

</div>

When you have this working try to read the bytes with this code on your phone.  
The name must be exactly that of your HC-05 module and be sure that there are no other modules paired, to avoid conflicts. Also on the Arduino side set a delay(100), 100 ms between each (short) write(); command.

```auto
import ketai.net.bluetooth.*;
import android.os.Bundle;

String device_name = "HC-05";
String Str; 

KetaiBluetooth bt;

void setup() { 
  fullScreen();
  orientation(PORTRAIT);
  bt.getPairedDeviceNames();
  bt.connectToDeviceByName(device_name);
  bt.start();
  textSize(60);
  textAlign(CENTER);
}

void draw() {
  background(0, 0, 200);
  text(Str, width/2, height/2);
}

void onBluetoothDataEvent(String who, byte[] data) {
  Str = new String(data); 
  println(Str);
}

void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  bt = new KetaiBluetooth(this);
}

```

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 3, 2021, 3:54pm UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/61 "2021-01-03T15:54:00Z")

</div>

hi sir

do i have to use this line or not ?

```auto
String device_name = "HC-05";
//String device_mac = "40:45:DA:00:25:05";/// this line i mean 

```

[Previous page](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578.md?page=2)

[Next page](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578.md?page=4)
