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.
Components Required –
1. Arduino Pro Mini
2. HC-05 Bluetooth Module
3. Desktop Computer or Laptop
4. USB Cable
Software Tools Required –
1. Arduino IDE
2. Any Hyper Terminal Desktop Application like Arduino Serial Monitor
Circuit Connections –
Fig. 1: Prototype of Arduino based Bluetooth AT Commands Test Project
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 the following way –
Power Supply – The circuit is powered by a battery which directly supplies to the Arduino board and the Bluetooth module.
HC-05 Bluetooth Module – HC-05 Bluetooth module is serial port protocol module. It operates on ISM band 2.4GHz with V2.0+EDR (Enhanced data rate). It can work in both 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 pin are unused and so not connected in the circuit. The VCC and Ground pins are connected to the common VCC and Ground. The TxD and RxD pins of the module are connected to the pins 10 and 11 of the Arduino Pro Mini respectively. These connections are summarized in the table below –
Fig. 2: Table listing circuit connections between Arduino Pro Mini and HC-05 Bluetooth Module
Apart from these connections, the 34th pin of the module is wired to the pin 9 of the Arduino Pro Mini.
Desktop Computer – The computer is connected to the Arduino board through USB cable and transfers serial data to the board through Virtual serial communication using a hyper terminal application.
How the project works –
The project device receives the user entered AT commands from the hyper terminal application. The commands are serially read over virtual serial communication and passed to the Bluetooth module. The Bluetooth module responds to the AT commands and the responses are again serially read and transferred to the desktop application.
First of all, the AT command to change the name of the Bluetooth module was tested. Most of the modules come with a default name. Like the module used during testing had a name – h-C-2010-06-01. Many modules can have the same name. By using AT commands, any user-defined name can be assigned to the module. Like if there are many modules, they can be assigned names like Bluetooth 1, Bluetooth 2, Bluetooth 3 etc. During testing, the name of the module was changed to Engineers Garage.
First the current module name was verified by passing following command –
AT+NAME
For which the response received was as follows –
AT+NAME = +NAME:h-C-2010-06-01
Then the new name was assigned to the module by passing the following command –
AT+NAME = ENGINEERS GARAGE
To verify the change of name, again following command was sent –
AT+NAME?
For which the response received was as follows –
AT+NAME = ENGINEERS GARAGE
For checking current password, following command was passed –
AT+PSWD
For 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 change of password, again following command was sent –
AT+PSWD?
For which the response received was as follows –
+PSWD=996696
For checking current role of the module, following command was passed –
AT+ROLE
For which the response received was as follows –
+ROLE:0
Then the new role was assigned to the module by passing the following command –
AT+ROLE=1
To verify the change of device role, again following command was sent –
AT+ROLE?
For which the response received was as follows –
+ROLE=1
The Bluetooth module can have two roles – slave or master. Setting the role to 0 makes the device slave while setting the role to 1 makes the device master.
Finally, the baud rate was changed. For checking the current baud rate, following command was passed –
AT+UART
For which the response received was as follows –
AT+UART = 38400,0,0
To change the baud rate, following command was passed –
AT+UART=9600,1,0
To verify the changed baud rate, following command was passed –
AT+UART?
For 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.
So during testing of the AT commands following control parameters were changed –
Fig. 3: Table listing AT commands of HC-05 Bluetooth Module and changes in their default settings
The AT commands for changing 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 following AT command should be passed –
AT+ORGL?
These responses were observed on the Hyper Terminal Application. If the responses are not received on the desktop application, the circuit connections should be checked and baud rate must be verified. The baud rate of the software serial port and the Bluetooth module should be same to enable running the AT commands.
Programming Guide –
The Arduino sketch manages the data communication between the computer and the Bluetooth module. For enabling virtual serial communication, SoftwareSerial.h needs to be imported. An object of Software serial type is instantiated and mapped to Arduino pins 10 and 11.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
The setup() function is called in which the baud rate for communication with the PC is set to 9600 bits per second. The pin 9 which is connected to the 34th pin of the Bluetooth Module is set to digital output and set to HIGH logic using pinMode() and digitalWrite() methods. Some initial messages are sent serially to the hyper terminal application and baud rate of the software serial port is set to 38400 bits per second for communication with the Bluetooth module.
void setup() {
Serial.begin(9600);
pinMode(9,OUTPUT); digitalWrite(9,HIGH);
Serial.println(“Engineers Garage:”);
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. Similarly, if any AT command from the desktop is available, it is read and written to the Bluetooth module.
void loop().
Note: Refer to the code section for complete coding.
This completes the Arduino sketch for the Bluetooth Module Configuration Project. Get a computer, assemble the circuit, launch a hyper terminal application and get hands dirty. It’s time to personalize your module.
You may also like:
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()); } ###
Project Video
Filed Under: Electronic Projects
Filed Under: Electronic Projects
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.