Simple Bluetooth connection with Android

In this post I’ll describe how I got a simple bluetooth connection set up with an Android phone and Windows 8. You’d think it would work out of the box fairly easily but for me it sure didn’t, probably because I’m using a cheap BT dongle.

First of all, go check out this Android bluetooth code bit, that will allow you to connect and send/receive data over the communication channel. Make sure to edit the following line of code

  // MAC-address of Bluetooth module (you must edit this line)
  private static String address = "00:15:FF:F2:19:5F";

Here you will need to fill in the MAC address of your Bluetooth module in your PC (or if your PC doesn’t have BT built in, a Bluetooth dongle). For some reason I could not find it easily on Windows 8, googling said you could find it in the Address field of the Bluetooth module in Device Manager, mine showed “00000002” which obviously is not a MAC address.

To find it I enabled visibility of my BT dongle (easiest way to do this is to go to Control Panel and search for “Bluetooth”). Select “Change Bluetooth settings” and tick the “Allow Bluetooth devices to find this computer”. Apply the changes and turn to your Android phone. Now search for discoverable devices while you have logcat active (e.g. in Eclipse). Once the pairing is done, check your logcat log and voila, the MAC address will be somewhere in the log lines. I know this is a very stupid approach on getting your BT MAC but I couldn’t be bothered to dig through Windows 8’s multitude of (hidden) menus and options.

Bluetooth Settings

Bluetooth Settings

After this you should be able to “hide” your Bluetooth radio again as the Android app will be able to connect without any problems now it has the MAC address.

Next up you probably want to be able to receive data from your phone to your PC, this requires a serial port (COM Port). In the Bluetooth Settings window, go to the COM Ports tab and click “Add”. Select “Incoming” and hit OK. Your computer will assign a COM port for you.

In my case it was COM4. To easily test communications, you can download ComTestSerial. It looks a bit funky but don’t worry, it works great. Once installed, run the program and hit the “Serial Port” button in the bottom right of the program. In the dialog that appears make sure the COM port that was created earlier is checked. I left the baud rate and other options as default. Lastly, click the “Serial port (COM X)” button with a red LED next to it (X being the number of the COM port). and your connection will be open.

Finally, run the Android app and hit the buttons, you’ll see 0’s and 1’s being received by your computer.

COM Test

COM Test

And there you have it, simple serial port communication over a wireless channel. Now you can create your own software on your computer that connects with your phone and transform your phone in a full fledged remote control!

p.s. If you happen to find an easier way to get the Bluetooth MAC on Windows 8, please let me know in the comments and I’ll update this post as it seems this really depends on what Bluetooth hardware you have.