The Bluetooth module HC-05 is a MASTER/SLAVE module.The Role of the module (Master or Slave) can be configured only by AT COMMANDS.
By default the factory setting is SLAVE.
This post walks you through the AT commands of Bluetooth module .Through AT Commands you can change the ROLE of the module. Name,Password of the Module can be changed .The list of AT commands can be downloaded HERE
Remember the models HC-04 or HC-06 are SLAVE only modules .HC-05 is the module of interest in this post.To identify the model you can see the pin count.If the module has 5 or 6 pins it is HC-05.If the module has only 4 pins then it is HC-04 or HC-06.
The firmware for HC04 is LINVOR & for the HC05 it is HC05 itself.If you scan for bluetooth devices from your Android phone you can see this name.
The extra pins in HC-05 are the KEY & STATE pins.The KEY pin is used to enter the Command mode.
HC05 Pin count is 6 MASTER/SLAVE HC-04 Pins 4 SLAVE ONLY
The slave modules can not initiate a connection to another Bluetooth device, but can accept connections.Master module can initiate a connection to other devices. Be sure not to make the mistake of buying 2 slaves (HC-04) .
To enter the Command mode you can either use an USB TO TTL Module or your Arduino UNO board.
USB TO TTL DEVICE ARDUINO UNO
First let me explain how to use the Arduino board for the configuration.We need to use the USB – UART portion of the Arduino board bypassing the bootloader function of ATMEGA328.For this connect the Arduino to PC & just upload an empty sketch
————————–
void setup()
{
}
void loop()
{
}
————————–
Connect Rx (pin 0) of Arduino to Rx of Bluetooth module.
Tx (pin1) of Arduino to Tx of Bluetooth module.
Yes,I’m correct.The connection is one to one while using Arduino as USB-UART board.It is not the other way (Tx to Rx while using USB-TTL board).
Before connecting the power to HC05 module you should know that there are there are two ways of activating command mode on these devices.
One is to hold pin 34 high (KEY) as the device is powered on and it should enter command mode at 38400,8,N,1
The other is to hold pin 34 low then set it high after the module has been powered on and it will enter command mode at the pre-programmed speed (default is 9600,8,N,1).
Let us complete all the connections and finally provide power to the module.
HC-05 ARDUINO
Tx –—> Tx (1)
Rx –—> Rx (0)
Vcc ––> 5v
GND –-–> GND,
KEY –—> 3.3V
Now provide the power to the module by connecting USB cable to Arduino
The Status LED starts blinking slowly (once per 2 secs).This indicates that the module has entered the command mode at the BAUD RATE 38400.
You can use the SERIAL Monitor of the Arduino to feed AT commands.
At the bottom of the SERIAL monitor ensure that you select “BOTH NL & CR” .This will feed /r/n after each command.Generally while using Arduino ,the println() statement), appends both carriage return and newline .(In case of PIC or 8051 you should add terminator ( “0x0d 0x0a”) to the program.)
HC 05 module needs a CARRIAGE RETURN & LINE FEED after each command .
Now open the Serial monitor of Arduino with settings BOTH NL & CR , Baud Rate 38400
Type in AT & click on Send.
You should get a OK response from the module.
The default ROLE of HC-05 is SLAVE .To change this to MASTER type in
AT+ROLE = 1
The module responds with OK.
To confirm , type in AT+ROLE ?
The module will reply the status as ROLE 1.
You can also use a Terminal software like TERATERM to feed the AT Commands.
Close the Serial monitor of Arduino & then start the TERATERM terminal.
Select Serial at the start up window of TERATERM.
Under SETUP –> Terminal select CR+LF of Transmit & tick mark the LOCAL ECHO (to see what you type)
Under SETUP –> SERIAL PORT select the BAUDRATE 38400 , 8N1
Now you are ready to feed the AT commands.
To query a condition like Name, Password ,etc. you need to use a ? question mark after the command.
To change the condition use the equal to mark = after the command.
For e.g to query about password you type in AT+PSWD?
To change the password you type in AT+PSWD=1234
In the next post we shall see how to pair 2 nos. HC-05 modules so that it can replace the physical Serial connection.This can be an alternative to ZIGBEE , but with less range and more data speed (2Mbps).