Posts

Using USB Bluetooth dongle on Arduino to connect to Android phone

Arduino connected to Nexus S

Arduino connected to Nexus S


Since Kristian’s release of SPP service for USB Host 2.0 library I got many e-mails with questions about Bluetooth serial communications in general and using the SPP class in particular. While establishing a Bluetooth connection is quite easy when using PCs/smartphones/tablets, the Arduino implementation is less user-friendly (for a good reason) and somewhat confusing. This article is intended to be a short tutorial of Arduino USB Bluetooth connectivity using an Android device as a peer – in my opinion, the simplest one to set up and communicate.

To follow this tutorial, you will need the following:

  1. An Arduino board ( I sell them too )
  2. full-size USB Host Shield 2.0
  3. USB Host Shield 2.0 library downloaded and installed in your Arduino library directory
  4. An SPP example sketch
  5. Bluetooth dongle – see below for detailed discussion
  6. Android device – a phone or tablet. The accuracy of this tutorial has been checked on Nexus S phone and Nexus 7 tablet, both running Jelly Bean 4.1.1 OS.
  7. A Bluetooth terminal emulator app for Android – I use Blueterm

The hardware setup is shown on the title photo (click on it to make it larger). It is a good idea to use external power supply at least in the beginning – some Bluetooth dongles are not happy when powered together with Arduino board/USB Host shield from USB cable. On a side note, it is always a good idea to use external power supply while experimenting with USB devices, especially when using current Arduino boards with their weak regulators. Also, Bluetooth code requires plenty of resources. The example used in this article compiles in ~24K and even though it would work on standard Arduino, any meaningful project will likely require a bigger board, like a Mega.

Finding compatible Bluetooth dongle could be tricky. Many will work; a pile of dongles in the foreground represent compatible ones. Older dongles from Belkin, D-Link and Kingston are all good. Most Chinese dongles from eBay are likely good too. Among brand names, Asus dongles won’t work. Bluetooth dongle sold by Sparkfun is an example of incompatible Chinese product.

Here’s how the terminal output looks like when compatible dongle is used:

1
2
3
4
5
6
7
SPP Bluetooth Library Started
Bluetooth Dongle Initialized
No response to HCI Reset
HCI Reset complete
Local Bluetooth Address: 00:0C:76:46:1A:D6
The name is set to: Arduino
Wait For Incoming Connection Request

Note line 3. You may or may not see this message. In any case, the output similar to the one above is an indication of a good dongle. Also note device address – if you have many active BT devices around you this address will help you find your Arduino in the pairing list.

Now let’s look at the dark side. The following terminal output is typical for an incompatible dongle:

SPP Bluetooth Library Started
Unknown Device Connected - VID: 0CF3 PID: 3000
BTD Init Failed, error code: 209

Here is another one:

SPP Bluetooth Library Started
getConf
BTD Init Failed, error code: 13

You may also receive an output which is even less informative. Sometimes, only the first line is printed. Sometimes, some random garbage is printed. And sometimes, no output is given at all. All this mean your dongle is incompatible with library code and you need to find a new one. Here’s some closeups of my bad dongles.

Incompatible dongles

Incompatible dongles

ASUS label

ASUS label

Insides of the red dongle

Insides of the red dongle

Insides of the black dongle

Insides of the black dongle

A little ASUS dongle has downloadable firmware. When used on Windows machine, a dongle appears on the bus as a proprietary device, the driver detects it, loads the firmware and resets the dongle. After reset the dongle comes up as a typical Bluetooth. Due to the limited resources this process is difficult to implement on Arduino therefore this dongle is not supported.

Other two dongles are equipped with strange controllers which don’t like MAX3421E for some reason. I have several others packaged in similar cases. There is a lot of dongles looking like this on eBay – don’t buy them, they don’t work very well with a PC either.

