Bluetooth UART

I’ve recently been able to get my hands on some Bluetooth UART modules. They’re under the name HC-05/HC-06/HC-07 on websites such as aliexpress, ebay and dealextreme. They’re available for around $8USD each with international shipping included.

If you’re familiar with using a UART/RS-232/TTL communications, you’ll love these little cuties! These devices run off 3.3V and accept TTL serial input with baud rates between 300bps to 115200bps. Not bad if you need some cheap, reliable wireless connections.

With these being bluetooth, not only can they talk to each other, but they can talk to smartphone devices and laptops with ease! They also handle the entire BTstack for you so you dont need to worry about it, and all you get is CRISP , clean communications unlike those AM/FM 433MHz ‘dumb’ modules – where you need to worry about noise, antennae’s etc!

So they all seem great on the outside. And they mostly are, but my main concern about using this devices would be the latency. I wonder how long it takes for a character to be sent from the micro to the HC-05 to another HC-05 and then seen on the remote HC-05 output.

Lets take a quick look!

  • Firstly, using AT Commands that the HC-05 accepts, we configure one as master and one as a slave.
  • Pair the master with the slave
  • Send a character from the master
  • Time the delay until the character appears on the slave’s output.

To begin configuring, we need to set the module’s KEY input to high.

Here are the commands for the master. The units are already shipped as a Slave setup, so no need to re-init the Slave module.

These commands essentially set the module as a Master. Inquire (bluetooth’s lingo for search for devices) and then connect (Link) and pair (PAIR) with the device. The FSAD command is not a random keyboard press – it’s Check with the Device is already paired. Since these devices remember all previously paired devices.

We then remove the KEY input and it becomes floating, it’s okay since the module has an internal pull down resistor.

The unit come out of COMMAND mode goes into DATA. Here are the results when sending characters.

With 2ms intervals its approximately 13.8ms before the character comes out of the Remote/Slave device.

With 2ms intervals its approximately 7ms before the character comes out of the Remote/Slave device.

So you can see that the character latency varies between about 5ms-20ms. It’s a bit laggy if you ask me.

However, there’s more. The Bluetooth radio’s stop talking to each other after around 2 – 3seconds of inactivity. The current then noticeably drops from 15.5mA per BT module to 8mA per BT module. So with 2 BT modules, I found that the current increased around 15mA from idle to transmitting.

You can probably guess that the latency when transmitting successive bytes is going to be a low lower than when it has to transmit from an idle state. And that’s dead right! Check out these HUGE latencies!

42ms

43ms

Due to the nature of it all, I wasn’t able to capture the range of latencies when transmitting from an Idle state. But from the two bytes i did capture, the latency was around 42ms. That’s significant especially if you are dealing with Audio and timing applications.

What’s important here is that the jitter is constant. Jitter is the variance in latency, having a constant, known latency is sometimes better than a lower latency but tends to vary wildly!

So there you have it, some performance parameters for the Bluetooth HC-05 modules!

How you get around these issues is all part of your design!

  • Keep the connection active by sending dummy data
  • Pre send the data so it is buffered on the client side.
  • Burst send data so the connection remains active throughout the entire transmission.

Motivation

What new knowledge, materials, products, devices, processes or services does this aim to produce?

A convenient way to transfer data between devices. No need to worry about wires or the right type of cable. Wireless data transmission has it’s advantages over wired methods.

What eligible activities were undertaken to meet this objective?

1.  An investigation into wireless data transmission techniques.

2.  Performance of bluetooth Serial port profile and HC-05 modules

3. Developing a method of dealing with possible latency issues.

What is the scientific or technological uncertainty this project seek to resolve?

Since wireless communications has significant latency issues, we need to develop or design a method which can deal and handle the significant latency. It may be pre-buffering data or burst data transfer or keeping the connection active so that it never idles (sending dummy data)

What appreciable element of novelty does this project contain?

No wires. Seamless setup and integration between devices.

