Using the HC-06 Bluetooth Module


After my first post using a Bluetooth module, things have evolved a bit. The challenge with these Bluetooth modules is: they look the same, but having different firmware. I did not fully realize that until I have ordered another bluetooth module from dx.com:

DX.com Bluetooth Module (HC-06)

DX.com Bluetooth Module (HC-06)

That module comes already on a carrier, so I assumed I can use the same driver as for my other module. I was wrong :-(.

HC-05 or HC-06

My earlier module which I received from another source (without an adapter, see this post) has a different firmware on it, known as HC-05, while my DX.com module has a HC-06 firmware. To be clear: the modules are the same, but the software/firmware on it is different, and the firmware uses the pins differently too :-(

HC-06 and HC-05 (Source Wavesen Data Sheet)

HC-06 and HC-05 (Source Wavesen Data Sheet)

:idea: Check out this post which explains how to re-program the firmware of the device with firmware programming adapter: http://byron76.blogspot.ch/2011/09/hc05-firmware.html

The HC-05 has the ‘full’ firmware on it: many AT commands, and can be both master and slave module. The HC-06 firmware on the other hand only can be a slave device, with very limited AT commands.

Or in other words:

  • The HC-05 module can build a connection to other modules. E.g. a Robot being a master and connecting to slave bluetooth module. Or in slave mode to make a wireless bridge to a notebook.
  • The HC-06 module only can be a slave. This makes it only useful for say connecting a notebook as a master to a robot with a slave module e.g. for a wireless serial bridge.

For most use cases the HC-06 is enough, as typically I want to have a wireless UART connection to my devices from my notebook.

JY-MCU V1.5 Module

Below is an image of the JY-MCU HC-06 (JY-MCU V1.5) module. The module came with a 4-pin header, and I have added the pins for STATE and KEY, and removed the plastic around the module to get access to the pins:

HC06 Top Side

HC-06 Top Side

Pins

On the bottom side there are labels for the signal direction and voltage levels:

JY-MCU BT_BOARD V1.05 Bottom Side

JY-MCU BT_BOARD V1.05 Bottom Side

  • KEY: according to the data sheet, I need to pull-up this pin while power-on-reset of the module to enforce AT mode. I have not been able to verify this yet. I have been told that some modules have this pin not connected at all?
  • VCC is indicated in the range of 3.6V-6V. The module worked for me both with 3.3V and 5V.
  • GND: Ground
  • TXD: serial output of the module, to be connected to RX of the microcontroller. Note that this signal is using 3.3V logic level
  • RXD: serial input of the module, to be connected to the TX of the microcontroller. Note that this signal is using 3.3V logic levels.
  • STATE: connected to LED2 (Pin32) of the module, but no meaning? At least on my module the pin was always low, regardless if paired or not.

Different AT commands

On the HC-05 module, I send “AT\r\n” to the device, and then it responds with “OK\r\n”.

But on the HC-06, the protocol is different :-( I need to send “AT” (without the new-line characters), and I receive “OK” (without the new-line characters).

The logic analyzer shows this behaviour too: AT command sent to the device:

AT Command sent to Device

AT Command sent to Device

OK response from the device with no “\r\n” at the end:

OK Response from the Device

OK Response from the Device

The missing “\r\n” is present for all commands of the HC-06 firmware. As as this is not enough, there are very few command possible. The table below shows all the HC-06 firmware commands with the response:

Command Response Comment
AT OK Used to verify communication
AT+VERSION OKlinvorV1.8 The firmware version (version might depend on firmware)
AT+NAMExyz OKsetname Sets the module name to “xyz”
AT+PIN1234 OKsetPIN Sets the module PIN to 1234
AT+BAUD1 OK1200 Sets the baud rate to 1200
AT+BAUD2 OK2400 Sets the baud rate to 2400
AT+BAUD3 OK4800 Sets the baud rate to 4800
AT+BAUD4 OK9600 Sets the baud rate to 9600
AT+BAUD5 OK19200 Sets the baud rate to 19200
AT+BAUD6 OK38400 Sets the baud rate to 38400
AT+BAUD7 OK57600 Sets the baud rate to 57600
AT+BAUD8 OK115200 Sets the baud rate to 115200
AT+BAUD9 OK230400 Sets the baud rate to 230400
AT+BAUDA OK460800 Sets the baud rate to 460800
AT+BAUDB OK921600 Sets the baud rate to 921600
AT+BAUDC OK1382400 Sets the baud rate to 1382400

That’s it.

Firmware Timing

As this is not enough, my driver did not work even with the new commands implemented. The HC-05 firmware as sending a response back in less than 300 ms, while the HC-06 firmware needs more than 500 ms until there is a response:

Delay between Command and Response

Delay between Command and Response

So for this I had to introduce a user configurable delay in the component.

Processor Expert Component

With this knowledge, the Processor Expert Bluetooth component has been updated to support both the HC-05 and HC-06 firmware:

Bluetooth Component Supporting HC-05 and HC-06

Bluetooth Component Supporting HC-05 and HC-06

  • Firmware to select between HC-05 and HC-06
  • Configurable Response Time if the module needs longer for commands
  • Optional State and CMD pins

If the HC-05 firmware is selected, then the component automatically disables the functionality methods not present/supported in the firmware (grayed out methods):

Bluetooth Module Methods

Bluetooth Module Methods

Command Line Interface

The Processor Expert component features an optional command line interface:

HC-06 Shell Commands

HC-06 Shell Commands

With this, I can change the pairing pin, device name or baud, beside of sending AT commands or sending a string over the wireless bridge.

:idea: Changing the pairing/name/baud will be effective after resetting the device. Keep in mind if you change the baud, this will change the baud as well between the module and the microcontroller.

The ‘status’ command issues an AT command to the device to see if it responds, plus shows the firmware version:

BT1 Status with Module Firmware

BT1 Status with Module Firmware

:!: Status and AT commands can only be used if the device is not paired yet (means: while the red LED is blinking).

Connecting to the Bluetooth Module

The Bluetooth module runs the SPP (Serial Protocol over Bluetooth) protocol. So any device supporting SPP can connect to it. On a PC this looks like a virtual COM port. I show here the steps for Windows (running Windows 7).

:!: It seems that Apple (iPhone, iPAD, etc) does *not* support SPP, so connecting with an iPhone is not possible.  Android (which I did not try) should work, or any PC machine with Bluetooth.

Before connecting, make sure the module is powered and ready to pair. The red LED on the module indicates the status:

  • blinking: ready to pair
  • steady on: paired

From the Device Manager, select ‘Add a Device':

Device Manager with Add a Device

Device Manager with Add a Device

Then the new device should show up:

Add a device Dialog

Add a device Dialog

:idea: the name of the device shows here for me ‘blue1′, as I have named it as such. But it might show up for you as ‘linvor’ (default) or ‘other’.

Select the device and press ‘Next’.  In the next dialog select ‘Enter the device’s pairing code':

Enter the device's paring code

Enter the device’s paring code

The default pairing code is 1234:

Enter the pairing code for the device

Enter the pairing code for the device

Pressing next, and device drivers will be installed:

Installing device drivers

Installing device drivers

Then the device is ready to use:

Your Device is ready to use

Your Device is ready to use

And the confirmation dialog shows up:

This device has been successfully added to this computer

This device has been successfully added to this computer

COM Port used by Device

Checking the properties on the newly added device shows that it supports SPP. And it shows the virtual COM port used:

Device Services

Device Services

:!: Note that if I check the COM ports in the device manager, then I see that actually two COM ports have been added. Only the one shown above with the SPP protocol will work. It is unclear to me why there is a second port?

Connecting to the Wireless Bluetooth Bridge

Using that COM port shown for the SPP service, I can connect with a terminal program on the host PC to my board. Basically this gives me a wireless bridge over Bluetooth to my board. So from my PC I can open a terminal window and type in some commands, which are parsed by the Shell on the FRDM board, and it responds back to the terminal on the PC:

Wireless Bluetooth Bridge Connection

Wireless Bluetooth Bridge Connection

:!: Make sure you use the COM port used for the SPP service, and that it matches the baud settings of the communication between the microcontroller and the Bluetooth module. I’m using above the default of 9600 baud. It is possible to change/increase the baud as explained above, as 9600 is not very fast. Only be sure that you not exceed the baud to a value which cannot be handled by your PC. It should work ok up to a baud of 115200.

Once connected, the red LED on the Bluetooth module is always on.

Pairing LED

Pairing LED

While connected, the module is in ‘transparent’ mode, and does not accept AT commands. Below is an example where I try to send an AT command from the microcontroller while the Bluetooth module is connected to the host PC:

Trying to send AT commands while connected to PC

Trying to send AT commands from the microcontroller while connected to PC

Instead, what I send to the UART ends up transparently on the host PC:

Bluetooth Module in Transparent Mode

Bluetooth Module in Transparent Mode

Wireless Bridge

Everything I send to the virtual COM port ends up on the Bluetooth module, which then sends the commands to the microcontroller using the RX and TX connection between the microcontroller and the module. With this, it is very easy to send/receive commands using the Processor Expert Shell component, and the implementation are just a few lines:

/**
 * \file
 * \brief This is the implementation module for the shell
 * \author Erich Styger
 *
 * This interface file is used for a console and terminal.
 * That way we can interact with the target and change settings using a shell implementation.
 */

#include "Shell.h"
#include "CLS1.h"
#include "LEDR.h"
#include "LEDG.h"
#include "LEDB.h"
#include "BT1.h"

static const CLS1_ParseCommandCallback CmdParserTable[] =
{
  CLS1_ParseCommand,
#if LEDR_PARSE_COMMAND_ENABLED
  LEDR_ParseCommand,
#endif
#if LEDG_PARSE_COMMAND_ENABLED
  LEDG_ParseCommand,
#endif
#if LEDB_PARSE_COMMAND_ENABLED
  LEDB_ParseCommand,
#endif
#if BT1_PARSE_COMMAND_ENABLED
  BT1_ParseCommand,
#endif
  NULL /* sentinel */
};

/* Bluetooth stdio */
static CLS1_ConstStdIOType BT_stdio = {
  (CLS1_StdIO_In_FctType)BT1_StdIOReadChar, /* stdin */
  (CLS1_StdIO_OutErr_FctType)BT1_StdIOSendChar, /* stdout */
  (CLS1_StdIO_OutErr_FctType)BT1_StdIOSendChar, /* stderr */
  BT1_StdIOKeyPressed /* if input is not empty */
};

void SHELL_Run(void) {
  unsigned char buf[32];
  unsigned char bTbuf[32];

  buf[0]='\0';
  bTbuf[0]='\0';
  CLS1_ParseWithCommandTable((unsigned char*)CLS1_CMD_HELP, CLS1_GetStdio(), CmdParserTable);
  for(;;) {
    (void)CLS1_ReadAndParseWithCommandTable(buf, sizeof(buf), CLS1_GetStdio(), CmdParserTable);
    (void)CLS1_ReadAndParseWithCommandTable(bTbuf, sizeof(bTbuf), &BT_stdio, CmdParserTable);
  }
}

Unbinding and Trouble Shooting

In case there are issues with connecting to the module, it is necessary to unbind and re-bind (connect) to the module. It happened to me sometimes I’m able to connect once, but then not any more. In that case the following steps help:

  1. Close any terminal program potentially connected to the Bluetooth virtual COM port.
  2. Unpower the Bluetooth module so it is not visible any more to the PC.
  3. Right click on the device in the Windows Device manager (or Devices and Printer group) and select ‘Remove Device':

    Unbinding Bluetooth Device

    Unbinding Bluetooth Device

  4. Re-power the module: the red LED shall be blinking as not connected.
  5. Search for the device in the device manager (as above), and connect again to the device with a pairing pin.
  6. Connect to the module using the COM port specified for the SPP service.

That way I was always able to recover connection to my module. See as well this post which helped me to solve my problem.

Sources

All the component sources discussed are available on GitHub. Additionally, the FRDM-KL25Z Bluetooth example project has been updated to support both the HC-05 and HC-06 modules.

Happy Bluetoothing :-)

About these ads

113 thoughts on “Using the HC-06 Bluetooth Module

  1. Hi Erich,

    Maybe you can talk about 24L01+ and Ethernet communications? Do you have this Beans?

    Thanks,
    Alex Vecchio
    Brasil

    Like

    • Hi Alex,
      do you mean the 24L01 from Nordic Semiconductor? No, I do not have beans for this one. I do have an Ethernet Shield, but had not much time to work on it. It will be one of the next things for sure.

      Like

      • Ouch… Fastest answer i`ve ever seen!

        Yes. I am talking about the Nordic Semiconductor 24L01. Maybe this can be a really cheap solution to control a freedom board from another freedom board wirelessly.

        Other thing is to control a freedom board through the intranet.

        I am waiting for your new posts. Thanks for this excellent job you are doing.

        Like

      • Sometimes I never sleep :-)
        yes, that Nordic module is really interesting, altough I do not have one (yet). The HC-06 Bluetooth one (or the HC05) are really cheap: less then $10, and at least the HC-05 one can be used to control another FRDM board.

        Like

      • Hi Erich,
        I think we can control a lot of Freedom boards simultaneously with the 24L01+ but we cannot do this with bluetooth devices. Right?

        Like

      • Yes, doing this with the HC-05 probably is not easily possible. For the use case you describe I’m using an IEEE802.15.4 module which can build up star or mesh networks.

        Like

      • Hi Tom,
        they are *increcibly* cheap, thanks for the link. I guess will order a few to try it out. Once concern I have: the derivers I have seen are all GPL2 which is a concern. Have you seen (or using) LGPL or BSD style drivers or stacks? Otherwise it looks I need to develop everything from ground up which is not ideal.

        Like

      • Hi Tom,
        yes, I already found that library, but it is GPL2 as well, so not very usable for anything than true hobby projects.
        Anyway, I have ordered a handful of modules, and whenever I find time, I’ll start writing a BSD style driver. Contributions are always welcome :-)
        Erich

        Like

  2. Hi Erich
    I got some experience with one of these modules on a project. I think they are all more or less the same, but for the firmware (as you point out). The circuit is a CSR reference design. The CSR chip is based around a core architecture developed at Cambridge university. You can get the development tools from their web site (easy to find), and develop your own firmware for the module. I never got so far as to download all that, not sure about what the cost is etc. I would guess there is a reference design for the firmware as well, which is what all of these different firmware versions would be based upon.

    Like

  3. Hi, Erich!
    You have done a very good job by creating a component like this.
    Two weeks ago, I have bought a BC04 bluetooth module from ElectroDragon (which is a little bit different from HC05 or HC06 as firmware) and this thing involved, for me, some changes into your component source code.
    After implementing all changes, I would like to add a new BC04 firmware to
    “Bluetooth_EBGT” component project. The problem with that is caused by the fact that I cannot import very well your project, because when I try to edit the source code of a method I get the following error : “Source Code missing in default driver. It could be present in a prg.”.
    Any help would be greatly appreciated.
    Thank you.

    Like

    • Hi Surdeanu,
      I don’t think I have seen that error myself, so not sure what is causing this? Maybe you could email me your changes/source code and I’m happy to have it incorporated into the Processor Expert component. Send it to the email I have listed at the end of the ‘About’ page of this blog.
      Thanks for contributing to that project!

      Like

  4. Pingback: Yet another Bluetooth Firmware: BC04 | MCU on Eclipse

  5. Pingback: Tutorial: Ultra Low Cost 2.4 GHz Wireless Transceiver with the FRDM Board | MCU on Eclipse

  6. Pingback: Mini Sumo Robot Competition running with FRDM-KL25Z | MCU on Eclipse

  7. Pingback: Zumo Robot Chassis PCB arrived! | MCU on Eclipse

  8. Hi Erich,
    thx a lot for showing the differences between HC-05 and HC-06 module !
    I happened to get my HC-06 work with a Trust USB-BT dongle and WinXP32.
    Just shortcut the Tx/Rx on the module and used Comport Toolkit as a terminal to see the looped back chars.
    If longer blocks of data are sent the delay decreases to somewhat 90msecs. But that’s all for the good news.

    The HC-06 does not establish working mode (steady LED) when I use my lenovo T500 with win7-64. I can connect the device, send pairing pin and two successive COMxy ports are shown in device manager. But the first where the SPP is assigned to can not be accessed by my terminal programs and the LED on the HC-06 keeps flashing indicating AT mode :(.
    Same situation with my Galaxy-S2 GT-i9100, it finds it, pairing pin input but HC-06 stays in AT mode.

    Has anyone an idea or solution about that ???

    All the best, Tom.

    Like

    • Hi Tom,
      I had some problems with another notebook, where I was not able to establish connection: here it helped to re-install the drivers on the notebook as explained in the article.
      On another notebook I used a cheap bluetooth dongle (under Windows7 64bit). I never got it working to connect to the bluetooth module, while it worked on another machine with XP.
      So I just make the guess that there might be a similar problem in your case, but with the internal bluetooth module? It might be worthwile to try an external bluetooth module?

      Like

      • Hi Erich,
        Thanks for your comments.
        With Android I’ve got it work. After inputting the pairing sequence on the phone the HC06 stays in AT mode but if my app runs it connects and switches to SPP mode :).
        I’ll try to reinstall the win7 BT drivers and see what will happen…
        Good luck, Tom.

        Like

      • Hmm, yes, this is true on Windows too: only if I connect to the COM port with my terminal, it changes from AT to transparent mode. I thought I had mentioned this, but probably not bold enough…..
        So here again: the connection only happens if actually connected on the host to the virtual COM Port :-)

        Like

      • yepp,

        But with my win7-64 I see both virtual COM ports created by the BT in the device manager but can not access the lower numbered one with any terminal program…
        This works with XP-32.

        Like

  9. Pingback: Zumo Robot assembled | MCU on Eclipse

  10. I have a problem when I compile the file bth1.h gives me an error on line 331: byte BT1_ParseCommand (const unsigned char * cmd, bool * handled, CLS1_StdIOType const * io);

    Like

    • Hi Diego,
      what kind of error message do you get? I tried again my example on GitHub and it works fine for me. Have you loaded the latest Processor Expert components from GitHub too? It looks like it is an issue with the shell, and maybe you are using an older version of the code/components?

      Erich

      Like

      • fix the error, I wanted to ask you for help with the command line interface, as you do to get the settings? because it recognizes the port but when writing AT commands nothing happens. If you could help me or pass me your mail. Thanks in advance.

        Like

      • If nothing happens if you write AT commands, this typically means that the Bluetooth module already has been connected to the PC host. If the module is connected, then the LED is on (compared to be in blinking mode if not paired, where it accepts AT commands). Another reason for the AT commands not working is a wrong UART baud configuration. By default the modules operate with 9600 baud. Please verify with a logic analyzer if that baud is used. I hope this helps?

        Like

  11. HI
    i am presently working on a project that requires microcontroller to microcontroller wireless communication. i was wondering if we could do this using 2 BLUETOOTH hc06 or hc05, by simply interfacing 1 of the modules with the transmitting microcontroller and interfacing the second with the receiving microcontroller.
    i have been able to pair my HC06 module with laptop and mobile. when i use a laptop on 1 end i simply have an option to enter the pairing code into my laptop but while working with 2 bluetooth modules the problem i am facing is how do i enter the pairing code.

    Like

  12. Hello,
    I have HC-06, and I need to change data bits 8 to 7 (required for my application). I cant find any info about setting data bits. Maybe you know something about that.. is it possible?

    Like

  13. hello, hey when I run the program the terminal gives me this

      ————————————————– ————
    My Project Name
    ————————————————– ————
    CLS1; Group of CLS1 commands
       help | status; Print status information or help
    CMD>
     

    AT write the codes and nothing happens

    Like

    • Hi Diego,
      are you using my example from GitHub? From the shell output it looks like you have not added the command line interface to the Bluetooth module, as it does not show up with help. Be aware that if the HC-06 LED is not blinking, the module already connected to a host, and it does not accept any AT commands (the AT commands are sent to the host).

      Like

  14. Hi,
    That was great, but I have a question, Can my PC connect to more than one module.
    I want to create an app in the PC that monitor many bluetooth modules at the same time.

    Is that possible?

    Thanks

    Like

  15. I’ll immediately snatch your rss feed as I can not to find your e-mail
    subscription hyperlink or e-newsletter service. Do you’ve
    any? Kindly let me recognize in order that I could subscribe.
    Thanks.

    Like

  16. Hi Erich,

    Thanks for sharing the result with such great detail.
    I’m planning to use this bluetooth module with Arduino Pro Mini 3.3V model – in this case, the logic level would be needless, right?

    Best reagards,
    Jami

    Like

    • Hi Jami,
      yes, the module operates with 3.3V logic levels. You just need to be careful about the supply voltage. My modules say 3.6V-6V, but I was able to use them with 3.3V without problems. That might depend on the module.

      Erich

      Like

      • Hi Erich,

        Thanks for the reply.
        I still haven’t got HC-06 but quickly tested an HC-05 (also marked with 3.6V-6V) with the Arduino. They both are well integrated.

        Jami

        Like

  17. Excellent site, thanks, lots of good info,
    I wonder if you can assist with my little challenge?
    My project is to provide a wireless connection between a racing yacht’s Nav computer (a B&G Hercules Performance Unit) and my Android phone using my HT-06 (Ver 1.06).
    To build up some expertise, I’m practicing at home by trying to get the connection going by connecting the HT-06 to my Garmin GPS72 handheld GPS receiver. I’m bluetoothing to the HT-06 with my laptop and a cheap USB dongle using a good terminal emulator (Reflection).

    When connecting the GPS72 to the laptop with a cable, it comes in on USB at COM04 and my terminal emulator happily talks to it at 4800 8/None.

    However, when trying to get the laptop to talk to the GPS72 with the HT-05, I get the connectionup and running (solid led) and I’m receiving data from the GPS72, but on the terminal see the pulses of data, but instead of getting interpretable data, there are strings of, like “~f~~”

    I know it’s because I have an incompatibility in comms protocols and have tweaked the terminal through speeds and parity with no joy.
    I suspect I have to configure the HT-06 to use 4800 8/N, but not having the connectors to connect the laptop to the HT-05 I’m not able to tweak the coms speeds from the laptop, so I’m wondering if it is at all possible to send AT commands from the laptop to the HT-06 over BT?

    Like

    • Hi Alan,
      thanks for your kind words :-).
      As for your question: you cannot send AT commands over the air to the Bluetooth module: if it is connected, it is in transparent mode and will send the incoming data to the other side (so you cannot reach the Bluetooth controller with AT commands).
      As for the protocol errors: can you hook up a logic analyzer on the serial signals to see what is going on? That would give a clue if the baud is somewhat wrong or outside the spec, if parity/etc is used.

      Like

      • And thanks for your prompt reply. It’s as I feared. Odd, eh, that they design a slave module – presumably to connect to a dumb device, that can’t be configured by the master.
        One more question, if I may. When I do get to set the comms protocol with an AT command, say AT+BAUD3, does that setting persist over a power reset? i.e. can I set it in the lab, and then rely on it in the field?

        Like

  18. Hi Erich,
    Back again, sorry.
    I suspect I have a faulty device (HC-06 Ver 1.06), and being a software guy, a class world-renowned for unfairly blaming the hardware, I have tried to be thorough in my testing.
    The final clincher for me is that when I send AT commands over the serial port I get no response at all.
    I have a breakout board on the serial line and can see the RX line flash its led.
    The HC-06 is flashing.
    I am using 232Analyzer to send data 9600 8 N 1 and am sending AT.
    I have read the HC Serial Bluetooth Products User Instructional Manual, http://www.exp-tech.de/service/datasheet/HC-Serial-Bluetooth-Products.pdf which seems quite straightforward if a little confusing.
    And I’m still receiving corrupt data over the bluetooth connection when sending ASCII at 9600 8 N 1.

    Before I send off for a replacement, is there anything else that you know that I can try to talk to my baby?
    Cheers, and thanks for your patience.

    Like

    • If the HC06 is flashing, then it is not connected to the PC. You really would need a logic analyzer like the Salae one so you can inspect the bits and bytes on the line. Maybe something is wrongly configured on your side (baud?), and only with flashing LEDs you will not see it. I’m a software guy too, but developing software for hardware means a scope and a logic analyzer is key. Without it, it is like programming without a PC monitor :-(.

      Like

      • I’m a novice with these boards as well but it appears that you’re trying to send AT commands and the chip is not in that mode. My board had a pin labeled “KEY”.Tie that pin to the VCC source, Now disrupt and re-establish the power to the HC-06 leaving the “Key” tied to power. The unit will reboot in AT mode. To reset to Normal mode remove KEY from Vcc and disrupt and re-establish power. I was also able to easily pair with this device using “1234” as the code. Once that was done I opened up TeraTerm Pro and selected the comm port configured for my BT. I was talking to a Mini Pro quite quickly…Hope this helps…

        Like

  19. Hello Erich,

    I am using an HC-05 board (found on eBay http://www.ebay.com/itm/150843209961?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649).

    I am trying to configure it using the AT commands. This can only be done using the physical serial connection to the PC, is that correct? I believe I managed to get the board into configuration mode using the KEY pin, since the LED now blinks differently. However, when I use Termite to send AT commands (simply with AT\r\n), the board responses with things such as: x, then xÅr\n, then Ap\ûpÿ, etc every time I resend the AT command. I guess it could be some problem with the coding of the commands such as wrong font… But still I don’t understand why it responds differently to a unique command.

    Can you help? Thank you in advance!

    Remi

    Like

    • Hi Remi,
      this does not sound like a font problem. Can you hook up a logic analyzer to see what the module really responds? It very well could be that this module is not a HC-05 one, but a different one with different firmware?

      Erich

      Like

      • I have concluded that the HC-06 device does not conform to RS232 standards.
        I have spent 6 weeks messing with it ( well, 2 separately purchased boards) connected to my PC (XP and W7) using some pretty clever terminal emulators (realTerm, Commfront 232Analyser, Reflection ) and I have concluded that it doesn’t generate the 10 bit per character (start, 8 bit data, stop) syntax defined by RS232.
        I was unable to get it to respond to an AT command, nor could I get it to transmit text at its default speed of 9600, N 8,1 or any other combination.
        All the folks successfully using it are using Arduino. I haven’t found anyone using it successfully in conventional RS232 PC mode.
        I have thrown them away and spent $125 on an older but functional RS232 to Bluetoth adapter. It’s pretty clunky, requiring a PC Utility to configure it, but it works!

        Like

      • Hi Erich,

        Thanks for the reply. I don’t have a logic analyzer. I have tested somewhat further and I have noticed that using Termite, when I change the baud rate to a lower value, I get a response identical to what I send to the device. If I put a higher baud rate, I start getting all this nonsense… Also, I should mention that I don’t have a serial connection on my computer, so I make use of a RS232 to USB converter from Logilink. So the baud rate which I change is probably the baud between the PC and the converter.

        Like

      • Hi Remi,
        yes, the baud is only applied to the physical serial line, not for the USB communication. for a USB-CDC connection the baud is pretty much useless.

        Like

      • Just read Allan and Tom’s comments. If I understand it, I should have a RS232 to TTL converter between my USB to RS232 converter and the HC-05 module because the HC-05 “talks” in TTL and not RS232?

        Like

      • Hi Remi,
        The HC-05 module does not use TTL (0-5V) levels, but 0-3.3V. RS-232 uses completely different voltage levels (3 to 15V and -3 to -15V, see http://en.wikipedia.org/wiki/RS-232), so they are not compatible. Your PC or RS-232-USB converter expects that different voltage, so if you want to connect the bluetooth module to your PC, then you need to use a level shifter like a Maxim 3232 or similar. The logic levels of 0-3.3V of the module are only to be used with something which has the same voltage levels, e.g. a microcontroller.

        Like

      • Hi Erich, thanks for the answers. The daughter board which I bought with the HC-05 module mounted on it has such a MAX3232 level shifter (see ebay link above).

        I know that I was able to switch the board into AT mode, at least from the different blinking of the LED. I tried using different baud rates for the serial communication to the bluetooth module, no success. I made sure the TX and RX are correct, used different voltage levels (5.0 and 3.3 volts) for both the Vcc and the Key. I tried to reset the device using AT+RESET in case the transmission to the device was functioning correctly but not the reception from it. I have bought 3 of these devices and tested all, they give the same results.

        I am running out of ideas…

        Btw, what is the tiny push button on the daughter boards for?

        Like

      • I have not used these modules. But it sounds you have nothing than the modules? No user manual, schematics or something you absolutely need to understand this module. I checked that ebay page, but there was no more information than the pictures. You even cannot be sure what kind of firmware is on the module without this information. And without the right tools (aka logic analyzer) it is like fishing in the dark :-(

        Like

      • Oh, I see, there *is* indeed a data sheet :-). What the ‘Key’ does depends on the firmware on the module. Many firmware are using it to get back into the ‘command’ mode. But not clear to me which firmware really is on this module.

        Like

      • And I have found in the description what ‘key’ is supposed to do. Key connects 3.3.V to PIO11:
        3. PIO11, control the module working mode, High=AT commands receiving mode(Commands response mode), Low
        or NC= Bluetooth module normally working.

        Like

      • Hi Remi,
        I can confirm that a Maxim 3232 works like a charm with the HC-06 to provide an interface between a PC serial COM port and the HC-06, notwithstanding the discrepancy between the TTL and MCU voltages, as it handles the voltage range of 3.3 to 5V.
        I have just taken delivery of my Maxim board and am happily bluetoothing between my PC and my Android phone.
        I have also connected my Garmin GPS72, configured to report using NMEA at 4800 to my Android phone with this configuration.
        You don’t need a logic analyser.
        You do have to cross the TXD and RXD lines between the HC-06 and the Maxim.
        It’s taken me almost eight weeks to work this out, but success comes to the diligent!

        Like

  20. Alan,

    Sorry, but you are missing basic electrical skills and you did not rtfm.

    The HC-05/6 as well as all the other BT-modules from other suppliers provide a 3,3V digital logic interface. The guys using an arduino wire the 3,3V TxD/RxD signals of the arduino UART to the corresponding pins on the HC-05 module, the arduino provides a virtual COMport via USB to the connected PC/Laptop so there is no RS232 within that signal way to be used.

    Your PC (COM1:) has a standard RS232 interface what is electrically on a total different planet (use wikipedia and READ please) as the 3,3V or 5V digital logic interface. Or you use an USB->RS232 converter cable but that’s the same…
    That’s why you could not make a working connection… It is an electrical problem !

    http://www.ebay.de/itm/RS232-Serial-Port-to-TTL-Digital-Converter-Module-SP3232EEN-5V-3-3V-Jump-Kables-/400676853830?pt=Wissenschaftliche_Ger%C3%A4te&hash=item5d4a339846

    Use something like that and everything should be fine ;o).

    Good luck, tom.

    Like

    • AHA!, at last some light in the wilderness.
      Silly me…When I did R TFM (extensively), the doco consistently (if slightly incoherently) referred to the HC-05 as a serial BT adapter, and from my software background, serial MEANS RS232!
      Nowhere did they say that the headers on the card talk TTL not RS232. I have discusses my problem extensively on forums and emails, I knew I was making a simple mistake, but no-one was smart enough to spot my confusion.
      The traps for young players trying to reach across technologies! Thanks Tom, so much for your clarification.

      Like

  21. hi..my project is to send the data using bluetooth module.is that possible if i want to connect hc-05 from PIC1 as a transmitter and hc-06 as a receiver at PIC2 ?

    Like

    • The HC-06 Bluetooth module only can be a slave, but the HC-05 is able to be a master too. So with the HC-05 as master, you should be able to connect from teh HC-06 module. What microcontroller (PIC, TI, Freescale, STM) does not matter :-)

      Like

  22. Hi erich
    I have a module (DAQ Module) to get data from strain gage in rotating sensor. The module use USB cable communication to my computer (It has Ft232 serial to Usb IC in its daughterboard).
    Now, I want to get the data via Bluetooth, and I already bought HC 05. Unfortunately, Because of the module architecture, I can’t get its rx tx to my HC 05.

    In the HC 05 datasheet, I see the USB Dp and Dm port, and they said it can transfer data via usb protocol (v 1.1). After that, I connect my module’s USB port (USB type B) to the Dp and the Dm port, and I connect the Vcc and Gnd to my power bank. The HC 05 is connected to my comp, but it is connected to my Serial Com over the Bluetooth, not as the module it self. And i cant connect the module to my Labview (because the module is used to connect via USB cable)

    I want to ask several questions:
    – Can I connect HC 05 via USB Protocol, instead of UART Serial Communication?
    – What should I do if I want to connect via USB protocol? Install another driver (in windows device manager)for my HC 05, or else?

    I’m sorry for my long post and my english. Hope to get your response soon
    Thank you :D

    Like

  23. Pingback: Getting Bluetooth Working with JY-MCU BT_BOARD V1.06 | MCU on Eclipse

  24. Hi Erich
    Thank you for your kindness to answer me.
    I’m sorry, maybe my explanation about my module is not good enough yet
    My module is Emant 300. It is used to be connected to computer physically with usb cable, but actually communicate with the computer using UART. So that’s why there is converter of USB-TTL (FT232) in my module.
    You can see it in this link http://www.emant.com/251004.page

    I have tried to connect my module via usb cable, and it was detected (until now, it is, as long as i connect it via usb cable). In Windows Device Manager, its name is USB serial port (to proof it physically connect via usb cable, but talking with serial communication). It connected to my Labview, detected as emant 300 DAQ module.

    But now, I want to change usb cable with bluetooth HC 05. So i cut the usb cable, pin Dp and Dm to HC 05, and power it with power bank. But why the bluetooth can’t connect as USB Protocol?

    About SCI to USB converter, I will try to learn that. Maybe it will provide me another alternatives. Thank you, Erich

    Like

    • Are you saying that you connected Dp and Dm to the HC05 Rx/Tx pins? This for sure does not work: USB is using a completely different protocol than RS-232/SCI. Not only this, it is using different voltage levels too.

      Like

      • No, I am not. I connected Dp and dm to the HC 05 Dp and Dm pins, since it have those pins. I want to communicate usb protocol via bluetooth but it doesn’t work :(
        Maybe the manufacturer must delete its spec about ‘can use usb protocol v. 1,1′ . They does not have the explanation about that (and make me confused). HC 05 Users in internet don’t talk about this too, so it’s hard to find any clue about usb protocol over bluetooth on it.
        Maybe i’ll try to convert the usb protocol to serial protocol, as you say, and after that connect that serial to the Rx/Tx pin at HC 05
        Thank you very much, Erich

        Like

  25. Pingback: Processing and Arduino through Bluetooth

  26. Pingback: Android Based Wireless ECG

  27. Pingback: Say your Arduino how much you love it | HELENTRONICA

  28. Hi,
    So I got the Hc-06 module,put it on a breadboard,powered it up,paired it with my pc.Then I used Teraterm to open a connection to it,which it did(the red light stayed continuously on),entered in the command “AT” but I got no response back.
    Am I doing something wrong?

    Like

    • Hi John,
      you only can send AT commands from the microcontroller connected to the HC-06 module, not ‘over the air’.
      Once the LED of the module is on, it is in transparent mode, means it is sending the text over the air ‘as is’, and the module does *not* accept any commands.

      Like

      • Ah ok,so the only way I would be able to see data on teraterm/hyperterminal would be to connect the HC-06 to a micro,then have the micro send data out to the HC-06 which would transmit that to the paired pc which could be viewed on Teraterm,would that be correct?

        Like

      • Cool,thanks.I think I have a 8051 micro around somewhere,anyone know where I get some example code that I could load onto the micro that I could send to the HC-06

        Like

  29. Hi Erich,

    A great and interesting article on the bluetooth modules..!! And I must say, your comments section is full of lost of additional info..!! I would like to ask help for my small problem with the HC-06 module, which seems similar to Tom.

    I’m on Vista with the default bluetooth stack/drivers. I have a cheap bluetooth dongle adapter as my laptop doesn’t have native BT hardware. I have followed the numerous procedures for paring-powerup-power cycle-unplug replug device- etc etc, but none seem to get the hc-06 to connect with my PC.

    The computer sees the BT device fine, it seemingly pairs. Atleast the windows dialog box shows that and device drivers are installed. I can also see the com ports in device properties and in device manager. But the status LED on the module keeps blinking indicating AT mode and never goes solid on.

    The serial port shows up in the services tab of the BT device properties, but when I try to connect to the serial port in any terminal emulator (I tried a few of them to be sure), it either stops responding or tells port not found or closed etc. Checking the services tab again afterwards confirms this (the serial port has disappeared from the list momentarily). If I unpair / repair / power cycle the module, same thing happens over again.

    There doesn’t seem to be anything wrong with the module itself, as I can pair it with 2 separate smart-phones. Everything works correctly as I can see serial data coming in from the microcontroller, and also issue commands to the microcontroller over BT.

    Thanks in advance for your help.
    Kind regards,
    Ameya.

    Like

    • Hi Ameya,
      thanks for your kind words :-).
      About your problem: just installing the drivers on the host will not change the blinking LED. The blinking LED only gets permanently on once you have a connection to the module with a terminal program. The fact that your terminal emulator stops responding indicates to me that you might be using the wrong COM port? At least I have the same on my machine (which has a native BT module). Pay attention that there are multiple USB COM ports installed by the driver, but only one works (the one which is listed in the properties of the device driver, http://mcuoneclipse.files.wordpress.com/2013/06/device-services.png?w=584). So can you make sure you connect to the proper COM port with your terminal program?
      I hope this helps.

      Like

      • Hello Erich,

        Thanks for your prompt help..!! I am sure I am using the correct port in the terminal emulator. The HC-06 enumerates with 2 ports, only one is available in SPP mode and thats the one I use to connect. Here is some more surprising behavior I came across.

        1. Firstly, “sometimes” I am able to successfully connect and send-receive data..!!
        2. But then majority of the times, it refuses to connect after paring. When that happens, LED is blinking, terminal emulator reports port closed or stops responding, and SPP device disappears from the Bluetooth device properties.
        3. I then have to remove device, power-cycle HC-06 module, re-pair and try to re-connect again. But 90% of the times it never works. I just get plain lucky the remaining 10% times, and proceed with my actual work.
        4. I may get going again after a restart of the PC, but that also is not consistent. Yesterday I tried installing other BT drivers PC side, but of no use.
        5. Also, all these times I keep checking the module functionality periodically, by successfully pairing and connecting with an android smart phone, which works as expected.

        I strongly feel its the PC side BT stack which is messing things up. Can you suggest something here..??

        Kind regards,
        Ameya.

        Like

      • Hi Ameya,
        yes, this could be a PC BT stack issue too. You might try to uninstall the device driver for it in the device manager, maybe this helps. But not sure.

        Erich

        Like

  30. Hello Erich,

    I have bought an HC-05 mounted on a daughter board that allows me to communicate in RS232 with the module instead of TTL (it has the MAX3232 chip).

    I use the module to communicate between a PC and a motion controller (Elmo) in RS232. I was able to change the communication parameters to suit me (baud rate, flow control and parity). I was able to establish a connection with the controller through the software that was delivered with it.

    Only I noticed that the connection is very unstable: I am either unable to establish a connection at the first attempt or the connection drops after between 5 and 60 seconds. I decided to analyze the communication between the PC and the controller by using Termite. I look at what is transmitted by the PC when a connection is attempted and what the controller responds.

    I noticed that the connection fails or drops when the controller’s response contains errors. These are sorts of typos in the answers from the controller. Do you think this could come from the module ? Or does it look more like noise, or a bad connection to earth level ? Any ideas ?

    Thanks!

    Like

    • Hi Remi,
      I would first verify the power connection to the module. Is it within specs? 5V? Then: maybe the UART connection from the microcontrolle is the problem: if your clock is drifting, or not stable enough, you will get garbage on the serial line. you would need to check this with a scope or logic analyzer. And you might need to use a lower baud rate (I use all my modules with the default baud rate of 9600 or 38400 (depends on module)).

      Like

      • Hi Erich,
        I use a USB port for the 5V supply, just for convenience. Maybe this is not the best thing to do. I will have a try with my DC controlled power supply instead.
        I do not have a logic analyzer available but will look for one in case this does not fix the problem.
        Also, I had the module set to a baud rate of 115200 since this is the default baud of the controller. I have now lowered it back to 9600 and at first sight, the connection looks more stable than before. It will need some more testing but it looks better already!

        Thanks a lot!

        Like

  31. Pingback: Interfacing Android With Microcontroller | Adhitya Reza

  32. Pingback: 1000 Days of Blogging: Numbers and Tips for You | MCU on Eclipse

  33. Hi. I have huge problem with HC 06. I changed name, pin and baud rate with AT commands… but then the module is not working… It doesnt respond to any AT commands and when I am connected to module with.. for example.. android device and I try to send some AT commands… It doesnt read any characters………. Please.. help me :( thanks

    Like

    • You need to use a microcontroller board (like the FRDM-KL25Z I used) to regain access to the module.
      Use the same baud as you have specified. If that does not work, it could be that the baud settings are incorrect:
      try with the microcontroller all defined baud rates of the module, and use a logic analyzer to inspect the result.
      Then you should be able to recover the module.
      good luck!

      Like

  34. hi Erich
    can you provide coding for senting signal via bluetooth module from adriuno to antroid phone. input can be signal from a pushbutton. like notification in phone wenever the button is pushed .

    Like

    • Hi, there is really no magic behind doing something like this:
      a) check that button is pressed (several ways to do this)
      b) send a message/string/command to the UART to the Bluetooth module
      c) that message/string/command will end up on the Android phone connected to the bluetooth module
      d) it is up to you what you do with this message on the Android side.
      I hope this helps,
      Erich

      Like

What do you think?

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s