Bluetooth communication between an Arduino and an Android Phone

Following my recent hardware purchases, I wanted to be able to have an Android phone to talk to an Arduino.

Being an iPhone kind of guy, I did not had a recent Android phone. Hopefully my parents got rid of a ZTE Link device a few months ago. This devices runs on Android 1.6 (Donut), so a really old version of Android, and can’t be updated to any recent version.

I was expecting some issues because of the old version of Android, but this turned out NOT to be a problem.

Android SDK and Amarino setup

What I did last night was to download all the stuff provided by the Amarino Toolkit. I also installed the Android SDK using Homebrew:

brew install android-sdk

After that as explained in the HomeBrew instructions for this recipe, I launched android from a Terminal:


and installed the platforms SDKs. I actually choose to install both Android 4.0 and Android 1.6.

Install the Amarino application in your phone

I then tried to install the Amarino Android application in the emulator. Unfortunately this does not seem to work at all. I tried this with both Android 1.6 and Android 4.0 emulators. You need to use a real Android device, this does not work within the emulators!

As soon as I plugged in the real device using the USB cable and switched the device in debub/development mode, I was able to follow the official instructions in order to upload the Android application in the phone:

adb install Amarino_2_v0_55.apk

Install Eclipse & build the Android application

Now, install Eclipse and the Android plugins for Eclipse.

Create a new Android project and in the wizard choose “Create project from existing sources” and choose the folder where you downloaded the SensorGraph application. In the “build target”, choose the appropriate version, based on the Android device you plan to use.

Then right-click on the project folder, choose “Build Path” -> “Configure Build Path”. Remove the missing JAR path, and add an “External JAR” whose location should be the one of the AmarinoLibrary_v0_55.jar file.

Your project should now build properly!

One more very important thing: edit the file and fill in your Bluetooth address (it’s written on the sticker stuck on your Bluetooth module)

Install the Arduino library

Next we need to install the MeetAndroid library for Arduino. Follow the instructions from the download page. If you’re using a Mac, right click on the Arduino application and choose “Show package contents” in order to see the directories in which you should copy the library.

Install the SensorGraph Arduino application

Finally we need to upload the SensorGraph Arduino application:

  1. Disconnect your Bluetooth module if it is connected, otherwise you won’t be able to upload the code in the Arduino (you only need to remove the RX/TX connections on the Arduino side)
  2. In Eclipse, double-click on the SensorGraph.pde file located in the arduino/SensorGraph directory: this should open the Arduino application and you should see the SensorGraph sketch
  3. Build & upload the sketch
  4. Plug your Bluetooth module (see picture below in order to find out how to connect it properly)

I used a potentiometer in order to be able to have varying values. Here is below the complete setup:

Run the SensorGraph application

Go back to Eclipse. Right-click on the project folder and choose “Run as” -> “Android Application”.

This should deploy the application on your phone via the USB cable. This should also launch the application on the phone.

You should now have a screen displaying the value of your sensor. Try playing with the potentiometer. You should see the value changing.

That was quite a journey to get there, but the end-results is at least satisfying:

comments powered by Disqus