30 thoughts on “Bluetooth UART

  1. Good article, thanks for doing this analysis. Your article confirmed my worries about using this device for wireless MIDI applications — the latency is a bit too high.

  2. Thank you for this nice test, depending on application, that delay is a bit high.
    I have a question, have you tried having multiple active connections to the master module?
    does it support a piconet for example?

    Thanks

    1. Hi Fadi,

      I haven’t tried multiple connections. Bluetooth works on a pairing system, though I’m not sure if it can be paired with two devices at once!

      Looking at the datasheet, HC-05 it doesn’t seem like it supports multiple connections. It however does support many paired devices, but I think it can only connect to one device at a time.

      An AT+DISC disconnect command needs to be sent.

      1. Hello Adrian
        i understand about the pairing, but the bluetooth may pair with different devices in sametime
        i have project with master and many slaves, but i dont resolve with HC-05 at day
        have any idea?
        thank you

  3. Thank you for the quick reply. It is a little confusing for me because they mention it supports BT2.0 I was hoping they’d have a full implementation.

    I will try to get my hands on a few modules to play with. Thanks again.

  4. I’m also interested how to connect to multiple device, currently I’m able to connect to 2 device “only got 3 HC-05 to play with” from 1 master but only the first connected BT module receive serial data from the master.
    After BT module1 connected I toggle the PIO11 than back to AT mode and can connect to other device.

  5. Hello Adrian,
    Nice article and I quite like your bit relating to latency throughput. Do you know what the latency throughput for music would be from master input to slave output.
    Regards
    Dick

    1. You dont want to do latency sensitive stuff with these… especially when it comes to MIDI… if it were buffered Audio, it’s probably okay since the buffer adds in 200 or so ms anyway.

      Dick, I reckon the latency is the same regardless of who initiated the pairing. You’d have to test it yourself, but at the end of the day, if you’re worried about latency, use the el cheapo 2.4GHz RF modules you can get for like $2.

      Adrian

      1. Hello Adrian,
        The problem is that I need 10 Bluetooth transmitters / receivers running at the same time.
        Thanks
        Dick

  6. Hi!
    I’m about to develop a system of two slave devices (and a pc/android host). However I don’t seem to find a way to change the MAC address of the devices. Do all HC-05 devices have the same address or not? I hope not otherwise I can’t have several devices…

  7. Hi, can anubody tell me how to connect to bluetooth dongle acting as slave with HC-05 as master? I am able to pair it up but not able to connect.

  8. Hello,
    Thanks for the very interesting read. I’m working on a wireless project myself and I’m trying to make the big leap from ‘dumb’ 434/315Mhz RF to BT. And while I have had success connecting simple projects to my Android and computer with the HC-06 BT modules, I haven’t yet been able to connect TWO microcontrollers simultaneously to my Android or computer in order to analyze serial data. Would it be possible to perhaps read the data between a slave/master BT pair of HC-05’s and display their data on my Android? Any help will be appreciated, thanks.

    1. Sounds like you want to have some sort of multi client setup. I think the HC-05 BT device can only be paired and communicating with one other BT module. To connect to another device you need to ‘Disconnect’ and then reconnect with another BT module.

      In a way you’d be making a BT Hub/Message switcher. It’s very possible! Good luck with the project!

  9. Hi Adriangin
    Congratulations by your article
    I have a doubt:
    when I link HC05(master) with HC 06(slave) works fine, but when paired HC05 with Asha 311 (nokia cel) and try send bytes the link bluettoh goes down and up again, I see the HC05 paried led off and on. Do you any idea about ? Did you already pair hc05 with cel phone ?
    thanks

    1. Hi Paulo,

      Interesting, yes I paired it with my Android Phone and used the Bluetooth Serial Port app. Make sure the distance is within range. Also make sure that that cellphone and HC05 is not trying to pair with something else.

      The Bluetooth HC05 modules when transmitting use a lot of energy, 50mA bursts. Are the power supplies of both Cellphone and HC05 have a solid smooth power supply.

      Did you try with the cellphone being the master?

  10. Hi Adriangin,
    Thanks for answer
    I checked everithihg you sad and its OK.
    I tried with cellphone being master, in this case cell and HC05 are paired but don´t start conection and I can´t send AT commands to HC05 to link then.
    The asha 311 doesn´t run android.I try with another cell nokia(classic 310) and the result is the exactly the same.
    My project is to send SMS using the cell’s AT commands,I did this using a Dell Notebook(bluetooth master) and Asha 311(bluetooth slave).
    I changed the HC05 class os service,I used the same a Dell Notebook,but doesn´t work too.
    Maybe there is a bug in HC05 firmware…

  11. Hi Adriangin
    I was wrong I can send AT commands when HC05 is in the slave mode,I try using HC05 slave anda cell phone master, but hapened the same thing again.

  12. my bluetooth module RKI-1545 is paired with PC or also with mobile, but when i want to send data to it via PC or mobile, it does not show in option window to send data and also when i try to send commands through Hecules or other software, it does not give any response. whats the problem i don’t understand please solve it and if any code regarding to this module (inbuilt in it) and interfacing code with controller , please share it. thanks alot.

  13. Hi,
    interesting practical work on actual latency. You may be able to answer another question for me, have you tried pushing the data rates up, and if so, what was the maximum on air data rate you could achieve. For example, say I wanted to send 40 bytes in 1 or 2 mSec, is this doable. You may have to pump the UART link at the highest baud rate, and use handshaking perhaps.

  14. Hi, So nice article and awesome work done by you.

    I am alos having the same module HC-05, it gets configured correctly and paired with my mobile phone. But when I issue AT+LINk=, Command , It did not reply and Start Inquiring again.

    Even I have the address already paired with my mobile.

    Also, I want to Transmit Audio using this module, Is I need to do ADC and then need to send data serially? or I need to change the profile? or else?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s