Using USB Bluetooth dongle on Arduino to connect to Android phone

By Oleg Mazurov

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.

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:

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

ASUS label

Insides of the red 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:

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

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.

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

After a short time the next screen pops up. This is pairing request sent from Arduino. Tap on the form field

Type a PIN and press ‘Done’. On the next (or is it previous?) screen tap ‘OK’

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.

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

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.

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.

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?

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 would also like to use the Mega ADK with 2.0 lib for this project but I don’t understand what avrpins.h#L25 is? The listing doesn’t look like a commented line.
What is the line? Also can I use the mini version (that I have) of the USB Host Shield for this project?

Unfortunately Google broke something in the Bluetooth core in 4.2. I got a Nexus 7 myself, so I downgraded to 4.1.1 by installing Cyanogenmod. I recommend using the following tool: http://www.wugfresh.com/nrt/ to root your device.

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.

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?

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)

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

Hello again,
i have downloaded the latest code today from this this link: https://github.com/felis/USB_Host_Shield_2.0
but i still get the same error:
“Error sending L2CAP message: 0xD6 – Channel ID: 00 41” when i send long strings.
it’s better than the previous code but actually i’m sending a string of size about 300 characters or more and as i said prefer to send it as a block as it is.
any suggestions?!

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?

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

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.

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

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?

I was wondering if there was a way to enable debugging without editing settings.h?

Let me elaborate:
I am working on a single sketch with a handful of people, who are all using different computers.
Is there anything that could be done within the individual sketch that would only enable serial debugging for that sketch?

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

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)

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/

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?

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?

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

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.

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.

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

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

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