Configuring the HC-05 using AT commands

Anyone tinkering with the HC-05 bluetooth module will eventually have to use what are called “AT commands”. AT commands are simple text-based commands that follow the “AT” prefix (“AT” meaning ‘attention’). These commands are similar to the ones used with old modem devices. By sending specific AT commands to the HC-05 module, you can configure it or retrieve basic information about it, such as its name, baud rate, PIN code, role, and so on.

In this tutorial, you will learn to configure the HC-05 module using AT commands to tailor the module according to your project’s requirements.

Configuring the HC-05 Module

To configure the HC-05 module, you put it into command mode and send AT commands over the UART port. While in command mode, any ASCII bytes you send are interpreted as commands. After making changes, you restart the module to apply the settings. When you change the configuration parameters, they are saved until you change them again or perform a factory reset.

The default configuration for the HC-05 module is:

  • Device Name: HC-05
  • Role: Slave
  • Passkey: 1234
  • Serial Parameters:
    • Baud Rate: 38400 bits/s
    • Stop bit: 1 bit
    • Parity bit: None
  • Inquire code: 0x009e8b33

Connecting HC-05 Module to a PC

When it comes to connecting the HC-05 module to a PC, you have two options.

  1. You can use a USB to TTL converter, directly establishing a connection between the HC-05 module and your PC. This converter serves as a bridge between the USB port on your PC and the TTL-level serial signals that the HC-05 module understands.
  2. Alternatively, you can use the Arduino as a medium between the PC and the HC-05 module. In this configuration, the Arduino serves as a translator, relaying commands and data between the PC and the HC-05 module.

With USB to TTL Converter

Let’s connect your HC-05 module to your PC using a USB to TTL converter.

Connecting the HC-05 Module to a USB to TTL converter is as easy as applying power and wiring up the serial Rx and Tx pins. The Tx of the HC-05 module is connected to the converter’s RXD, the Rx to TXD, GND to GND, and VCC to 5V.

Note that the Rx pin on the HC-05 module is not 5V tolerant. So, if you are using a USB-to-TTL converter that is operating at 5V I/O levels, you need to step down the Tx signal from the converter to 3.3V. There are numerous ways to accomplish this, but the simplest is to use a resistor divider. A 1K resistor between HC-05’s Rx and converter’s TXD, and a 2K resistor between HC-05’s Rx and GND, will work just fine.

To summarize, the following are the connections:

HC-05 ModuleUSB-to-TTL converterNotes
VCCVCC
GNDGND
TXDRx
RXDTxUse level shifter if using 5V converter

The image below shows the HC-05 connected to the PC using the FT232RL USB to TTL converter.

wiring hc05 bluetooth module to pc using ft232 serial adapter

With Arduino

Similarly, you can connect the HC-05 Module to an Arduino. The TXD of the HC-05 module is connected to the Arduino’s D1, the RXD to D0, GND to GND, and VCC to 5V.

Again! The Rx pin on the HC-05 module is not 5V tolerant. So, if you are using a 5V microcontroller such as Arduino UNO, you need to step down the Tx signal from the Arduino to 3.3V using a resistor divider. A 1K resistor between HC-05’s Rx and Arduino’s D0, and a 2K resistor between HC-05’s Rx and GND, will work just fine.

To summarize, the following are the connections:

HC-05 ModuleArduinoNotes
VCC5V
GNDGND
TXDD1
RXDD0Use level shifter if using 5V MCU

The image below shows how to connect the HC-05 module to the Arduino Uno.

wiring hc05 bluetooth module to arduino hardware uart

If you use this method, make sure that an empty sketch is uploaded to the Arduino.

Entering AT Mode

To enter AT mode, follow these steps.

  1. Press and hold the push button on the HC-05 module.
  2. Supply power to the module.
  3. Release the push button now. If the onboard led starts blinking with a time difference of approximately 2 seconds, the HC-05 has successfully entered AT mode; otherwise, repeat the procedure.

Note that in AT mode, HC-05 communicates at a baud of 38400 by default and with each command it is mandatory to send ‘\r’ and ‘\n’.

Sending AT Commands

