How to set up a BTM 222 and connect it to Android

Because I had some problems to get it working I will show you how to connect a BTM222 bluetooth module (or any similar device) to an Android mobile phone.

1. What you need

  • obviously a Bluetooth Module
  • something to power the module and communicate with it (I use Arduino)
  • a level-shifter (I use the 74HC4050N but it can be done with 2 resistors)
  • an Android mobile phone

2. Setting up the Bluetooth module

At first have a look at the Datasheet. To use the BTM222 you need to hook up 11 pins. 6 of them should have the GND signal. It is very important to tie every single one of the GND-pads to the GND-signal because in the mysterious world of high frequency applications devices don't work when they are not properly grounded. Also remember that the BTM222 needs a supply voltage of 3.3 V when hooking up the module. Of the three remaining pads of the module there are two used for UART communication and one for the antenna. If you check the antenna against GND with a circuit indicator don't wonder if there is a connection - but it works. I found it very hard to solder wires to the BTM222. The pads of the devices are very small and you need a calm hand to get it done. I don't have a calm hand. Thats why my device looks like this: test

In my case I have an Arduino which I want to connect to the bluetooth module. So this is the schematic for my setup. Please remember that you can use a voltage divider instead of the 74HC4050N to get the conversion between 5 V and 3.3V for the UART done.

  Please check if you really have connected "UART Data Output" (Pin 27) to the TX input of the Arduino board (so its TX -> TX).

This is how my wiring looks like:

3. Use the UART to connect to the module

Now its time to communicate with the BTM222. Make sure you Arduino does not use the UART  interface (you can burn the "Blink" demo on the device or just remove the chip of the board). Now connect your PC to the Arduino Board. Use 19200 Baud, 8 data bits, no flow control, no parity and 1 stop bit for the connection. Since I am running Ubuntu it is very simple to initiate a connection.

screen /dev/ttyUSB0 19200

You can also use your Arduino IDE serial console window. When you do that make sure to send a carriage return after each command. If  the connection was established successfully the BTM222 will echo all chars you send to it. Send "ATI1" to get some information of the device.

4. Connecting the module to the Android device

At first you need to pair the mobile phone with the BTM222. Just activate your bluetooth and search for devices. The default name of the module ist "Serial Adapter". If you don't find it check your wiring. Don't forget the antenna or to set all grounds. Use the pin "1234" for pairing. Now it is time to write the Android App which communicates with the devices. Google created a very nice example application called "Bluetooth Chat". You will find a download of the Eclipse project at the bottom of the article if you do not want to search for the above mentioned code and create a project by yourself. So I started an eclipse android project with the "Bluetooth Chat" demo app code by Google. The application can list bluetooth devices, connect to them, run a server socket and send and recieve strings. The problem ist that it will only work for other mobiles devices but not for the BTM222 which only supports the bluetooth SPP profile. There is only one line of code to change to get a communication between your mobile and the BTM 222 working. Just replace the UUID definition in the file ""  in line 49 with the UUID "00001101-0000-1000-8000-00805F9B34FB". So it looks like this in the end:

// Unique UUID for this application
private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34F");

Thats it. Now you should be able to connect your BTM222 via the menu and send messages. To do it, execute the App, press the Menu button and then click "Connect a device". The rest is self explaining.

This is how it looks in the serial console of arduino and on the Android device:

To come to the end here you find the download of the eclipse project: BluetoothChat (100 kb .zip) An apk is included if you do not want to compile the project again. Have fun.


Jonas wrote on

Thank you really, that's exactly, what I need!

ozoderm wrote on

**ozoderm...** Thanks for taking the time to debate this, I feel strongly about it and love studying extra on this topic. If possible, as you acquire expertise, would you mind updating your blog with further information? It is extremely useful for me....

couzty wrote on

What antenna should i use ?

Ben wrote on

Hi! Thanks for your question. There are many factors which affect the performance of an antenna but in general you can remember this: The optimal antenna is a piece of wire with the length of 1/2 * λ (wavelength). So for Bluetooth you have a radio frequency from 2402 to 2480 MHz. You calculate the wavelength like this: λ = c/f (c is speed of light, f is your frequency) I assumed a frequency of 2450 MHz for calculation. So you have a wavelength of approximately 12,4 cm. Take the half of it (6,2cm) and you will probably get a good antenna. But remember that many other effects influence the antenna (like material of wire) especially in these high frequency application.

Mihai wrote on

Hello, I have a question about the antenna and ground pins of the btm222 module (pins number 37 and 38 respectively). I soldered the module onto a PCB and when I checked for unintended connections I found that those two pins are connected. I don't know whether they are connected internally through an inductor or something, or maybe I've made some error in my PCB which I can't seem to find. So my question is this: can you check if those two pins are connected internally with a multimeter on your board (which is working properly), because I don't want to risk damaging my device if I have made some mistake. Thank you in advance

Ben wrote on

Hi. They are also connected on my board. Very strange but it works. Greetings

Mihai wrote on

Thank you very much for your help. I managed to get my btm222 working. I've sent characters through a serial to usb converter to the microcontroller, which sent those characters back to the PC through the btm222 paired with a bluetooth dongle attached to the PC. Tip: If you ever need a high speed level converter look for the sn74cbtd series form texas instruments, it can convert between many voltage levels, it's pretty cheap, but it's not designed to drive loads.

Tilman wrote on

Hey tolles Projekt! habe sowas ähnliches vor ;) hat mir schon ein bisschen weitergeholfen ;) habe vor meine zimmerbeleuchtung über ein Android app, einen Microcontroller, Relais und den BTM22 zu steuern. Dass XML Layout des Apps ist schon fertig mit Checkboxen zum an und ausmachen der lichter. Doch ich kenne mich mit Java kein bisschen aus und hoffe du könntest mir ein paar Tipps geben wie ich dass ganze programmieren könnte. Außerdem weiß ich nicht welchen Microcontoller ich benützen soll, und hoffe daher dass du vielleicht schon Erfahrungen mit welchen gemacht hast und mir einen nennen kannst. Mfg Tilman

Ben wrote on

Hallo, danke für deinen Kommentar. Witzigerweise haben wir genau gestern auf einer Messe in München genau das präsentiert, was du da vorhast. Wir haben einen ATmega 8 mit einem selbstgebauten Relaiscontroller verwendet. Ich werde in den nächsten Tagen über die Konstruktion einen Artikel schreiben, geht denn dein BTM222 und funktioniert die Kommunikation zu deinem Android-Gerät schon? Grüße

Zdzisław wrote on

Bardzo dziękuję autorowi za umieszczenie cennych informacji, zwłaszcza że dopiero zaczynam zabawę z Androidem i w końcu mogę wykorzystać swoje moduły Bluetooth. [Thank you in Polish :) ]

Andreas wrote on

hi suppppper seite ! ist die version BluetoothChat von deiner Seite schon für BTM-222 gefixt ? Danke

Ben wrote on

Ja sollte sie sein.

Martin wrote on

Nope, mir hat's nichts gebracht. Ich finde den BTM222 auch ziemlich schlecht gemacht bzw. ein eindeutiges Datasheet vermisse ich (sogar im Internet) ebenfalls. Ich habe nur welche gefunden, bei denen die Grounds gaaaanz anders belegt sind, als bei dir. Ich check nicht mal ob ich das Teil von unten oder oben löten muss. Trotzdem danke. Martin

Leave Comment: