Tutorial - HC05 Slave/Master Setup

Hardware Required
  • HC-05 x 2
  • USB to UART Converter Module / Arduinop Uno
Software Required
Documentation
In this tutorial, i used HC-05 from my Nadi Eleczone Solutions and USB to UART from cytron. Arduino Uno also can be used as USB to UART converter.

This tutorial will cover how to setup one HC-05 as Slave and another HC-05 as a Master. As a factory reset, HC-05 come as a Slave mode. HC05 above come with FC-114 breakout / base board. There are variety of breakout / base board in the market but most of it has basically the same operation.

The thing that you must notice is this board can be power up by connecting 3.6V-6V positive terminal to VCC and negative terminal to GND pin. However, it operate at 3.3V logic level.

Please set the USB to Uart power selector to 3.3V. So the logic that come out from the USB to UART coverter will be 3.3V logic level. Below is the schematic:

If you set the USB to UART power selector to 5V or using Arduino Uno, you may need external hardware which is potentiometer or variable resistor. This is because USB to UART is now 5V logic level. HC05 RX pin must receive 3.3V logic level from USB to UART TX pin. Hence between these two module, a potentiometer is needed. The potentiometer act as a step down voltage from 5V logic to 3.3V logic. Adjust the logic level at the middle pin of the potentiometer to 3.3V logic level. This can be done by using multemeter set to voltmeter and measure the voltage at the middle pin of the potentiometer. If you are not using the potentiometer, it may work but may not suitable for long term use because it will harm or drain more current from USB to Uart converter (will get warm).

After you have set up the circuit, connect the USB to Uart to your computer. Then, you will notice that the HC05 LED will start blinking indicate it is power up. If not, toggle the switch so it can be power up. The key pin on this HC05 board act as a reset pin. If it connected to VCC, it will ON otherwise connect to ground, it will OFF. The switch connect to this key pin act as a reset pin.

The LED on the HC05 board can blink in four type as shown below:

AT Mode : Slow blinking (0.25Hz)
Trans Mode : Fast blinking (2Hz)
Paired Mode : Medium blinking (1Hz)
Connection Mode : LED will blink twice and stop for long time (~2 seconds), and repeat itself.

Slave Mode
  • Connect the circuit and connect the USB to UART to computer
  • HC05 will power up, if not try to toggle the external switch.
 
  • Led on HC05 will blink in Trans Mode
  • Now hold on the internal switch on HC05 board, and toggle the external switch OFF and ON. This will reset the HC05. Then wait for a second. Then, do not release the internal switch on HC05 board until you finish all the step. The led on HC05 will blink in AT mode.

  • Open the hyperterminal and set it to default mode, 38400 baudrate. HC05 use 38400 baudrate in AT mode.

  • Go to “Settings” tab, ticked “Send line ends with line feeds” and “Echo typed characters locally”.

  • Then, type the following AT command in the Hyperterminal window. Remember to press “Enter” at the end of command. Put the name for your HC05 slave as you want at AT+NAME="NAME HERE" . Copy the slave address given by AT+ADDR? to be use later.
AT Command Response Description
AT OK Typed AT until HC05 response OK. Sometime for the first time connect, it may return ERROR.
AT+ORGL OK
Reset HC05 setting to default.
ID: 0
Working Role: Slave Mode
Baudrate: 38400bits/s or 9600bits/s
Stop bit: 1
Parity: None
Pair Code: 1234
AT+RMAAD OK Cleared any paired devices
AT+PSWD=1234 OK
Set password to 1234 (user can choose any password they like, master and slave must have the same password)
AT+NAME=Slave OK
Set the HC05 name to Slave
AT+ROLE=0; OK
Set the HC05 as slave
0 – Slave
1 – Master
2 – Slave Loop
AT+ADDR? +ADDR<address>OK
Get the slave address. Every HC05 has its own unique address. Copy this adress.
AT+UART=9600,0,0 OK
Set the transparent UART baudrate to 9600.(user can choose any baudrate that they prefer.)

  • Hyper Terminal Window
 

Master Mode
  • Take another HC05 to be set as Master mode.
  • Connect the circuit and connect the USB to UART to computer
  • HC05 will power up, if not try to toggle the external switch.

  • Led on HC05 will blink in Trans Mode
  • Now hold on the internal switch on HC05 board, and toggle the external switch OFF and ON. This will reset the HC05. Then wait for a second. Then, do not release the internal switch on HC05 board until you finish all the step. The led on HC05 will blink in AT mode.

  • Open the hyperterminal and set it to default mode, 38400 baudrate. HC05 use 38400 baudrate in AT mode.

  • Go to “Settings” tab, ticked “Send line ends with line feeds” and “Echo typed characters locally”.

  • Then, type the following AT command in the Hyperterminal window. Remember to press “Enter” at the end of command. Put the name for your HC05 slave as you want at AT+NAME="NAME HERE" . Put the address that you copy earlier in AT+PAIR, AT+BIND and AT+LINK.
