Wednesday, March 9, 2016

Bluetooth HC-05 module

Hi there! I bought a HC-05 bluetotth module and am writing a few lines because it is quite different to manage when compared with the previous HC-06 (which is quite easier). So, let's see:
On HC-06 to enter AT mode you just have to connect to the device before it synchronizes with a BT device. HC-05 needs the KEY or EN or ENABLE or WAKEUP pin to be connected to VCC (3.6 - 6V). An other way to achieve the AT mode is to press the available push-button to 'on' while booting the device, though this will lead to "mini" AT mode instead of "full" AT mode, and in "mini" mode not all AT commands might work.
So, let's see a list of the PINOUT:

KEY/EN: This pin has to be pulled high to enter "full" AT mode;
VCC: Indicated within a range of 3.6 to 6 volt;
GND: Ground;
RXD: Serial input pin;
TXD Serial output pin;
STATE: It's an output pin that can be connected to a LED (with a resistor) which will light up when a BT device is synchronized with the HC-05.

 Then, the console should be configured at 38400 baud (HC-05 default) and change "no line ending " to "both NL & CR".
With the console working type "AT" (without the quotes) on the serial monitor and press enter. if "OK" appears then everything is all right and the module is ready to take command. Now you can change the name of the module, retrieve address or version or even reset to factory settings. To see the default name, type AT+NAME. The name will be prompted, by default it is HC-05. To change the name just type AT+NAME=desired_name.
Important note: if the key pin is not high, (not connected to Vcc while receiving AT commands), it will not show the default name even after giving the correct command. You can still change the name by the command mentioned above. To verify if the name has really changed, search the device using your pc/mobile. The changed name will appear.
To change baud rate, type AT+UART=desired_baud_rate. Exiting AT mode will work by sending AT+RESET command.

Some useful HC-05 AT commands:
AT : Check the connection;
AT+NAME : See default name;
AT+ADDR : See default address;
AT+VERSION : See version;
AT+UART : See baudrate;
AT+ROLE: See role of bt module(1=master/0=slave);
AT+RESET : Reset and exit AT mode;
AT+ORGL : Restore factory settings;
AT+PSWD: See default password;
More detailed AT commands are given in the 1st pdf.

HC-06 AT commands are more limited, though it'll do the job.
AT : Check the connection;
AT+NAME: Change name. No space between name and command;
AT+BAUD: Change baud rate, x is baud rate code, no space between command and code;
AT+PIN: Change pin, xxxx is the pin, again, no space;
AT+VERSION: Shows version;
More detailed AT commands are given in the 2nd pdf.