Search

Mastering AT Commands for HC-05 Configuration

Those who experiment with the HC-05 Bluetooth module will inevitably need to employ a set of commands known as “AT commands.” AT commands are uncomplicated, text-based instructions prefixed with “AT” (where “AT” stands for ‘attention’). These commands share similarities with those utilized in older modem devices. By transmitting specific AT commands to the HC-05 module, you can customize its settings or retrieve fundamental information, such as its name, baud rate, PIN code, role, and more.

This guide will teach you how to configure the HC-05 AT commands, allowing you to tailor the module to meet the specific requirements of your project.

Configuring the HC-05 Module

To configure the HC-05 module, you need to enter command mode and transmit AT commands through the UART port. In command mode, any ASCII bytes you transmit are treated as commands. Once modifications are made, you must restart the module to implement the changes. The altered configuration parameters persist until you modify 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 connecting the HC-05 module to a PC, you have two options to choose from.

Option 1 involves using a USB to TTL converter, creating a direct link 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 understood by the HC-05 module.

Alternatively, you can employ an Arduino as an intermediary between the PC and the HC-05 module. In this configuration, the Arduino acts as a translator, facilitating the exchange of commands and data between the PC and the HC-05 module.

Using a USB to TTL Converter

Let’s establish a connection between your HC-05 module and your PC using a USB to TTL converter.

To set up the connection, apply power and wire the serial Rx and Tx pins. Connect the Tx of the HC-05 module to the converter’s RXD, the Rx to TXD, GND to GND, and VCC to 5V.

It’s crucial to note that the Rx pin on the HC-05 module is not 5V tolerant. Therefore, if you are using a USB-to-TTL converter operating at 5V I/O levels, you need to reduce the Tx signal from the converter to 3.3V. A simple method is to use a resistor divider: a 1K resistor between HC-05’s Rx and the converter’s TXD, and a 2K resistor between HC-05’s Rx and GND.

In summary, here 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.

Using Arduino

Similarly, you can establish a connection between the HC-05 Module and an Arduino. Connect the TXD of the HC-05 module to Arduino’s D1, the RXD to D0, GND to GND, and VCC to 5V.

Once again, it’s crucial to note that the Rx pin on the HC-05 module is not 5V tolerant. Therefore, if you are using a 5V microcontroller like Arduino UNO, you must lower the Tx signal from the Arduino to 3.3V using a resistor divider. Specifically, a 1K resistor between HC-05’s Rx and Arduino’s D0, along with a 2K resistor between HC-05’s Rx and GND, will function effectively.

To summarize, here 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.

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

Parts Required

Component NameBuy Now
Arduino Uno REV3Amazon
HC-05 Bluetooth Serial Pass-through Module Wireless Serial Communication with Button for ArduinoAmazon
BreadboardAmazon
BOJACK 1000 Pcs 25 Values Resistor Kit 1 Ohm-1M Ohm with 5% 1/4WAmazon
Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

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 issue AT commands, you’ll need a Windows terminal program installed on your PC capable of communicating with the HC-05 module over UART. We recommend using the “Arduino Serial Monitor” for this purpose, but there are other free alternatives (such as PuTTY, Tera Term, etc.) that you can explore.

Here’s a step-by-step guide:

Launch the Arduino IDE.

Ensure the HC-05 module is powered up and in AT mode, indicated by the onboard LED blinking at a slow and steady rate.

When you connect the HC-05 to your PC, it will be recognized as a COM port. Check your device manager under the “Ports (COM & LPT)” tree for the new port.

In the Arduino IDE, go to Tools > Port and select the identified COM port.

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

Type “AT” (without quotes) in the textbox at the top of the Serial Monitor and click the Send button. A successful communication will display “OK” as a response from the module.

You can now send various commands to gather information about your module. For instance:

  • AT+VERSION? – Prints the software version.
  • AT+NAME? – Prints the device’s name.
  • AT+ PSWD? – Prints the passkey.

These are Read Commands. Additionally, you can send Write Commands like:

  • AT+NAME=Param1 – Sets the device’s name to Param1. Note that the device name can be up to 32 bytes long and may 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:
FAILv
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?

UsageInquire 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

UsageSet 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?

UsageInquire 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

UsageSet 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

Related article

Leave a Comment