It’s now time to move to the part 2 – connectivity. Assuming that a compatible dongle is attached and sketch is displaying ‘Wait For Incoming Connection Request’ line it’s time to switch attention to the Android device. The steps and screenshots (click on them to make them larger) are enumerated below:

  1. Go to ‘Settings’ and make sure Bluetooth is turned on as pictured. It is also a good idea to check if any remnants from previous pairing attempts are present – tap on Bluetooth and see if any Arduinos are listed as paired and if so, unpair them
  2. Open Blueterm. The opening screen will say ‘not connected’ in the upper right corner. Go to ‘Settings’ (device dependent, mine has an icon under the screen, second from the left) and tap on ‘Connect device’. The next screen appears.
  3. Tap on ‘Scan for devices’. If you have made pairing attempts before, you will see the list of paired devices. You can try to connect to the device from the list, however, I found it less reliable so I suggest to start with a clean list (see 1.)
  4. After a short time the next screen pops up. This is pairing request sent from Arduino. Tap on the form field
  5. Type a PIN and press ‘Done’. On the next (or is it previous?) screen tap ‘OK’
  6. This is the final screen with ‘Hello from Arduino’ line transmitted via Bluetooth. It is now possible to type in an Android or Arduino terminal window and see letters appear in another terminal window

The following listing shows Arduino terminal output during connection negotiation phase. A lot of useful info can be extracted from it. If you’re having difficulties while connecting, please copy this output from your terminal and post it in the comments.

Thank you for your time!

Oleg.

1. Turn on Bluetooth

1. Turn on Bluetooth

2.Blueterm window

2.Blueterm window

3. Connect

3. Connect

4. Pairing request

4. Pairing request

5. Typing PIN

5. Typing PIN

6. Hello from Arduino

6. Hello from Arduino

Incoming Connection Request
Remote Name: Nexus S
Connected to Device: 94:63:D1:BC:DD:B4
Wait For Incoming Connection Request
SDP Incoming Connection Request
SDP Configuration Request
SDP Successfully Configured
Disconnected SDP Channel
Bluetooth pin is set too: 1234
RFCOMM Incoming Connection Request
RFCOMM Configuration Request
RFCOMM Successfully Configured
Received SABM Command
Received UIH Parameter Negotiation Command
Received SABM Command
Send UIH Modem Status Response
Send UIH Modem Status Command
Send UIH Command with credit
Received UIH Command with credit
RFCOMM Connection is now established - Automatic
 
SDP Incoming Connection Request
SDP Configuration Request
SDP Successfully Configured
Disconnected SDP Channel
HCI Disconnected from Device
Wait For Incoming Connection Request

