Home » Android » bluetooth – Interfacing Android Nexus One with Arduino + BlueSmirf

bluetooth – Interfacing Android Nexus One with Arduino + BlueSmirf

Posted by: admin May 14, 2020 Leave a comment


I’m a bit new to all of this, so bear with me – I’d really appreciate your help.

I am trying to link the Android Nexus One with an arduino (Duemilanove) that is connected to a BlueSmirf. I have a program that is simply outputting the string “Hello Bluetooth” to whatever device the BlueSmirf is connected to. Here is the Arduino program:

void setup(){
int i;

void loop(){Serial.print(“Hello Bluetooth!”);

One my computer BT terminal I can see the message and connect no problem. The trouble is with my android code. I can connect to the device with android, but when I look at the log it is not displaying “Hello Bluetooth”. Here is the debug log:

04-09 16:27:49.022: ERROR/BTArduino(17288): FireFly-2583 connected

04-09 16:27:49.022: ERROR/BTArduino(17288): STARTING TO CONNECT THE SOCKET

04-09 16:27:55.705: ERROR/BTArduino(17288): Received: 16

04-09 16:27:56.702: ERROR/BTArduino(17288): Received: 1

04-09 16:27:56.712: ERROR/BTArduino(17288): Received: 15

04-09 16:27:57.702: ERROR/BTArduino(17288): Received: 1

04-09 16:27:57.702: ERROR/BTArduino(17288): Received: 15

04-09 16:27:58.704: ERROR/BTArduino(17288): Received: 1

04-09 16:27:58.704: ERROR/BTArduino(17288): Received: 15


Here is the code, I’m trying to put only the relative code but if you need more please let me know:

private class ConnectThread extends Thread {
    private final BluetoothSocket mySocket;
    private final BluetoothDevice myDevice;

    public ConnectThread(BluetoothDevice device) {
        myDevice = device;
        BluetoothSocket tmp = null;
        try {
            tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
        } catch (IOException e) {
        mySocket = tmp;
    public void run() {
        InputStream inStream = null;
        boolean run = false;
        //...More Connection code here...

The more relative code is here:

        byte[] buffer = new byte[1024];
        int bytes;

        // handle Connection
        try {
            inStream = mySocket.getInputStream();
            while (run) {
                try {
                    bytes = inStream.read(buffer);
                    Log.e(TAG, "Received: " + bytes);
                } catch (IOException e3) {
                    Log.e(TAG, "disconnected");

I am reading bytes = inStream.read(buffer). I know bytes is an integer, so I tried sending integers over bluetooth because “bytes” was an integer but it still didn’t make sense.

It almost appears that is sending incorrect baud rate. Could this be true?

Any help would be appreciated. Thank you very much.

How to&Answers:

Did you see this project?



read() returns the number of bytes it successfully read into the buffer. Therefore, in this line of code:

bytes = inStream.read(buffer);

…your message will be found in the first bytes bytes of buffer (assuming everything else is correct). You can convert those to a String like so:

String message = new String(buffer, 0, bytes);

I’m glossing over a number of things here (encoding, concatenating multiple buffers, etc) but this should get you started.