*Before doing this step, make sure that HC05 slave is power up / ON so that the HC05 master can connect with this HC05 slave mode. You can just connect the HC05 slave VCC and GND pin and disconnect other pin.

AT Command Response Description
AT OK Typed AT until HC05 response OK. Sometime for the first time connect, it may return ERROR.
AT+ORGL OK Reset HC05 setting to default.
ID: 0
Working Role: Slave Mode
Baudrate: 38400bits/s or 9600bits/s
Stop bit: 1
Parity: NonePair Code: 1234
AT+RMAAD OK Cleared any paired devices
AT+NAME=Master OK Set the HC05 name to HC05Master
AT+ROLE=1 OK Set the HC05 as master
0 – Slave
1 – Master
2 – Slave Loop
AT+RESET OK Reset command after HC05 changing role from Slave to Master.
AT+CMODE=1 OK Allow connecting to any address.
AT+INQM=0,5,5 OK Inquire mode – standard, stop after 5 devices found, (or) stop searching after 5 seconds
AT+PSWD=1234 OK Set password, should be the same as the slave.
AT+INIT OK Start bluetooth transmit and receive profile library
AT+INQ +INQ<address>+INQ<address>…OK Searching for bluetooth device around. It should reply back the address of every detected bluetooth device around. Make sure the Slave is power up and you will notice that Slave address that you copied somewhere earlier is in the list.
AT+PAIR=<HC05Slave address>,20 OK Pairing the HC05Master and HC05Slave
<HC05Slave address>, ex: 12,3,289431. Note that ‘:’ is change to ‘,’
AT+BIND=<HC05Slave address> OK Bind address
AT+CMODE=0 OK Only allow connecting to the “bind address”
AT+UART=9600,0,0 OK Set the transparent UART baudrate to 9600.(user can choose any baudrate thet they prefer.)
AT+LINK=<HC05Slave address> OK And now to actually connect both devices.
  • Hyper Terminal Window

  • Now disconnect and connect power for both HC05 slave and master. They should now can connect to each other where the master will search for slave to be connected.
Happy trying







13 comments:

  1. Thank you so much.........I was almost going to hell for this bloody "Button" ....... finally saw my AT command response....ohh...........what a relief.. wish u best....

    ReplyDelete
  2. Hi.....My bluetooth module looks exactly right your's as u posted.....but so far it is not able connect to my android or pc("paired but not connected")......could u please help me in this regard

    ReplyDelete
    Replies
    1. Could you elaborate more on the problem, at which stage you are stuck or more specific on your problem. Thanks :-D

      Delete
  3. Perfect guide, thank you!

    ReplyDelete
  4. Thanks a lot! Without the comment about the button it would've been impossible to find out the solution. Thanks man!

    ReplyDelete
  5. Hello Eleczone,

    My new experience with bluetooth, but this module has different kinds of firmware: Bolutek firmware or linvorV1.8 firmware according to different internet sites information. It has different sets of AT commands with the specific firmware.

    See also:
    http://www.martyncurrey.com/hc-05-fc-114-and-hc-06-fc-114-part-2-basic-at-commands/

    It also means confusion in various HC-05 tutorials, if you don't know about the firmware version. Gladly this tutorial gave me the answer to configure the bleutooth module properly with the right AT commands.

    To get to the AT-command-mode, EN-signal is not necessary. You hold on the [button] on the module board [HC-05 FC-114], while powering up the module. EN is by default high, so the board is already to go when powered up.

    The STATUS signal is very handy for Arduino Boards to upload sketches from the Arduino IDE. With some electronic components (resistors, a transistor and a capacitor) you should connect this to the RESET input of the Arduino Board. So in this way you can wirelessly upload your sketches with bluetooth dongles or build-in bluetooth modules on the laptop/PC.

    Thanks for this handy tutorial. It is also a very cheap way to connect your MCU wirelessly in the 2.4GHz band.

    JACK-ZANDE


    ReplyDelete
  6. Thanks for those informations. But when we have a board FC-114 with EN in place of KEY, we can't use an external switch. The EN pin is only used to ENable or disable the HC-05 module. On the other hand, you can operate the internal switch as you said for getting the AT mode by powering the HC-05 module when maintening the switch on for a few secondes.

    Is there a AT command to list all the AT commands usabled?

    MICHEL

    ReplyDelete
    Replies
    1. We already attached the AT Command file on top of the page. Documentation: AT Command. But its not from original vendor. Try to find one too. :-D

      Delete
    2. Actually there is a lot of breakout board version in the market with various pin arrangement. :-D

      Delete
  7. Thanks very much. It was so helpful, especially that about the button to get AT mode. Sorry for my bad english.

    ReplyDelete
  8. I know it's a silly question but where is the setting tab?

    ReplyDelete
  9. Hey thank you very much for this blog.
    I just have a question, after i have set hc 05 to master mode can we provide serial communication via MATLAB over PC.

    ReplyDelete