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:
- An Arduino board ( I sell them too )
- full-size USB Host Shield 2.0
- USB Host Shield 2.0 library downloaded and installed in your Arduino library directory
- An SPP example sketch
- Bluetooth dongle – see below for detailed discussion
- 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.
- 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.
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.
Thank you for your time!
Oleg.
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
Related posts:
- Using USB Bluetooth dongle on Arduino to connect to Windows PC
- Exchanging data between USB devices and Android phone using Arduino and USB Host shield
- Bluetooth code for Arduino USB Host
- Bluetooth RFCOMM/SPP service support for USB Host 2.0 Library released!
- Android ADK terminal emulator for Arduino
- PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 3
- RC car controlled by Wii Remote on Arduino
- PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 1
- Interfacing Arduino to USB GPRS modem
- PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 2












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.
Hi,can you help me ?
I got this: (picture ı uploaded to my face profile)
http://www.facebook.com/photo.php?fbid=10151492173800676&set=a.10151492173550676.549612.643125675&type=3&theater
you can send me message over facebook also. ıt notivicates me
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.
Here’s a couple -> https://github.com/felis/USB_Host_Shield_2.0/issues/41
There is a full list at the wiki as well: https://github.com/felis/USB_Host_Shield_2.0/wiki
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.
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?
They broke BT around 4.2. It is definitely not working in 4.2.1 on my N7. I recently upgraded to 4.2.2, have yet to test it.
Well, just went back to 4.1 …and its working.
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 ?
Yes it’s possible. Simply uncomment this line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/avrpins.h#L25
And here is a list of dongles that are confirmed working with the library: https://github.com/felis/USB_Host_Shield_2.0/wiki
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 ?
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.
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
No I have the Wifi version. It doesn’t look like it has ever been available with Android 4.1: https://developers.google.com/android/nexus/images#nakasig. So you just have to wait for Google to fix the issue
I solved the problem with Android 4.2, so it should now work with your device!
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?
Just use createInsecureRfcommSocketToServiceRecord: http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#createInsecureRfcommSocketToServiceRecord(java.util.UUID) in your Android app instead.
Check out my Android app for my balancing robot: https://github.com/TKJElectronics/BalanduinoAndroidApp/blob/master/src/com/tkjelectronics/balanduino/BluetoothChatService.java#L301. I only pair once with the Arduino, so the phone remembers the device and then after that I simply connect using the createInsecureRfcommSocketToServiceRecord function.
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.
Thank you
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!
I seems like you dongle is not working correctly. Try another one
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)
See this reply: https://www.circuitsathome.com/mcu/using-usb-bluetooth-dongle-on-arduino-to-connect-to-android-phone/comment-page-1#comment-21079 – it answers your first question.
Yes of course simply receive the data using your Arduino and then send the data to your Android phone, or is this not what you mean?
Take a look on how I send data to an Android phone on my balancing robot: https://github.com/TKJElectronics/Balanduino/blob/master/Firmware/Balanduino/Bluetooth.ino.
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
There shouldn’t be a problem with the newest version of the code. Please make sure you have the newest version from Github!
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?!
Try to post your code somewhere like gist: https://gist.github.com/ and I will try to see if I can see what the problem is
thank you very much for you help
i will try to give my best shot and if i completely failed i will be posting my code.
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?
Make sure DUE has a driver for your device. Last time I checked thy only supported HID boot.
Do it work for a smart tv that don’t have a Bluetooth for the headset.
it needs a bluetooth of some kind inside, not necessarily a headset.