In the previous project, it was discussed how the Bluetooth module can be configured to operate in the request response working mode. The previous project also detailed the AT commands available for the HC-05 Bluetooth module. AT commands can only be used in Request Response Work Mode. AT commands are very useful and can be used to change or set various module control parameters. In this project, some of the AT commands will be used and tested. The project will demonstrate the use of AT commands to change the device name, password, mode, and baud rate of the module. At the end of the demonstration, default settings will be restored using AT commands.
The circuit used to test AT commands is similar to the circuit in the previous project. The Bluetooth module is interfaced with an Arduino Pro Mini and the Arduino board is connected to a computer. AT commands are passed to the Arduino board via a hyperterminal application which is later passed to the Bluetooth module serially by the Arduino board. Responses from the Bluetooth module are in turn read serially by the Arduino board and passed to the Hyper Terminal application for display on the desktop.
The Arduino Pro Mini can send AT commands and return responses by controlling serial communication between the Bluetooth module and the computer. The Arduino sketch for this was written in the Arduino IDE and burned to the board using the AVR Dude.
Required components –
1. Arduino ProMini
2. HC-05 Bluetooth Module
3. Desktop or Laptop Computer
4. USB cable
Required software tools –
1. ArduinoIDE
2. Any Hyper Terminal Desktop application such as Arduino Serial Monitor
Circuit Connections –
Figure 1: Arduino-based Bluetooth AT command test project prototype
The Arduino Pro Mini manages the exchange of data between the serial application on the desktop computer and the Bluetooth module. The circuit is assembled as follows –
Power supply – The circuit is powered by a battery that directly powers the Arduino board and the Bluetooth module.
HC-05 Bluetooth Module – The HC-05 Bluetooth module is a serial port protocol module. Operates in the 2.4 GHz ISM band with V2.0 + EDR (Enhanced Data Rate). It can work in Master and Slave modes. The Bluetooth module has six pins – Enable, VCC, Ground, Transmit Data (TxD), Receive Data (RxD) and State. The Enable and State pins are unused and therefore not connected to the circuit. The VCC and Ground pins are connected to common VCC and Ground. The TxD and RxD pins of the module are connected to pins 10 and 11 of the Arduino Pro Mini respectively. These connections are summarized in the table below –
Fig. 2: Table listing the circuit connections between the Arduino Pro Mini and the HC-05 Bluetooth Module
In addition to these connections, the 34th pin of the module is connected to pin 9 of the Arduino Pro Mini.
Desktop Computer – The computer is connected to the Arduino board via a USB cable and transfers serial data to the board via virtual serial communication using a hyperterminal application.
How the project works –
The project device receives the AT commands entered by the user of the hyperterminal application. Commands are read serially by virtual serial communication and passed to the Bluetooth module. The Bluetooth module responds to AT commands and the responses are again read serially and transferred to the desktop application.
Firstly, the AT command was tested to change the name of the Bluetooth module. Most modules come with a default name. Just like the module used during the test had a name – hC-2010-06-01. Many modules can have the same name. When using AT commands, any user-defined name can be assigned to the module. As if there are many modules, they can be given names like Bluetooth 1, Bluetooth 2, Bluetooth 3 etc. During testing, the module name was changed to Engineers Garage.
First, the current module name was checked by passing the following command –
AT+NAME
To which the response received was as follows –
AT+NAME = +NAME:hC-2010-06-01
Then the new name was assigned to the module by passing the following command –
AT+NAME = ENGINEERS GARAGE
To check the name change, again the following command was sent –
AT+NAME?
To which the response received was as follows –
AT+NAME = ENGINEERS GARAGE
To check the current password, the following command was passed –
AT+PSWD
To which the response received was as follows –
AT+PSWD = +PSWD:1234
Then the new password was assigned to the module by passing the following command –
AT+PSWD=996696
To verify the password change, again the following command was sent –
AT+PSWD?
To which the response received was as follows –
+PSWD=996696
To check the current function of the module, the following command was passed –
AT+PAPER
To which the response received was as follows –
+PAPER:0
Then, the new function was assigned to the module by passing the following command –
AT+PAPER=1
To check the change in device function, again the following command was sent –
AT+PAPER?
To which the response received was as follows –
+PAPER=1
The Bluetooth module can have two functions – slave or master. Setting the function to 0 makes the device slave, while setting the function to 1 makes it the master device.
Finally, the baud rate was changed. To check the current baud rate, the following command was passed –
AT+UART
To which the response received was as follows –
AT+UART = 38400,0,0
To change the baud rate, the following command was passed –
AT+UART=9600,1,0
To check the changed baud rate, the following command was passed –
AT+UART?
To which the response received was as follows –
+UART=9600,1,0
In the AT+UART command, the first parameter is the baud rate for serial communication, the second parameter is the stop bit which is set to a single bit if 0 is passed and set to 2 bits if 1 is passed and the third parameter is parity bit which can be set to 0 or 1.
Therefore, during testing of AT commands, the following control parameters were changed –
Fig. 3: Table listing the AT commands of the HC-05 Bluetooth Module and changes to their default settings
The AT commands to change these control parameters are summarized in the table below –
Fig. 4: Table listing AT commands for changing control parameters
To restore, the default settings of the Bluetooth module after the AT command must be passed –
AT+ORGL?
These responses were observed in the Hyper Terminal application. If responses are not received in the desktop application, the circuit connections must be checked and the transmission rate must be verified. The baud rate of the software serial port and the Bluetooth module must be the same to allow AT commands to be executed.
Programming guide –
The Arduino sketch manages data communication between the computer and the Bluetooth module. To enable virtual serial communication, SoftwareSerial.h needs to be imported. A Software serial type object is instantiated and mapped to pins 10 and 11 of the Arduino.
#include
SoftwareSerial mySerial(10, 11); //RX,TX
The setup function is called and the baud rate for communicating with the PC is set to 9600 bits per second. Pin 9 which is connected to the 34th pin of the Bluetooth Module is configured for digital output and set to logic HIGH using the pinMode and digitalWrite methods. Some initial messages are sent serially to the hyperterminal application and the software serial port baud rate is set to 38,400 bits per second for communication with the Bluetooth module.
empty configuration {
Serial.begin(9600);
pinMode(9,OUTPUT); digitalWrite(9,HIGH);
Serial.println(“Engineers Workshop:”);
Serial.println(“Enter AT commands:”);
mySerial.begin(38400);
}
The loop function is called in which the response from the Bluetooth module is checked and, if available, is written to the serial port. Likewise, if any desktop AT commands are available, they will be read and written to the Bluetooth module.
empty loop.
Note : See the code section for complete coding.
This completes the Arduino sketch for the Bluetooth module setup project. Take a computer, assemble the circuit, start a hyperterminal application and get your hands dirty. It's time to customize your module.
Project source code
###
//Program to #includeSoftwareSerial mySerial(10, 11); // RX, TX void setup { Serial.begin(9600); pinMode(9,OUTPUT); digitalWrite(9,HIGH); Serial.println("Engineers Garage:"); Serial.println("Enter AT commands:"); mySerial.begin(38400); } void loop { if (mySerial.available ) Serial.write(mySerial.read ); if (Serial.available ) mySerial.write(Serial.read ); } ###