94 comments to Using USB Bluetooth dongle on Arduino to connect to Android phone

  • CC

    Thanks for this tutorial! I got some n00b questions:

    1. When you mentioned : “Here’s how the terminal output looks like when compatible dongle is used” I’m not sure what you mean, does it mean Serial monitor on the arduino?

    2. How did you type the pin? From where? Is this arduino Serial communication again?

    I was hoping to use this to make my USB keyboard wireless using Bluetooth with an Arduino Due (I’m using a Micro right now but apparently it doesn’t have enough memory to store the libs.) But I think this may mean that I need two arduinos and two host sheilds. Any suggestions on what to try would be greatly appreciated.

    Thanks in advance.

    • Terminal output means serial monitor or any other terminal program opened on Arduino serial port (i use putty).
      I didn’t understand your second question.

  • Caner

    you can send me message over facebook also. Δ±t notivicates me πŸ™‚

  • Doug

    Is there an updated list of compatible bluetooth dongles? None of the ones pictured exist anymore and everyone I’ve tried so far, other than an old iogear that is no longer sold, is unrecognized. The oldest one I could find was an iogear gbu321 (one model newer than one that works GBU221), but that was also unrecognized.

  • Rob from UK

    Is it possible to use this board to push SMS messages from your android phone into the arduino and then display them on a small LCD display?
    If this is not possible, how about over WiFi and when will this be possible?

    • whatever you can push into Bluetooth on Android is possible to display on LCD connected to Arduino. The limiting factor here is your coding ability, not hardware.

  • Joe

    I’m finding I’m having an interesting problem. I have been able to get full communication between the Arduino and my Galaxy S3, but I have not been able to connect my Nexus 7 (says it pairs, but never connects). Strange since you confirmed it working on yours. Is this most likely a bluetooth dongle problem or something deeper?

  • i wanna buy a USB Bluetooth dongle or usb bluetooth adapter on Arduino to connect to Android phone
    can u give me a link of one that can work ?

    sorry for english it s not my native langage πŸ™

  • i will use the usb bluetooth adapter/dongle with ADK Mega to connect arduino with mobile …is it feasable ?

  • tolisn

    Hi.
    I have a nexus 7 3G using android 4.22. I cannot go to 4.1.1 since this is not available for my device.
    Can you please confirm if it is working with yours ?

  • tolisn

    Hi and thanks for your reply. Is your Nexus7 a 3G version ?
    I checked for a 4.1.1 downgrade for the 3G version but it is not available

  • Hello,
    how can i modify the spp code so i don’t have to pair everytime when i connect with my android to the Arduino via bluetooth?

  • Hello Lauszus,
    not only did you answer my orginal question about bluetooth pairing but i coincidentally by looking in your code solved a problem i have been weeks struggling with which is using the message handler functions like “write” in many activites in bluetoothchat sample.
    i’m really thankful and very happy to see you provide people your experience just on the shelf.

  • Walther Grube

    Wow! This is what I was looking for!
    I’m testing it right now, my Samsung Galaxy Ace Duos (Android 2.3.6) “sees” the Arduino but cannot pair… πŸ™
    On the serial monitor nothing appears only “Incoming Connection Request” (running the spp.ino sketch).
    I’ll try with another dongle as soon as I buy one, maybe this is the problem.
    Any suggestion?

    Thanks!

  • Wood

    Hello, I was wondering how I would be able to send a message from my Arduino mega ADK with a bluetooth dongle to a cell phone without putting the pin in every time. Thus far I have downloaded the library and am able to connect and pair my arduino with my phone. I have even run the example code where it displays “Hello from Arduino”. Also, is there any way to send a message to the phone that is received by a different rF transmitter from the board?(from sensor based data)

  • Joe

    Greetings,
    how can i modify the Bluetooth SPP.ino example to send long strings from the Arduino, where when i try to send long strings the programs seems to hangs and restart!
    and i get a message at the serial monitor: “Error sending L2CAP message: 0x0E – Channel ID: 0 65”
    i can add a delay in my code and send my strings by division but i prefer for some reason in my project to do this normally.
    thank you

  • g.

    Do we still need a USB shield if we’re using an Arduino Due? I believe that it has a host USB port built-in. That should mean that we could plug a Bluetooth dongle into that USB port instead of needing a separate shield. No?

  • Do it work for a smart tv that don’t have a Bluetooth for the headset.

  • snoozerm10

    Hello,
    I have been able to detect the Arduino on my phone.
    However when I try pairing with it, On the Serial Monitor, it says Incoming Connection Request and stops at that. And on the phone , it then says unable to connect to device.
    Can somebody please help me out with this?
    Thank You

  • snoozerm10

    No there is no change in the output. This is what it says.

    SPP Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:1B:10:00:2A:EC
    The name is set to: Arduino
    Wait For Incoming Connection Request
    Incoming Connection Request

    And on the phone, it says that it is unable to connect.

    • Try a different Bluetooth dongle πŸ™‚

      • snoozerm10

        I did try two other Bluetooth dongles, but I am getting the same error. If I am getting the first part of the output, i.e

        “SPP Bluetooth Library Started
        Bluetooth Dongle Initialized
        HCI Reset complete
        Write class of device
        Local Bluetooth Address: 00:1B:10:00:2A:EC
        The name is set to: Arduino
        Wait For Incoming Connection Request
        Incoming Connection Request”

        doesn’t it mean that my dongle is compatible? Could there be a problem with the Arduino ? or anything installed on it?

        • I can’t say for sure why it’s not working. It has nothing to do with the Arduino. It has something to do with the specific chip inside the Bluetooth dongle. I will keep working on adding support for more and more dongles, but the truth is that some dongles simply doesn’t work. For now the easiest solution would be to get a new dongle.

  • jeff

    I purchased some of the dongles from the wiki list and tried to use them, but keep getting “No response to HCI Reset” (continuously). I did some searching for anyone with the same problem, but cannot seem to find anything similar.
    I’m using an external power source with the USB host shield. Any suggestions?

    Outputs the following:
    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    No response to HCI Reset
    No response to HCI Reset
    No response to HCI Reset
    No response to HCI Reset
    No response to HCI Reset
    No response to HCI Reset
    No response to HCI Reset
    No response to HCI Reset
    .
    .
    .

  • donvukovic

    I am using UNO board and iogear GBU521 dongle.

    spp.ino compiles and uploads to the UNO board.

    Only message is “OSC did not start”.

    Does this mean the USB host chip did not start or the dongle (GBU521) did not start ??

    don

  • donvukovic

    Thank You for your quick response.

    Circuits At Home 2011
    USB Host Shield Quality Control Routine
    Reading REVISION register… Die revision invalid. Value returned: 00
    Unrecoverable error – test halted!!
    0x55 pattern is transmitted via SPI
    Press RESET to restart test

  • donvukovic

    I did not connect that connector. (blush)

    I will do that now.

    Thanks

    don

  • donvukovic

    Circuits At Home 2011
    USB Host Shield Quality Control Routine
    Reading REVISION register… Die revision 03
    SPI long test. Transfers 1MB of data. Each dot is 64K……………. SPI long test passed
    GPIO test. Connect GPIN0 to GPOUT7, GPIN1 to GPOUT6, and so on
    Test failed. Value written: 00 Value read: FF
    Press any key to continue…

    OK, now the next step Bluetooth

    Thank you

    don

  • donvukovic

    The library seems to be stuck:

    SPP Bluetooth Library Started

    hangs at this line.

    Ideas ?

    don

  • donvukovic

    OK, where is that found ?

  • donvukovic

    Found it: message.h
    // uncomment to activate
    #define DEBUG_USB_HOST

    SPP Bluetooth Library Started
    Unknown Device Connected – VID: 0A5C PID: 21E8
    BTD Init Failed, error code: D1

  • donvukovic

    Another BT dongle:

    SPP Bluetooth Library Started
    Unknown Device Connected – VID: 0A5C PID: 4500
    BTD Init Failed, error code: D1

    The one above is a iogear GBU421

    The last one was a iogear GBU521.

  • Samlol

    Hi,
    in my output it only says: “PS3 Bluetooth Library Started”

    That’s all. Is this an indicator for a bad dongle?

  • xenonforlife

    Hi,
    I am facing a very strange problem. I can connect to my dongle transfer data. everything seems to working perfectly, but after a while my android device loses connection to the bluetooth dongle. Does anyone know why this might the case?

    Thanks

  • Francisco Pinto

    Hello I have a dongle:
    http://www.kensington.com/kensington/us/us/p/1505/K33902US/bluetooth%C2%AE-2-1-usb-micro-adapter.aspx

    and when I run the application I get only this: Bluetooth Library Started
    Β  any solution?
    and is there any dongle that supports class 1?

  • Cman

    Is this compatible with the Nexus 7 ~ JellyBean 4.3? I

  • Marino Linaje Trigueros

    Nice work, thank you for sharing it.
    May question is: is it possible to use a wifi dongle following a similar approach?
    Maybe the full protocol stack (implementing the TCP/IP stack) requires too much memory

  • zery

    is it possible to control servo motor using USB Bluetooth dongle on Arduino that connect to Android phone?…

  • Simon

    Hello,
    Thanks for this excellent library and hardware, I’ve a few questions:

    1) Using the SPP example is it possible to pair without entering any pin? even better just pair automatically when in range?
    2) Can I adapt the SPP multi example to pair to a serial device (e.g. smartphone) and the PS3 BT object at the same time? Will that work? I’m using the following Android app. which sends bluetooth over serial (using voice input on the phone)

    https://play.google.com/store/apps/details?id=robotspace.simplelabs.amr_voice

    I’d like to talk to my robot and control via PS3 all over the same bluetooth!

    Lastly, is it possible to use SPI on my Mega at the same time as your USB shield? I’m controlling some shift registers and the SPI is apparently the most efficient way (I’m using ShiftPWM library)… I can use different pins but the lib says SPI is fastest. http://www.elcojacobs.com/shiftpwm/

    Thanks in advance!

    Simon

  • Carlos Eduardo Buzeto

    Seemingly my arduino was able to connect with Xperia Z1, but I don’t know why it is not able to send messages to phone, I read in the monitor a message different from Oleg’s example, look here:

    Wait For Incoming Connection Request
    Incoming Connection Request
    Remote Name: Xperia Z1
    Bluetooth pin is set too: 1234
    Connected to Device: 68:76:4F:DA:B4:37
    Information request
    SDP Incoming Connection Request
    SDP Successfully Configured
    Disconnected SDP Channel
    SDP Incoming Connection Request
    SDP Successfully Configured
    Disconnected SDP Channel
    Wait For Incoming Connection Request
    HCI Disconnected from Device
    Wait For Incoming Connection Request

    Somebody could help me, my Sony Xperia has jelly beans 4.4.2?

  • Carlos Eduardo Buzeto

    Hi everybody, About my latest message I don’t know why but the blueterm/blueterm+ didn’t work in my android sony xperia z1, but I was able to test the connection using an app called Arduino Bluetooth Tether, it sent and received data from arduino.

    Now I am trying to send messages with MQTT protocol from my arduino using the bluetooth tether in my android, I am just able to send messages to internet throughout bluetooth connection from my arduino to my android, but not in MQTT protocol, I found a MQTT library for arduino but it uses ethernet shield and wifi shield, Does somebody know any MQTT library for arduino that supports bluetooth connection?

  • Erik

    Hello,
    with the help of SPP.ino it runs on a Mega ADK (with an USB Bluetooth stick) and a Duemilanove and an USB Host shield (with the same stick).
    But when i took the same shield and the same stick with a Mega 2560 the Bluetooth stick didn’t blink and there is no
    Bluetooth device to detect.
    Also i put the USB Host shield (with the same stick) on the Mega ADK and there the Bluetooth stick wasn’t blinking too.
    (The same results were there when i tried to take another Bluetooth stick)
    Any ideas why the USB Host shield (and the Bluetooth stick) is not working with the Megas?

    Thank you very much in advance

    Erik

    • which shield are you using?

      • Erik

        Hello Oleg,

        i solved the problem. Your question shows that your thoughts were right. πŸ™‚
        The shield has a new design, so i thought that it is Rev. 2.
        But i tried, after many fruitless attempts, to follow up a tip i read
        in another forum. There it was said that for an old Rev. shield connections
        should be maid with pins 50-53 to the pins 10-13. First i thought that 50 is
        connected with 10, 51 with 11 … and so forth. But it failed.
        On the Arduino SPI Reference page i found under connections the right assignment.
        So it should be: pin 50 with 12, 51 with 11, 52 with 13, 53 with 10.
        And it works. πŸ™‚

        Best regards
        Erik

  • Erik

    Sorry i forgot to mention that i used every time external power (1,5A 7,5V).
    (and i used the latest library with Arduino 1.0.6)

    Best regards
    Erik

  • Harish Verlekar

    Hi,

    whenever I try connecting it to my Android phone it never connects . The Serial monitor shows the following messages.

    SPP Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:1B:10:00:2A:EC
    The name is set to: Arduino
    Wait For Incoming Connection Request
    Incoming Connection Request
    Remote Name: XPERIA P
    Connected to Device: 20:54:76:4A:DC:AB
    Wait For Incoming Connection Request
    SDP Incoming Connection Request
    SDP Successfully Configured
    Disconnected SDP Channel

    After this it asks me for a pair code on my Android phone , when I enter the code the phone never connects to the arduino and it shows the following messages on the serial monitor.

    HCI Disconnected from Device

    Please help!!!

  • Ner

    Hi everybody!

    When running the program the only message I get is this: SPP Bluetooth Library Started

    Then, I go to Blueterm but it doesn’t find the Arduino shield. What can be the problem?

    I am using a Logistech bluetooth dongle, is it compatible?

    Thank you

  • Declan Farrell

    Hi Guys

    Just wondering if its possible to create an instance of the device without giving it a passkey.

  • Jimminy

    I’m trying to find a Class 1 (long distance) Bluetooth USB dongle that will work reliably.
    I’ve tried this Azio one which doesn’t seem to work at all, and this Dynamode one that “kind of” works, but the connection is very flakey.

    Has anyone found a Class 1 dongle that works well?

    • Jimminy

      Actually, nevermind. Both of those class 1 dongles (the Asio and Dynamode ones on Amazon) work perfectly. My problem was I was powering over USB. Once I powered using a good external regulator everything works beautifully.

      Thanks for all the work on this library!

  • Gordon

    Hi, Thanks for your work on USB Host. I want to use Mega ADK to connect with a bluetooth dongle. then use bluetooth dongle to upload data to mobile. I have download USB HOST Shield 2.0 library. In file settings.h, change 0 to 1: #define USE_UHS_MEGA_ADK 1, compile and upload to Mega ADK, But got information “OSC did not start”, then I use board_qc.ino. Output is

    “Circuits At Home 2011
    USB Host Shield Quality Control Routine
    Reading REVISION register… Die revision 03
    SPI long test. Transfers 1MB of data. Each dot is 64K
    Test failed. Value written: 01 read: 00
    Unrecoverable error – test halted!!
    0x55 pattern is transmitted via SPI
    Press RESET to restart test”

    So what is the real problem here? please help!!!

  • Marrek

    hi there,
    android 4.1.2
    SainSmart UNO R3 Board ATmega328P ATmega16U2
    usb host shield keynes
    bt3.0 dongle broadcom 2070

    SPP Bluetooth Library Started
    Unknown Device Connected – VID: 0A5C PID: 4500
    BTD Init Failed, error code: D1

    BlueTerm&BlueScripts(http://teholabs.com/docs/bluescripts:overview)
    no connection πŸ™ (I even know mac address and pin)(at blue Scripts I swap createRfcommSocketToServiceRecord with createInsecureRfcommSocketToServiceRecord)
    but when I put dongle to win xp, I can do connect. do I have to buy new dongle or uhs? thx

    ps:
    Circuits At Home 2011
    USB Host Shield Quality Control Routine
    Reading REVISION register… Die revision 03
    SPI long test. Transfers 1MB of data. Each dot is 64K……………. SPI long test passed
    GPIO test. Connect GPIN0 to GPOUT7, GPIN1 to GPOUT6, and so on
    Test failed. Value written: 00 Value read: FF
    Press any key to continue…
    GPIO test passed.
    PLL test. 100 chip resets will be performed
    Resetting oscillator

    Reset number 0 Time to stabilize – 384 cycles
    …….

    Reset number 99 Time to stabilize – 384 cycles

    Checking USB device communication.

    Reset complete. Waiting for the first SOF…
    Getting device descriptor
    Descriptor Length: 12
    Descriptor type: 01
    USB version: 0200
    Device class: 09
    Device Subclass: 00
    Device Protocol: 00
    Max.packet size: 08
    Vendor ID: 0A5C
    Product ID: 4500
    Revision ID: 0100
    Mfg.string index: 01
    Prod.string index: 02
    Serial number index: 00
    Number of conf.: 01

    All tests passed. Press RESET to restart test

  • hi i’m trying tot connect tot the arduino using Android Phone as a first test using bleutooth. i can find the balanduino in my list and it is balancing fine . i do the connection request on my Phone but i have tot put in a pairing code i tried 0000 and 1234 but both give the same result. no connection ? cannot communicate to balanduino. how do i solve this ?
    thanks