To send AT commands, you will require a Windows terminal program installed on your PC that can communicate with the HC-05 module over UART. For this purpose, we recommend using the “Arduino Serial Monitor”. However, there are also many other free options (such as PuTTY, Tera Term etc.) that you can explore.

To begin, launch the Arduino IDE.

arduino ide screenshot

Make sure the HC-05 module is powered up and in AT mode. The onboard LED should be blinking at a slow and steady rate.

When you connect the HC-05 to your PC, it will be recognized as a COM port. Opening up your device manager, and looking in the “Ports (COM & LPT)” tree, you’ll find a new port.

com port in device manager

Then in the Arduino IDE, navigate to Tools > Port and choose that COM port.

select com port in arduino ide

Open up the Serial Monitor via Tools > Serial Monitor, and make sure that the baud rate in the lower right-hand corner is set to 38400 and the ‘Both NL and CR‘ option is selected. This means when you send commands to the HC-05, it will put a newline and return at the end.

open serial monitor

Now type “AT” (without quotes) in the textbox at the top of the Serial Monitor and click the Send button. You should see “OK” as a response from the module. This means the communication is successful.

simple at command

You can now send commands like the ones below to get more information about your module:

AT+VERSION? – It prints the software version.

AT+NAME? – It prints the device’s name.

AT+ PSWD? – It prints the passkey.

trying multiple at commands

These are Read Commands. You can also send Write Commands like:

AT+NAME=Param1 – It sets the device’s name to Param1. Note that the device name can be up to 32 bytes long and can include special characters.

HC-05 AT Commands

For your reference here’s a list of all HC-05 AT Commands.

AT

UsageTest
ResponseOK
Parameter
Notes
ExampleAT
OK

AT+RESET

UsageReset the module
ResponseOK
Parameter
Notes
ExampleAT+RESET
OK

AT+VERSION?

UsageGet the software version
Response+VERSION:****
OK
Parameter
Notes
ExampleAT+VERSION?
+VERSION:2.0-20100601
OK

AT+ORGL

UsageRestore default status
ResponseOK
Parameter
NotesThe parameter of default status:
1. Device type: 0
2. Inquire code: 0x009e8b33
3. Module work mode: Slave Mode
4. Connection mode: Connect to the Bluetooth device specified
5. Serial parameter: Baud rate: 38400 bits/s; Stop bit: 1 bit; Parity bit: None.
6. Passkey: “1234”
7. Device name: “H-C-2010-06-01”
ExampleAT+ORGL
OK

AT+ADDR?

UsageGet module bluetooth address
Response+ADDR:****
OK
Parameter
NotesBluetooth address will be shown as: NAP: UAP: LAP (Hexadecimal)
ExampleAT+ADDR?
+ADDR:1234:56:abcdef
OK

AT+NAME?

UsageInquire device’s name
ResponseIf Success:
+NAME:****
OK
If Failure:
FAIL
Parameter
NotesDefault: “HC-05”
ExampleAT+NAME?
+NAME:HC-05
OK

AT+NAME=Param1

UsageSet device’s name
ResponseOK
ParameterParam1: Bluetooth device name
NotesLength up to 32 bytes Supports special characters.
AT+NAME=”HC-05″ is the same as AT+NAME=HC-05
ExampleAT+NAME=myBluetooth
OK

AT+RNAME?Param1

UsageInquire remote bluetooth device’s name
ResponseIf Success:
+NAME:Param2
OK
If Failure:
FAIL
ParameterParam1: Remote Bluetooth device address
Param2: Remote Bluetooth device name
NotesBluetooth address will be shown as: NAP:UAP:LAP (Hexadecimal)
ExampleAT+RNAME?0002,72,od2224
+RNAME:Bluetooth
OK

AT+ROLE?

UsageInquire module role
Response+ROLE:****
OK
Parameter
NotesResult is a number where:
0 -> Slave
1 -> Master
2 -> Slave-Loop
ExampleAT+ROLE?
+ROLE=0
OK

AT+ROLE=Param1

UsageSet module role
ResponseOK
ParameterParam1: module role:
0 -> Slave
1 -> Master
2 -> Slave-Loop
NotesRoles:
Slave (Default): Passive connection
Slave-Loop: Passive connection, receive the remote Bluetooth master device data and send it back to the master device
Master: Inquire the near SPP Bluetooth slave device, build connection with it positively, and build up the transparent data transmission between master and slave device.
ExampleAT+ROLE=0
OK

