Using AT Commands To Set Up Your Bluetooth Module : HC-05 And ...

This sketch takes any data you send to it from the serial monitor inside the Arduino IDE and passes it straight out to the Bluetooth module. Any data coming back from the Bluetooth module is simply relayed back to the serial monitor. In this way, we can type commands into our serial monitor, have those executed on the Bluetooth module, and then see the results back on screen.

AT Commands for the Bluetooth Modules

These Bluetooth modules can be controlled through a series of AT commands. This technique is common to a large number of serial devices. Before the module will respond these commands it needs to be put in to AT mode. The HC-06 module is always in AT mode but the HC-05 modules need to be powered on with their small pushbutton held in.

Once the module is in AT mode we can start to send commands.

If you type AT into your serial terminal and press send you should see your Bluetooth module respond with an OK. If not make sure your serial terminal is connected to the same COM port as your Arduino and that the baud settings for both the Arduino to Bluetooth module and Arduino to PC connections are correct. If you haven’t yet changed any settings on the Bluetooth module it will be working at 9600 baud.

If you then type AT+VERSION and send that the Bluetooth module it should respond with the current version of the software it’s running.

What Settings Should You Change on Your Bluetooth Module?

The default serial speed is that the 9600 Baud. This is quite slow so it’s worth increasing that. The maximum you can set it to on an Arduino Uno is 115200. Don’t forget that once you change the baud rate you need to adjust the Arduino sketch and set the Arduino to Bluetooth module data rate to the correct value.

The Bluetooth modules broadcast name should be set the something sensible for your project. This is entirely up to you but it will help you identify your device when you try to pair with it.

Bluetooth devices use a four-digit pin as security when pairing. The modules use a default value of 1234 so you need to change this to make sure other people cannot pair with your Bluetooth module.

The AT commands we used to change the settings are different for each device so you’ll need to use the table below for your module.

HC-05 AT Commands

AT Check connection

AT+VERSION? Get software version

AT+RESET Reset the Bluetooth module back to data mode. This does not reset the settings.

AT+UART=SPEED,STOP,PARITY Set the baud rate and serial parameters between the Arduino and Bluetooth module. Replace SPEED with a value from below.

4800 = 4800 bps 9600 = 9600 bps 19200= 19200 bps 38400 = 38400 bps 57600 = 57600 bps 115200 = 115200 bps

STOP tells the module how many stop bits to send.

0 = 1 bit (Default) 1 = 2 bits

PARITY tells the module what parity to use.

0 = None (Default) 1 = Odd 2 = Even

So to set the baud rate to 115200 baud you would send the command,

AT+UART=115200,0,0

AT+NAME=XXXXXX Set the Bluetooth broadcast name for the module. Replace the Xs with the name you want to use. Make sure you don’t put any spaces between the AT+NAME, =,  and your desired broadcast name. For example, to set the broadcast name to My Project you would send the command,

AT+NAME=My Project

AT+PSWD=XXXX Set the Bluetooth pairing password to a four-digit PIN. Replace the Xs with the four-digit pin you want to use. For example, AT+PSWD=4321

HC-06 AT Commands

AT Check connection

AT+VERSION Get software version

AT+BAUDX Set the baud rate between the Arduino and Bluetooth module. Replace the X with a value from below.

1 = 1200 bps 2 = 2400 bps 3 = 4800 bps 4 = 9600 bps 5 = 19200 bps 6 = 38400 bps 7 = 57600 bps 8 = 115200 bps

So to set the baud rate to 115200 baud you would send the command,

AT+BAUD8

AT+NAMEXXXXXX Set the Bluetooth broadcast name for the module. Replace the Xs with the name you want to use. Make sure you don’t put a space between the AT+NAME and your desired broadcast name. For example, to set the broadcast name to My Project you would send the command,

AT+NAMEMy Project

AT+PINXXXX Set the Bluetooth pairing password to a four-digit PIN. Replace the Xs with the four-digit pin you want to use. For example, AT+PIN4321

Tag » Arduino Hc-06 At Commands