Wednesday, May 19, 2010

Android & Bluetooth module.




Android phone is becoming more popular, most of the android phones equipped with Bluetooth. Just wonder how we can make use of the powerful android phone to interact with MCU like Atmel AVR, PIC or even Arduino. I think that more interesting projects can be done with the bluetooth connectivity to Android:)

After some studies, I found out that in Android 2.0, Google enhanced the Bluetooth API and come with an Bluetooth Chat sample for communicating devices with RFCOMM (SPP profile). So I did a try and it really works very well!



Let's try it out! The Bluetooth module that I used is a very tiny one with PCB antenna, it can control device over 10 meters at least, good enough for small project:) It is programmed to use as RFCOMM, so it can act as a wireless UART, good fit for all the MCU! With only 4 wires, 3.3v/Gnd/Tx/Rx, no programming needed, you can directly connect the module to your MCU UART.


Here is my demonstration video:


For the bluetooth sample code, you can find it in the Android SDK or here.

42 comments:

senikk said...

What is the name of this Bluetooth module?

Bitartist said...

I don't know, just a CSR chipset module.

senikk said...

I think I found it at http://www.mdfly.com/index.php?main_page=product_info&products_id=63 seems to look like it. Good to know its working with Android :-)

Anonymous said...

Thanks so much. I've been looking for an affordable bluetooth module and this looks like it will work.

Radu Motisan said...

One of my last projects was a 4x4 differential drone, built from scratch, remotely controlled via Bluetooth using an Android smartphone and a bluetooth module like the one in this article.
Schematics / demo video here: http://www.pocketmagic.net/?p=1398
Besides ultrasonic sensors, the robot is about to be equipped with a homemade geiger counter sensor to detect "exotic" environment parameters
like the dangerous ionizing radiation. There are quite a few possibilities since the robot has an ATmega microcontroller that can easily
support additional sensors.
The data is sent back to the Android device, via bluetooth.

Bitartist said...

Hey Radu, that's super cool!

ZAZ said...

That demo was really interesting. I think I spotted the bluetooth module at http://www.zbaus.com/products.php?id=50

Anonymous said...

Bitartist, did you change anything in BluetoothChat to get it connect to the BT module? I tried and could pair, but when trying to connect I got "couldn't connect" message.
According to the original BTChat code it requires the other part to register an SDP server with a long UUID. It would be fine if you could publish the few lines that did the conection. I have a really cool project waiting for a BT connection in my lab.

Bitartist said...

Yes, using BluetoothChat example, you may need to change the UUID in order to pair with this module. Do you take a look of the source code here:
http://www.pocketmagic.net/?p=1398

I don't have the code on my laptop now, let me know if you still need help, I can post my UUID here.

Anonymous said...

Hi again,

I got it working with only one change. In the file BluetoothChatService.java I changed from:
private static final UUID MY_UUID = UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a66");
to:
private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

Then I connected my phone and used Run As Android Application.

Than you for telling us about this good and cheap module!

Regards,
Dag

ian87 said...

i want to send some character from pc to android phone. do you have any source code of bluetooth chat for pc? , while android use bluetoothchatsample from android sdk

does uuid need to be changed from its original value?

Bitartist said...

right, You can check the UUID as mentioned in the comment from Dag!

ian87 said...

do you know how to sent command from MCU to bluetooth chipset for sending or receiving data? does MCU support AT command or something?

Bitartist said...

The UUID would tell your computer that this bluetooth module is a serial UART adapter, so there is no AT command necessary to just sending/receiving data to/from MCU.

But MCU can send AT commands to control the bluetooth module, like setting the bluetooth password, bluetooth's name.

Ebbekaer said...

How did you find the UUID for exactly that module.

I am using a module called LM 400, and I don't know how to obtain the UUID. Hope your able to help me.

Bitartist said...

Did you try to use the UUID mention above? I think it is a common UUID for UART bluetooth adapter.

Ebbekaer said...

Yes I allready tried that. But there ain't any response from the module. I think I'll try with the module you mentioned. Thanks allot for the quick respone.

ian87 said...

do you know how to connecting android to two bluetooth spp at the same tima?

Onuray said...

@Ebbekaer Did you find a solution for LM400 UUID problem?

Anonymous said...

How I can use those bluetooth transceiver to power 2 relays with android?

Plesase help me to
jigasvicar@gmail.com

chintalapudi said...

what is the name of bluetooth module?
which microcontroller you connected with bluetooth?

chintalapudi said...

what is the name of bluetooth module?
which microcontroller you connected with bluetooth?

chintalapudi said...

Is any software code needed for interfacing of bletooth module with microcontroller

Bitartist said...

for the MCU side, you treat the bluetooth module as modern UART interface, so no special codes needed.

chintalapudi said...

WHICH BLUETOOTH MODULE WILL SUPPORT THE ARM9 MICROCONTROLLER?
can you tell the bluetooth module number?

chintalapudi said...

what is CSR chipset module

Anonymous said...

Pair code is 0000 IIRC

chintalapudi said...

i am using lpc3250 arm9 micro controller.which bluetooth module is suitable for this micro controller?
for sending data from bluetooth module to android any code is needed?

chintalapudi said...

Help to me
which bluetooth module is suitable for android mobile?

Bitartist said...

any bluetooth with pre-build firmware operate as a UART2Bluetooth (SPP profile) will be cool, so it is very easy to interface to any micro-controller with UART. For Android side, you have to write code for paring the bluetooth devices with PIN code, and then just open a output and write bytes to the stream, really easy to do it!

chintalapudi said...

which code is needed for android java or c++?.
can i use arf32 bluetooth module?

chintalapudi said...

PIN Code means

Bitartist said...

Android - uses JAVA

PIN code means the Password for pairing 2 bluetooth devices, please check out the comment aboves, someone mentioned a bluetooth may work for you. Also there is android sample code.

LuisMu said...

What If...

I would Like to send a number from my uC to my android mobile phone,

Before connecting the Tx of my uC to the Rx of my Bluetooth Module

(here comes the question)

I just only have to send the number via Tx of the uC and the Bluetooth module will transmit that number

LuisMu said...

I need to send a number from my uC to an android app.

I want to know if I have to connect my uC Tx (UART TX) to the Bluetooth Module Rx,then how can I send the number (is there like an AT command?)

Please Help Me

LuisMu said...

Master Or Slave..

If need to send data from my uC to my phone the SKU is Master and when i want to receive data from my phone my SKU is Slave?..Am I Right?, is there a way to switch between master or slave by code?..

LuisMu said...

Master Or Slave..

If need to send data from my uC to my phone the SKU is Master and when i want to receive data from my phone my SKU is Slave?..Am I Right?, is there a way to switch between master or slave by code?..

Bitartist said...

Hi, Concerning the AT command, Let's check out this connection:

Android <-> Bluetooth <-> [ Bluetooth 2 Serial Module] <-> UART <-> MCU

I only control the bluetooth module in MCU side, like setting PIN password via AT command.

LuisMu said...

so you configure the Bluetooth module as a Slave?, or it doesn´t matter...My question is if the Bluetooth module can transmit a receive data only by sending a string from any side (Mobile or MCU), for example:
I send a number from the mobile via bluetooth Can I receive that string in a variable in the MCU, or I send a number from MCU (UART tx) can I receive that number in the Mobile.

Thks in advance

Bitartist said...

Yes, you can do so. You can see in the youtube, I send a character from the phone to the PC (via bluetooth module->Uart), I didn't test sending from PC, but I think it works the same.

Roni Andria said...

the module name is RF-BT0417C

Roni Andria said...

the module name is RF-BT0417C