AT+CLASS?

UsageInquire device type
ResponseIf Success:
+CLASS:****
OK
If Failure:
FAIL
Parameter
NotesDefault: 0
Example

AT+CLASS=Param1

UsageSet device type
ResponseOK
Parameter
NotesBluetooth device type is a 32-bit parameter indicates the device type and what type can be supported. For inquiring the custom Bluetooth device from around Bluetooth devices quickly and effectively, user can set the module to be non-standard Bluetooth device type, such as 0x1F1F (Hex).
Example

AT+IAC?

UsageInquire “inquire access code”
Response+IAC: ****
OK
Parameter
NotesDefault: 9e8b33
ExampleAT+IAC?
+IAC: 9e8b3f
OK

AT+IAC=Param1

UsageSet “inquire access code”
ResponseIf Success:
OK
If Failure:
FAIL
ParameterParam1: Inquire access code
NotesAccess code is set to be GIAC type (General Inquire Access Code:0x9e8b33), and used for seeking ( or being sought by ) all the Bluetooth devices around. For inquiring (or being inquiring by) the custom Bluetooth device from around Bluetooth devices quickly and effectively, user can set the inquire access code to be the other type number (not GIAC nor LIAC), such as 9e8b3f.
ExampleAT+IAC=9e8b3f
OK

AT+INQM?

UsageInquire inquire access mode
Response+INQM:***,***,***
OK
Parameter
NotesOutput is in the format: Inquire access mode, the maximum of Bluetooth devices response, the maximum of limited inquiring time
Default: 1, 1, 48
ExampleAT+INQM
+INQM:1, 9, 48
OK

AT+INQM=Param1, Param2, Param3

UsageSet inquire access mode
ResponseIf Success:
OK
If Failure:
FAIL
ParameterParam1: Inquire access mode: 0 -> Standard 1 -> RSSI
Param2: The maximum of Bluetooth devices response
Param3: The maximum of limited inquiring time
NotesThe range of limited time: 1~48 (Corresponding time:1.28s~61.44s)
ExampleSet Inquire access mode such that: 1) has RSSI signal intensity indicator, 2) stop inquiring once more than 9 devices response, 3) limited time is 48*1.28=61.44s:
AT+INQM=1,9,48
OK

AT+PSWD?

UsageInquire passkey
Response+PSWD:****
OK
Parameter
NotesDefault: “1234”
ExampleAT+PSWD?
+PSWD:1234
OK

AT+PSWD=Param1

UsageSet passkey
ResponseOK
ParameterParam1: Passkey
Notes
ExampleAT+PWD=1234 (or AT+PSWD=”1234″)
OK

AT+UART?

UsageInquire serial parameter
Response+UART=****, ****, ****
OK
Parameter
NotesOutput is in the format: Baud rate, Stop bit, Parity bit
Default: 9600, 0, 0
ExampleAT+UART?
+UART:115200,1,2
OK

AT+UART=Param1, Param2, Param3

UsageSet serial parameter
Response+UART=Param1, Param2, Param3
OK
ParameterParam1: Baud rate:
4800 -> 4800 bits/s
9600 -> 9600 bits/s<br 19200 -> 19200 bits/s
38400 -> 38400 bits/s
57600 -> 57600 bits/s
115200 -> 115200 bits/s
230400 -> 230400 bits/s
460800 -> 460800 bits/s
921600 -> 921600 bits/s
1382400 -> 1382400 bits/s

Param2: Stop bit:
0 -> 1 bit
1 -> 2 bits

Param3: Parity bit:
0 -> None
1 -> Odd parity
2 -> Even parity
Notes
ExampleSet baud rate to be 115200, stop bit to be 2 bits, parity bit to be even parity:
AT+UART=115200,1,2
OK

AT+CMODE?

UsageInquire connection mode
Response+CMODE:****
OK
Parameter
NotesResult is a number where:
0 (Default) -> Connects the module to the specified Bluetooth address
1 -> Connects the module to any address
2 -> Slave-Loop
ExampleAT+CMODE?
+CMODE:2
OK

AT+CMODE=Param1

