- Configuring Bluetooth module using AT commands
- Adding Bluetooth to Your Arduino Projects
- Using Your Arduino As a Serial Terminal
- Code for Bluetooth Terminal Test
- Where to Get Your Bluetooth Modules
- AT Commands for the Bluetooth Modules
- What Settings Should You Change on Your Bluetooth Module?
- HC-05 AT Commands
- HC-06 AT Commands
Configuring Bluetooth module using AT commands
In the previous project, how Bluetooth module can be configured to operate in Order Response Work Mode was discussed. The previous project also detailed the AT commands available for the HC-05 Bluetooth module. The AT commands can only be used in Order Response Work Mode. The AT commands are very useful and can be used to change or set multiple control parameters of the module. In this project, some of the AT commands will be used and tested. The project will demonstrate using AT commands to change device name, password, mode and baud rate of the module. In the end of the demonstration, the default settings will be restored using the AT commands.
The circuit used for testing AT commands is similar to the circuit in the previous project. The Bluetooth module is interfaced to an Arduino Pro Mini and the Arduino board is connected to a computer. The AT commands are passed to the Arduino board through a hyper terminal application which is further passed to Bluetooth module serially by the Arduino board. The responses from the Bluetooth module are in turn serially read by the Arduino board and passed to the Hyper Terminal application for display on the desktop.
The Arduino Pro Mini manages to send AT commands and send back responses by controlling serial communication between the Bluetooth module and the computer. The Arduino sketch for this is written on Arduino IDE and burnt to the board using AVR Dude.
Adding Bluetooth to Your Arduino Projects
Bluetooth modules such as the HC-05 and HC-06 provide an easy way to add Bluetooth connectivity to your Arduino project. These modules arrive set up and ready to go with default settings for their connection speed to your Arduino, Bluetooth broadcast name, and Bluetooth pin number. You can use them as they are but is much better to customise the module’s settings to customise and secure your project. I’ve covered how to connect the module to your Arduino in a previous video so please have a look here to get started. Once you’ve got the Bluetooth module connected to your Arduino we can use the Arduino as a serial terminal to talk directly to the Bluetooth module.
Using Your Arduino As a Serial Terminal
Code for Bluetooth Terminal Test
Where to Get Your Bluetooth Modules
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