Sunday, May 6, 2012

Arduino to Android – Basic Bluetooth Connectivity Tutorial

This tutorial will show you how to configure an Ardunio to communicate over bluetooth with an Android device.

It assumes you have a basic knowledge of the Arduino, the Arduino IDE and installing Android applications from Google Play.

For this tutorial you will need the following items:

  1. An Arduino board.
  2. An Android device with bluetooth.
  3. A bluetooth serial board capable of connecting to the Arduino. 
  4. An Android bluetooth terminal program

You will also need the Arduino IDE.  The Android SDK and a breadboard are not required but are helpful.

What I used:

  1. A breadboard Arduino with a Modern Devices USB BUB.
  2. An Acer Iconia Tab A100 running Ice Cream Sandwich 4.0.3.
  3. A Sparkfun Bluetooth Mate Silver.
  4. BlueTerm by pymasde.es available on Google Play.

Arduino Configuration

Connect GND, VCC, RX and TX from the bluetooth device to the appropriate Arduino pins.  For my setup I connected GND to GND, VCC to +5V, RX to D5 and TX to D6.

Arduino Sketch

The Arduino sketch makes use of the SoftwareSerial library to communicate via two digital pins to the bluetooth device. You will need to make sure you set the SoftwareSerial baud rate to match the baud rate of your bluetooth device.

Android Setup

You will a program on Android that can connect to the bluetooth and host an SPP connection. I used BlueTerm from Google Play but you should be able to use another bluetooth terminal.

Run your bluetooth terminal. If you are using BlueTerm follow the steps below:

Select the three vertical dots to get the menu.

This next step is optional.  To make typing on your Android device easier you may want to turn on local echo.  Press preferences

and then select Local Echo. 

Return to the menu screen by pressing previous and select Connect Device.

Select your bluetooth device.  Mine is named mymate. If you are using the Sparkfun Bluetooth Mate when you successfully connect your Android device to it the blinking red LED marked "Stat" (red arrow in the above picture of the breadboard Arduino) will turn off and the green LED marked "Connect" (green arrow in the above picture) will turn on.

Compile and run the Arduino sketch and you should see output in BlueTerm and the Arduino serial monitor.

Serial Monitor

If you type characters on the Android device they should show up in the Arduino Serial Monitor.

Notes:

  1. As the SDK Emulator doesn’t emulate bluetooth and probably wouldn't be able to make a connection even if it did this example will not run in the emulator.
  2. This example is built upon the work of others. I post it here not as an example of original work but rather as a complete working example for reference. If I didn't appropriately credit you for your work please let me know and I will add you.

8 comments:

Harsh said...

Hi,
I am using your tutorial for my class project and I have been able to the bluetooth connected to blueterm on my android, the light on the bluetooth has turned to green, and I am getting serial output on arduino port but I am not getting output on the blueterm. Please help me out with some troubleshooting ideas, and possible causes. I really need some help and I will appreciate yours. Please do reply to this comment. Thankyou

digitalhack said...


Harsh,

One thing you might want to try would be to connect the rx and tx pins on the bluetooth module and see if the characters you type on blueterm echo back to it. If they do I would double check the setup on the arduino. If they don't it is likely either the bluetooth module, blueterm or the android device.

digitalhack

C.A Majdi said...

Hello digitalhack,
It is posible using your eclipse source code to recived data from arduino and display in editText in android?

For example:
Arduino print.serial "AAA"
the in android will display in Label or editText "AAA".

Kind regard,
CA Majdi

digitalhack said...


C.A Majda,

It is possible to receive data from Arduino and display in Android. I don't have a posted example but I do have one for sending data from Android to Arduino which could probably be used as a starting point for doing what you are looking for. Check out this post http://digitalhacksblog.blogspot.com/2012/05/arduino-to-android-turning-led-on-and.html.

digitalhack

Anonymous said...

im trying to make a pipe climbing robot using msp430..i want to control it via Bluetooth of android phone..can you please help for this? can you help me to build a program for Bluetooth so that I can control my robot .thanku

Unknown said...

i am making my own app, so how will i connect bluetooth module to it n get the output to my own app..... plz post a link....

Unknown said...

my problem that display "hello bluetooth" on my blueTerm.
please help me ASAP..

Unknown said...

Hii digitalhack.I have a small doubt can we save the data sent to the terminal app as a file like .csv??Please reply...