UsageSet connection mode
ResponseOK
ParameterParam1: Connection mode:
0 -> Connect the module to the specified Bluetooth address.
1 -> Connect the module to any address
2 -> Slave-Loop
Notes
ExampleAT+CMODE=2
OK

AT+BIND?

UsageInquire – bind Bluetooth address
Response+BIND:****
OK
Parameter
NotesBluetooth address will be shown as: NAP: UAP:LAP(Hexadecimal)
ExampleAT+BIND?
+BIND:1234:56:abcdef
OK

AT+BIND=Param1

UsageSet – bind Bluetooth address
ResponseOK
ParameterParam1: Bluetooth address: needed to be bind
NotesWhen writing the address, you must use commas rather than colons.
ExampleAT+BIND=1234,56,abcdef
OK

AT+POLAR?

UsageInquire – drive indication of LED and connection status
Response+POLAR=****, ****
OK
Parameter
NotesOutput is in the format: PI08 mode, PI09 mode
Default: 1, 1
ExampleAT+POLAR?
+POLAR=0, 1
OK

AT+POLAR=Param1, Param2

UsageSet – drive indication of LED and connection status
ResponseOK
ParameterParam1: PI08 mode:
0 -> PI08 outputs low level and turn on LED
1 -> PI08 outputs high level and turn on

Param2: PI09 mode:
0 -> PI09 output low level indicate successful connection
1 -> PI09 output high level indicate successful connection
Notes
ExamplePI08 outputs low level and turn on LED, PI09 outputs high level and indicates successful connection:
AT+POLAR=0, 1
OK

AT+PIO=Param1, Param2

UsageSet PIO single port output
ResponseOK
ParameterParam1: PIO port number(Decimal):
Param2: PIO port status:
0 -> low level
1 -> high level
NotesHC-05 Bluetooth module provides the user with the ports (PI00~PI07 and PI010) which can extern another input and output ports.
Example1. PI010 port outputs high level:
AT+PI0=10, 1
OK

2. PI010 port outpust low level:
AT+PI0=10, 0
OK

AT+MPIO=Param1

UsageSet PIO multiple port output
ResponseOK
ParameterParam1: Mask combination of PIO ports number (Decimal)
Notes(1) Mask of PIO port number = (1<<port number)
(2) Mask combination of PIO ports number= (PIO port number mask 1|PIO port numbermask 2|……)

Example :
PI02 port number mask=(1<<2) =0x004
PI010 port number mask =(1<<10)=0x400
Mask combination of PI02 and PI010 port number=(0x004|0x400)=0x404
Example1. PI010 and PI02 ports output high level:
AT+MPI0=404
OK
2. PI04 port output high level:
AT+PI0=004
OK
3. PI010 port output high level:
AT+PI0=400
OK
4. All ports output low level:
AT+MPI0=0
OK

AT+MPIO?

UsageInquire PIO port input
Response+MPIO:****
OK
ParameterParam1: PIO port value (16bits)
Param[0]=PI00
Param[1]=PI01
Param[2]=PI02

Param[10]=PI010
Param[11]=PI011
Notes
Example

AT+IPSCAN?

Usage Inquire page scan and inquire scan parameter
Response+IPSCAN:****, ****, ****, ****
OK
Parameter
NotesOutput is in the format: time interval of inquiring, duration in inquiring, time interval of paging, duration in paging
Default:1024,512,1024,512
ExampleAT+IPSCAN?
+IPSCAN:1234,500,1200,250
OK

AT+IPSCAN=Param1, Param2, Param3, Param4

Usage Set page scan and inquire scan parameter
ResponseOK
ParameterParam1:time interval of inquiring
Param2: duration in inquiring
Param3: time interval of paging
Param4: duration in paging
Notes
ExampleAT+IPSCAN=1234,500,1200,250
OK

AT+SNIFF?

UsageInquire—SNIFF energy parameter
Response+SNIFF:****, ****, ****, ****
OK
Parameter
NotesOutput is in the format: maximum time, minimum time, test time, limited time
Default : 0,0,0,0
Example

AT+SENM?

Usage Inquire safe and encryption mode
Response+SENM:****, ****
OK
Parameter
NotesOutput is in the format: the value of safe mode, the value of encryption mode
Default : 0,0
Example

