Android talks to Arduino

Android talks to Arduino (1)

This project slightly modifies the Google Android sample app called “Bluetooth Chat” so you can type a message in the Android app and that same message will appear on an LCD attached to an Arduino Uno.

Functionality:  Android  talks to Arduino
1. Run the Android “Bluetooth Chat” sample app (after we modify the app in this instructable).  Type a message in the app’s text box and press the “send” button.  The message you typed echoes on the app display.
2. Message travels through the air from the built-in Android Bluetooth modem to the Bluetooth modem connected to the Arduino Uno.
3. Arduino Uno receives the typed message.
4. The Arduino Uno prints the typed message on the LCD.Android talks to Arduino (1)

Functionality:  Arduino talks to Android
1. Every 30 seconds, the Arduino sends a message (“hello from Arduino”) to the Android phone via Bluetooth.
2. The Arduino message appears on the Android “Bluetooth Chat” sample app display.
Why?  Just an easy way to test the Arduino’s ability to not only receive messages from, but send messages to the Android phone.  You can take the example sketch and change it however you want.

Here’s the full video instruction that we’ll break out into steps:

Step 1: Hardware list

– Arduino Uno (328, 16MHz, 5V).
– Bluetooth Modem: BlueSMiRF Gold, aka FireFly (Sparkfun sku: WRL-00582).
– Parallel LCD (Sparkfun sku: LCD-09051 but you can use pretty much any parallel LCD).
– 10k Potentiometer.
– Wires to connect electronic components.
– Computer and FTDI chip (to change BAUD rate).
– Android Phone (I used a Motorola Droid – operating system v2.2.2 – but Google has sample code for all versions).

Assemble your circuit as shown in the diagram.  You don’t have to assemble anything between circle #1 and circle #2: that is the message going through the air from Android to the Bluetooth modem.  Hey, I’m an Arduino beginner so I’m not assuming anything.  🙂

Step 2: Software List

– Arduino Source code from this project (bluetooth_chat_LCD.pde attached below)
– NewSoftSerial library from Mikal Hart:
– Eclipse
– Android Development Kit (explicitly follow all of Google’s installation instructions)
– “Bluetooth Chat” Android sample code from Google:
– Hyperterminal or TeraTerm to change BAUD rate 

Android Beginners (like me):
Make sure you do at least a couple tests before you execute the rest of this instructable:
– Create a “hello, world” app (lots of examples out there) to make sure you have Android/Eclipse setup correctly to run an app on a virtual device.
– Plug in your Android phone and ensure that you can copy the “hello, world” app to your phone.  Make sure your phone has debugging turned on. Settings –> Applications –> Development –> USB debugging (turn it on)

After you successfully copy an Android app to your actual phone, you can proceed with this instructable.  Keep in mind that you are not going to be able to run this instructable on a virtual device; you have to have a real phone to deploy the “Bluetooth Chat” code.

Step 3: Change BAUD rate on BlueSMiRF Gold

Change the BAUD rate from the default 115.2k to 57.6k.  If you leave the BAUD at 115.2k, the parallel LCD will display gibberish when you send a message from Android to Arduino.  If you set the BAUD below 57.6k, the Android phone will “cut up” the message that the Arduino sketch sends every 30 seconds.  So 57.6k BAUD is just right.Schematic Android talks to Arduino (1)

*Commands to set BAUD:

*Video instructions on how to change BAUD:

FTDI Basic chip:

Step 4: Change Android “Bluetooth Chat” Sample App

Modify the Android app.  Make sure you watch the instructional video at the beginning of this instructable because I have recorded video of how to create a project from an existing sample app and where to change the code.

1. Open the “Bluetooth Chat” project.

2. Open the BluetoothChatService class, find the following declaration for MY_UUID, and replace with the code below:

//Actual Unique UUID for this application generated by Android: fa87c0d0-afac-11de-8a39-0800200c9a66
//common machine UUID that we need to communicate with FireFly Bluetooth module: 00001101-0000-1000-8000-00805F9B34FB
private static final UUID MY_UUID = UUID.fromString(“00001101-0000-1000-8000-00805F9B34FB”);

Read more: Android talks to Arduino

Leave a Comment

Your email address will not be published. Required fields are marked *