In my last post, I showed basic serial communication between an Arduino Uno and a HC-06 Bluetooth module (Arduino + Bluetooth Module Bringup). I will now show how to use that to send characters back and forth between an Android phone/tablet and the Arduino over Bluetooth using the HC-06 module.
I have the same Arduino Uno + HC-06 Bluetooth module setup from the above referenced post. Here is the Fritzing diagram again…
I used the same serial passthrough Arduino sketch as I showed in the above referenced post.
DIAGRAM UPDATED: Someone noticed that I had the HV and LV supply reversed in my original diagram. I have corrected it.
Note: I used a HC-05 Fritzing symbol here (only one I could find). The State and Key pins are not there on my HC-06 module. Not sure what they should be connected to if it were a HC-05.
Andriod Phone/Table Side:
I used an Android tablet for my testing. To prepare for the testing, I powered up the HC-06 module and Bluetooth paired my tablet with the HC-06 using the standard Android Bluetooth settings menu. When I searched for devices in the Android Bluetooth menu, I saw a new device with name HC-06. When I tried to pair with it, I was asked for a pin. I found the default pin listed in the HC-06 datasheet (http://silabs.org.ua/bc4/hc06.pdf) as 1234. I entered 1234 and successfully paired my Android tablet with the HC-06 module. The HC-06 data sheet gives the command to change the pin if needed but I am just going to leave it as the 1234 default for now.
Next was to find an Android App that could send and receive Bluetooth characters/strings. Since I have been playing with MIT’s AppInventor recently (see some of my previous posts with the AppInventor tag), I decided to just build my own.
The Bluetooth Android App
I have a feeling I will be working with Bluetooth often from now on so I decided to make a very generic Android App that can be set to run as BT server or BT client. Once a BT connection is made in either mode, I want to be able to send and receive characters to the other side.
I created the app in MIT’s AppInventor environment but it would be a little too long to post a tutorial on all the steps. If you are interested, here is my .aia file if you want to load it into your AppInventor environment and review it on your own….
If you just want to install and use it, here is the .apk file…
Here are a couple screen shots…
The App can actually be used without the Arduino + HC-06 setup. It can even be installed on 2 Android devices then:
- Pair the 2 Android devices first
- Launched the app on both devices
- Click the “Start as Server” button on the 1st device
- Click the “Start as Client” button on the 2nd device
- If the Bluetooth link is established, the screen on both sides should change to have Send Text / Received Text boxes and Send button.
- Just type a string in the Send Text box and hit the Send button. You should see the string show up in the Received Text box on the other device.
Here is a quick video demo…
The Android to Arduino Bluetooth Test
I didn’t find any documentation on the HC-06 datasheet on how to connect to a BT server so I assumed it was default set up as a BT server. I launched my Android App and clicked “Start as Client”. I had previously already BT paired the HC-06 on that tablet so it popped up as one of options to connect to. I selected HC-06 and the connection was successful. The red LED on the HC-06 went from blinking to solid on. When I sent something from the Android App, it showed up in the Arduino serial monitor window. Now when I typed something in the Arduino serial monitor window, it popped up in the “Received Text” box on the Android App. Before the Arduino serial to HC-06 was for AT commands, but as soon as a BT connection established, it looks like the HC-06 automatically switched to serial pass through mode.
To better illustrate, here is a quick video demo….