AT+SENM=Param1, Param2

Usage Set safe and encryption mode
ResponseIf Success:
OK
If Failure:
FAIL
ParameterParam1: the value of safe mode:
0 -> sec_mode0+off
1 -> sec_mode1+non_secure
2 -> sec_mode2_service
3 -> sec_mode3_link
4 -> sec_mode_unknown

Param2: the value of encryption mode:
0 -> hci_enc_mode_off
1 -> hci_enc_mode_pt_to_pt
2 -> hci_enc_mode_pt_to_pt_and_bcast
Notes
Example

AT+RMSAD=Param1

UsageDelete authenticated device in the Bluetooth pair list
ResponseOK
ParameterParam1: Bluetooth device address
Notes
ExampleAT+RMSAD=1234,56,abcdef
OK | FAIL

AT+RMAAD

UsageDelete all authenticated devices in the pair list
ResponseOK
Parameter
Notes
ExampleAT+RMAAD
OK

AT+FSAD=Param1

UsageSeek the authenticated device in the Bluetooth pair list
ResponseIf Success:
OK
If Failure:
FAIL
ParameterParam1: Bluetooth device address
Notes
ExampleAT+FSAD=1234,56,abcdef
OK | FAIL

AT+ADCN?

UsageGet the authenticated device count from the pair list
Response+ADCN:****
OK
Parameter
Notes
ExampleAT+ADCN?
+ADCN:0
OK

AT+MRAD?

UsageGet the Bluetooth address of Most Recently Used Authenticated Device
Response+MRAD:****
OK
Parameter
Notes
ExampleAT+MRAD?
+MRAD:0:0:0
OK

AT+STATE?

UsageGet the work status of Bluetooth module
Response+STATE:****
OK
Parameter
NotesResult can be one of the following:
“INITIALIZED” -> initialized status
“READY” -> ready status
“PAIRABLE” -> pairable status
“PAIRED” -> paired status
“INQUIRING” -> inquiring status
“CONNECTING” -> connecting status
“CONNECTED” -> connected status
“DISCONNECTED” -> disconnected status
“NUKNOW” -> unknown status
ExampleAT+STATE?
+STATE:INITIALIZED
OK

AT+INIT

UsageInitialize the SPP profile lib
ResponseIf Success:
OK
If Failure:
FAIL
Parameter
Notes
ExampleAT+INIT
OK

AT+INQM?

UsageInquire Bluetooth device
Response+INQ:****
+INQ:****

OK
Parameter
NotesEvery result is in the form: +INQ:Bluetooth address, Device type, RSSI signal intensity
ExampleAT+INQ
+INQ:2:72:D2224,3E0104,FFBC
+INQ:1234:56:0,1F1F,FFC1
+INQ:1234:56:0,1F1F,FFC0
OK

AT+PAIR=Param1, Param2

UsageSet pair
ResponseIf Success:
OK
If Failure:
FAIL
ParameterParam1: Bluetooth address of remote device
Param2: limited time of connection (second)
Notes
ExampleMake pair with the remote Bluetooth device(address:1234:56:abcdef), the limited time is 20s:
AT+PAIR=1234,56,abcdef,20\r\n
OK
UsageConnect device
ResponseIf Success:
OK
If Failure:
FAIL
ParameterParam1: Bluetooth address of remote device
Notes
ExampleConnect with the remote Bluetooth device (address: 1234:56:abcdef): AT+FSAD=1234,56,abcdef
OK
AT+LINK=1234,56,abcdef
OK

AT+DISC

UsageDisconnection
ResponseIf Successful Disconnection:
+DISC:SUCCESS
OK
If Lose the connection:
+DISC:LINK_LOSS
OK
If No SLC connection:
+DISC:NO_SLC
OK
If Disconnection Timeout:
+DISC:TIMEOUT
OK
If Disconnection Error:
+DISC:ERROR
OK
Parameter
Notes
Example

AT+ENSNIFF=Param1

UsageEnter to energy mode
ResponseOK
ParameterParam1: Bluetooth address of device
Notes
Example

AT+EXSNIFF=Param1

UsageExit energy mode
ResponseOK
ParameterParam1: Bluetooth address of device
Notes
Example