HC-05 Bluetooth Module AT Commands

Click for Larger View

This page is my attempt to document and explain how to use some of the AT-style commands that are available for the in expensive HC-05 type Bluetooth Modules available on eBay, or from various Chinese sellers.  Be aware that not all HC-05 modules you can purchase are configured with the same firmware version.  The information presented here is based on the modules I purchased and which use version 2.0-20100601 of the HC-05 firmware.  From what I've read online, the firmware in these module can be upgraded, but the process is quite involved and requires the use of another company's firmware and development software, which seems a bit sketchy to me.  And, as the 2.0-20100601 version firmware seems to work well enough of my purposes, I have not investigated or tried this upgrade process.

Configuring the HC-05

To use these commands you must first place the HC-05 module into command mode.  To do this, start by connecting the HC-05 with Base Adapter Board to an FTDI-type USB to serial adapter using the following image as a reference:

Click for larger view

Next, remove power from the module, hold down the MODE button and reapply power while continuing to hold down the MODE button.  Release the MODE button after a few seconds.  If you have successfully placed the module into command mose, the LED on the module should now be blinking slowly on and off (and one second on followed by one second off.)  You can now use a serial terminal program to communicate with the HC-05, but you must set it to 38400 baud and configure it to send both a CR and LF code when you press enter on the terminal.  Alternately, you can use the Arduino IDE's Serial Monitor to send commands to the HC-05.  After clicking the "Serial Monitor? button in the upper right of the Arduino IDE's window, set one selector to "Both CR & LF" and the other to "38400" baud, as shown below.

The next section will show the result of giving various AT commands to the HC-05.  Commands typed and send by typing ENTER or pressing the SEND button will be displayed in BLUE.  Responses from the HC-05 will be shown in GREEN.  YOU can find a variety of documents on the Internet that purport to describe the AT command set for the HC-06 but, in my experience, many of these seem to list commands that I could not get to work.  One example is the command "AT+NAME" which is supposed to read back the name that will be displayed on a PC when pairing, or connecting to this module.  However, this command does nothing when I try it.  It doesn't even echo back an error message.  It's possible this a limitation of firmware programmed in the HC-05's I purchased and that this command may work on other versions of this firmware, but that's just speculation.  So, be careful not to assume that something will work just because you read about it a document.  Test and verify!

Configuration and Info Commands

Get Firmware Version:

AT+VERSION

+VERSION:2.0-20100601

OK

Get UART Configuration

AT+UART

+UART:57600,0,0

OK

Note: numbers are baud rate (57600), number of stop bits (0 = 1 bit, 1 = 2 bits) and parity (0 = none, 1 = odd, 2 = even)

Configure UART

AT+UART=<baud>,<stop>,<parity>

OK

Replace "<baud>" with the needed baud rate, such as 57600, "<stop>" with one the following values to select the number of stop bits (0 = 1 bit, 1 = 2 bits) and "<parity>" with one the following values to select parity (0 = none, 1 = odd, 2 = even).  Note: the baud rate set here does not change the baud rate used by command mode, which is always 38400.  It changes the baud rate that will be in effect when you cycle VCC to exit command mode and this new setting will persist until changed again with this command.

Configure Polarity of STATE (DTS) Pin

AT+POLAR=1,1

OK

Note: first number selects pin (0 = PI08 pin, which is the status LED, 1 = PI09 pin, which is the DTS signal that indicates an active connection) and the second number sets the polarity of the signal (0 = pin goes LOW when active, 1 = pin goes HIGH when active.)  Unless changed with this command, toe polarity of the STATE signal defaults to active = HIGH.  You can also issue the command "AT+POLAR=0,<state>" to change the polarity of the LED signal, but this is not recommended.

Check Polarity of STATE (DTS) Signal After Setting It

AT+POLAR

+POLAR:1,1

OK

Note: you can only issue this command after setting the Polarity, as the set command selects what signal pin to display (by default it shows the polarity of the pin used for the activity LED.)

Get Current Password (PIN) for HC-05

AT+PSWD

+PSWD:0000

OK

Set New Password (PIN) for HC-05

AT+PSWD=<pin>

OK

Where "<pin>" is the new 4 digit PIN, or Password to set.  Note: on Mac OS, setting the PIN to 0000 makes pairing happen without having to enter a PIN number when setting up the connection.

Set Name of HC-05 Module

AT+NAME=<name>

OK

Where "<name>" is the name you've selected for the module.  Note: I was unable to find a command to read back the current name.  The docs say the name string can be up to 32 characters long, but I have no tested this.  Error code 3 in the response indicates the name is too long.

