connecting an android phone to an arduino via bluetooth

The Goal

I’ve been working on having my Android phone talk to my Arduino wirelessly with Bluetooth.  I want to do it because I think it is pretty cool how powerful smartphone gesture interaction is- swipes and taps on a touchscreen is compelling- and I am surprised there are not more products and things around us that can talk to smartphones through local wireless communication-  even basic consumer electronics. Once something is connected to a smartphone, the possible functions expands.  Most simply, just consider any electronic object being able to interface not just with touch gesture, but also with the web through tethering.

Materials

I am using an HTC Incredible  and BlueSmirf Silver with an Arduino Uno.

Bluetooth Setup

First – getting the bluetooth set up properly I found this tutorial useful : http://www.mutexlabs.com/r-bluesmirf-silver-intro.html.  Remember that when you first hook up the bluetooth, it will blink fast and then after a minute slow down.  While it is going fast, you must connect to it. Once it slows down, switch it off, then on.  For some reason there is this time limit to connect. Sometimes the connection will just not happen, in this case turn off the module, and then on, and try again.

The default password is probably ’1234′ when you connect to the device in Bluetooth Preference.  To talk to the module, I used Cornflake but you can use other things like ZTerm.  You will need to do this to change the baud rate, which must be the same between the arduino and the bluetooth module (this will be more clear when going through the Amarino tutorials discussed below).

Some Issues

I researched quite a few methods to program Bluetooth connection between my phone and the Arduino.  The creators of the SweetBT share a similar sentiment of connecting mobile phones locally to things around. They created a Processing library for Android Arduino Bluetooth interfacing.  I first tried that route since I’m pretty comfortable with Processing, but I had trouble with my app crashing.  I tried going through this tutorial: http://webdelcire.com/wordpress/archives/1045 on Processing, Android, and Arduino- but ran into similar phone freezing issues.   One issue I noticed was that if I closed my test application after bluetooth connection, my phone would slow down and it took several minutes for any gesture to respond.  The only way out of this was to pull out the battery (since there is not off switch on the phone, and the button did not respond when I held it down).

Success! 

I came across the Amarino toolkit.  It comes with an app to connect to the bluetooth module with your phone, and several example apps to run on an android phone and an arduino after the connection has been made.  The SensorGraph tutorial covers reading values from the arduino and plotting them on the phone (so arduino –> android), and the MultiColorLamp tutorial covers sending data from the android to the arduino (so android –> arduino).   So far the only issue I have found is that you have to hand type in the device address of the bluetooth module into the android app.  In the future I hope to automate this procedure after a device is connected via bluetooth.

In the coming weeks I’ll share updates on what I’m prototyping with the android+arduino+bluetooth+Processing combination.

Note: You may wonder why I did not choose to use an android IOIO board.  I did this mostly because I wanted to use a smaller Arduino- in future iterations I plan to switch to the Nano.  IOIO includes android APIs to communicate with the board, but so far serial through Bluetooth is working fine for my purposes.

3 thoughts on “connecting an android phone to an arduino via bluetooth”

  1. I have this issue with running the bluetooth chat sample app from android.

    I have an Arduino connected to with bluesmirf.
    When I install a free app like blue s2 the bluetooth connects fine. but the sample bluetooth chat app keeps crashing.

    I am running android 4.0 on a samsung galaxy 2 7″ tablet.

  2. I have published an Android app that removes all the andriod programming. You only need to do some Arduino programming to send simple msgs and handle simple cmds.

    Think red-designed HTML for micros. The Android app (pfod) is the micro browser and the Arduino is the micro server. Messages are typically <255 bytes. See http://www.pfod.com.au for numerous examples.

Comments are closed.