Get HC-05's Role (Master, Slave or Slave-Loop)

AT+ROLE

+ROLE:0

OK

Note: a response of 0 indicates HC-05 is in Slave Role, 1 = Master Role, 2 = Slave-Loop Role.  Note: Slave-Loop Role configures HC-05 to send back the data it receives from the Master.

Set HC-05's Role (Master, Slave or Slave-Loop)

AT+ROLE=<role>

OK

Where the numeric value of "<role>" set the new role. (0 = Slave Role, 1 = Master Role, 2 = Slave-Loop Role.  Note: Slave-Loop Role configures HC-05 to send back the data it receives from the Master.

Get HC-05's Bluetooth Address

AT+ADDR

ADDR:14:3:638f4

OK

Note: this command displays the address that's needed by another HC-05 in "master" mode in order to allow it to connect to this HC-05 in "slave" mode.  This address is supposed to be a unique Id.  To work as a slave device, this HC-05 must be set to the same baud rate as the Master HC-05 and have its Role set to "2" with the Set Role command (AT+ROLE=1).  The next section show how to configure the Master HC-05.

Configure HC-05 As Master

AT+ROLE=1

OK

AT+CMODE=0

OK

AT+ADDR=14:3:638f4

OK

The command "AT+ROLE=1" configure this HC-05 as a Master.  The command "AT+CMODE=0" set the connection mode to use a "fixed address" and "AT+ADDR=14:3:638f4" sets the address of the Slave HC-05 it will connect to.  After both HC-05s are configured, power cycle both and, within a few seconds, the Master HC-05 will automatically establish a connection to the Slave HC-05.  Serial data can then flow back and forth between them without any setup needed.

Get Address for Most Recent Device Connection

AT+MRAD

+MRAD:8863:df:ae7c44

OK

Displays the Bluetooth address for the most recent device (such as a PC) that this device has communicated with.

Get Inquire Access Code

AT+IAC

+IAC:9e8b33

OK

Returns the Access Code for this HC-05. The normal response if "9e8b33" which indicates it is set to the General Inquire Access Code:0x9e8b33, and can be used for seeking (or being sought by) all the Bluetooth devices around.  This code can be changed, but is not recommended unless you know what you're doing.

SPP Profile

The HC-05 has a special mode called SPP Profile which is supposed to provide a way to make use of an additional set of commands you can use to do things like scan for other, nearby bluetooth devices that are discovery mode or manipulate a set of additional I/O pins.  So far, I've been unable to use this mode to scan for other bluetooth devices in discovery mode, but it does work with the commands for setting and clearing the HC-05's I/O pins (see below.)

Enter SPP Profile

AT+INIT

Use command to switch the HC-05 into SPP Profile mode.  However, be aware that immediately after you issue this command, the HC-05 will switch to using the baud rate, stop bits and parity settings you last set in command mode using the AT+UART command.  And, oddly, this command does not echo back an "OK" response even if you've set the baud rate to 38400 using the AT+UART command.  Also, once the AT+INIT command is sent, sending the command an additional time will produce an error 17 response.

Using HC-05's I/O Pins

The HC-05 modules you typically see on eBay consist of two parts.  First, there's the true HC-05 module, which is a smaller, sub-module PCB that's mounted onto a "Base" board that adds a 5v to 3.3v regulator and some circuity, such as a MODE switch and an LED that used to put the HC-05 module into command mode.  Many of the pins available on the smaller HC-05 sub-module, such as set of  general purpose I/O pins, are not made available through the Base board, but can be accessed by attaching small wires to the "castellated" pads around the edge of the board (see image at top of page).  This next section describes a set of AT commands designed to set and read the state of these pins.  While you can use these commands in command mode, they are really designed for use in SPP Profile Mode.

Set State of an Individual I/O Pin

AT+PIO=<port>,<state>

OK

Where "<port>" specifies pin number (pins 2, 3, 4, 5, 6, 7, 10 and 11 are legal values) and "<state>" is new state for pin (0 = LOW, 1 = HIGH).  An error code of 9 indicates an invalid pin number was used.  Note: in theory, I/O pins 0 and 1 should also work but I always got an error when I tried to set them with the AT+PIO command.

Get State of All I/O Pins

AT+MPIO

+MPIO:4FC

OK

Where the value send back (0x4FC) is a hex value where a one in bit "n" corresponds to the I/O pins listed in the bottom row of the following chart

Set State of All I/O Pins

AT+MPIO=<hex value>

OK

Where "<hex value>" is a hex number with the bits set according to the chart in "Get State of All I/O Pins,"  However, leave any bits that correspond to a pin marked as "LED" or "x" set to zero (0),