AT Command Mode of HC-05 and HC-06 Bluetooth Module

851,155

250

133

Introduction: AT Command Mode of HC-05 and HC-06 Bluetooth Module

UPDATED july 18: You can now enter AT mode of HC-05 using an Arduino board, (arduino uno used in this tutorial)

UPDATED july 7: I had the opportunity to test a HC06 module. This guide now covers HC-06 module too. :)

Having multiple bluetooth modules with the same name can be confusing. Sometimes it may require to change the default settings like baud rate, or master/slave role of the module. This guide shows how to enter AT command mode of HC05/HC-06 bluetooth module with the help of USB to TTL converter. Alternatively for HC-05, you can use an arduino board.

Requirements:

1.HC-05/HC-06 Bluetooth module with breakout board.

2.USB to TTL converter : I used PL2303HX usb to ttl converter. Any other usb to ttl converter will do too./Arduino board, arduino uno used in this tutorial, other boards should work to.

3. Arduino IDE/ Tera Term : It can be downloaded from here or if you don't want to download arduino then download Tera Term from here.

Step 1: Identifying Your Module

First thing you need to do is identify your module. It can be either HC05 or HC06. Both the modules are same in functionality except the pinout. Also HC05 can act as both master and slave whereas HC06 functions only as slave. It's hard to differentiate between the two only by seeing. One probable way would be checking the back of the breakout board. If it has "JY-MCU" written on the back, it's probably a HC06. Mine has "ZS-040" written and it is a HC05. And the HC06 module I tested had a bluetooth sign behind with three pcb footprints(refer to figure2). To confirm the device identity, you can power up the module, search for new device on your pc or mobile, and look for HC05 or HC06 on found device list.

Step 2: Pinout and Entering AT Mode

PINS: The pins found on the breakout board are,

KEY: This pin has to be pulled high to enter AT mode.
VCC: Indicated range is 3.6 to 6 volt. To be on safer side, you should connect it to 3.3 Volt.
GND: Ground.
RXD: Serial input pin.
TXD Serial output pin.
STATE: May or may not be connected to any pin. Supposedly outputs the Bluetooth connection status. This pin will not be needed.

Some of the breakout boards have EN pin or even WAKE UP pin instead of KEY pin. None of them seem to be connected to any pins of module. But that does not matter because we wouldn't need them anyway.

Once you identified the module, now it's time to enter the AT mode.
For HC05: Connect the Rx pin of the Bluetooth module to Tx pin of USB to TTL converter, and Tx pin of Bluetooth to Rx pin of converter. Also connect their ground but don't connect the Vcc yet. First you'll have to short the key pin with the Vcc. Connect key pin and Vcc together on breadboard, or any other way. After all other pins are connected, connect Vcc of bt module to USB to TTL converter's Vcc. Now the led on the module will blink at the interval of 2 seconds. That means it has entered the AT mode. If the led blinks faster then AT mode was not entered. Disconnect Vcc, check your circuit and try again. If it does not work then there's a chance that your KEY pin of the module is not really soldered to the KEY of the main chip, i.e. the 34th pin. You can check that with the help of multimeter.

If you use an arduino uno, then connect Rx pin of the Bluetooth module to pin 11 of Arduino Uno(supposedly same for arduino mega), and Tx pin of Bluetooth to pin 10 of Arduino. Also connect key pin of module to pin 9 of arduino and ground to ground, but don't connect the Vcc yet. You have to first power up the arduino, and then connect Vcc just like you did in case of USB to TTL converter.

For HC06: Just connect the Rx of module to Tx of usb-ttl converter and Tx of module. Connect ground and Vcc. The module is in AT mode. Didn't see that one coming, right? :P Turns out HC06 module is permanently configured to be slave and it is always in AT mode when not paired to any other device. So there is no confirmation led blinking that it is in AT mode like HC05 has. Just power up the module and pass the AT commands to modify the default settings.

Connection overview:

HC05 USB to TTL Arduino
Vcc Vcc Vcc
Rx Tx pin 11
Tx Rx pin 10
Gnd Gnd Gnd
key Vcc pin 9

HC06 USB to TTL

Vcc Vcc
Rx Tx
Tx Rx
Gnd Gnd

Step 3: If Key Pin Is Not Present or Not Connected

Only for HC05: As stated earlier, some models of the breakout board do not have the key pin, instead they have an EN (enable) pin or WAKE UP pin which may or may not be connected to any pin just like the STATE pin. In that case you'll have to solder a wire to the 34th pin of the bt module. I soldered a male header to mine but if you can't solder or don't want to, then you can just hold a wire (the pointy end of a male to male jumper wire would be convenient ) while connecting the Vcc to 5volt. Once the bt module is in AT mode, you can release the wire.

HC06 does not require key pin.

Step 4: Setting Up Connection

For HC05:

Once the module is in AT mode, open arduino. Go to tools>serial port>select the com port your USB to TTL converter is connected to (to find out, go to device manager of your pc>ports(COM &LPT)) . Now open the serial monitor. The bt module is now communicating at a baud rate of 38400. So change the baud rate to 38400 at bottom right corner of the serial monitor. Also change "no line ending " to "both NL & CR" found just beside the baud rate.

If you don't have Arduino IDE, then download Tera term(which is an excellent terminal emaluator). Open Tera term. A pop up window will open, Select Serial and choose the com port the usb to ttl converter is connected to. Press ok and a connection will be established. Now go to setup>serial port>set the baud rate to 38400. After setting up baud rate go to setup>terminal>change the newline to CR+LF from the drop down menu. Also check the local echo box under newline. Now the set up is complete.

If you use arduino (UNO/MEGA) board, then copy paste the following code, which is just a modification of Software Serial example included in arduino examples.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {

Serial.begin(9600);

pinMode(9,OUTPUT); digitalWrite(9,HIGH);

Serial.println("Enter AT commands:");

mySerial.begin(38400);

}

void loop()

{

if (mySerial.available())

Serial.write(mySerial.read());

if (Serial.available())

mySerial.write(Serial.read());

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Upload the code to the arduino board, once the code is uploaded, open Serial monitor, change "no line ending " to "both NL & CR" at the bottom, close it and disconnect arduino board from usb. Now again reconnect arduino to usb,connect vcc of bluetooth module to arduino 5volt, and open serial monitor. The led on the module should blink at the interval of 2 seconds. That means it has entered the AT mode. Now you are ready to enter AT commands.

For HC06:

Now there is a small drawback for HC06, it does not wait for any termination character for each AT command entry. Instead, it acts to whatever character you entered after one second. Hence, if you are not able to complete a command entry within a second, it will be ignored. Because of this behavior, it may be extremely difficult to do manual entry configuration using Windows Hyper-terminal software. Terminal software that allows batch sending of multiple characters must be used. I found that arduino works fine. On the other hand, if you use Tera term you have to write down the AT commands in a notepad, than copy-paste it to Tera term. Right clicking on Tera term console will automatically paste the copied line and execute immediately.

So once the module is connected to usb-ttl converter and powered up, open arduino, select the usb-ttl com port, set baud rate to 38400. No other settings have to be applied unlike HC05. And for Tera therm, select appropriate com port, go to setup>serial port>set the baud rate to 38400, go to setup>terminal>check the local echo box and everything is set.

Step 5: AT Commands

For HC05: 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 or JY_MCU or something like that. To change the name just type AT+NAME=your desired name.

Here is an important note, if the key pin is not high, i.e. not connected to Vcc while receiving AT commands(if you did not solder the wire and released it after the module entered AT mode), it will not show the default name even after giving right command. But you can still change the name by the command mentioned above. To verify if the name has really changed, search the device from your pc/mobile. The changed name will appear. To change baud rate, type AT+UART=desired baud rate. Exit by sending AT+RESET command.

Most useful AT commands are

AT : Ceck 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.

For HC06: On arduino serial monitor type "AT" (without the quotes) and press enter, "OK" will confirm AT mode. Unlike HC05, you can't see the default name or baud rate. You can only change them. To change name type AT+NAMEDESIRED NAME, notice that there should be no space between the command and name. The module will reply OKyour set name. For example, AT+NAMEPROTOTYPE will set the name to PROTOTYPE. To change baud rate, type AT+BAUDX, where X=1 to 9.

1 set to 1200bps
2 set to 2400bps
3 set to 4800bps
4 set to 9600bps (Default)
5 set to 19200bps
6 set to 38400bps
7 set to 57600bps
8 set to 115200bps
so sending AT+BAUD4 will set the baud rate to 9600.

For Tera Term write down the commands somewhere else and paste it on the console by right clicking. No need of pressing enter. The command will be executed immediately and confirmed.

HC 06 AT commands are limited, all I could find are given here.

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

More details in 2nd pdf.

5 People Made This Project!

Recommendations

  • Metalworking Contest

    Metalworking Contest
  • Water Contest

    Water Contest
  • Creative Misuse Contest

    Creative Misuse Contest

133 Discussions

As a beginner with Arduino I am surprised at the slip-shod nature of the HV-06 instructions, that a must be carefully read,.

An enumeration 1,2,3 etc is required for a beginner;
more attention to why +3.3v power is required.

0
None
uriel01

Question 17 days ago

can oyu please tell me how to connect this module (master)to another hc06 plese?

Okay, this part had me quite stuck. The code shows :
SoftwareSerial mySerial(10, 11); // RX, TX
However, the wiring (from arduino to Bluetooth module) has to be the opposite.
That means you have to connect pin 10 on Arduino Uno to TXD on Bluetooth and connect pin 11 on Arduino Uno to RXD on Bluetooth. I wasted a lot of time on that.

Also this shows the Serial Monitor being set up at 38400, but that always gave me jumbled output. I believe it is supposed to be at 9600 (that's what worked for me).

It's obvious once you know it, but it caused a bit of a struggle when trying it for the first time.

1 reply

YEP TX CONNECTS TO PIN 11 AND RX TO PIN 10

In the post it is said that the baud rate of the Serial Monitor should be set to 38400 but that is not the case. In order ro get a correct output the baudrate should be set to 9600. However the baudrate of 'mySerial' in the code shouldn't be changed (38400) because this is the default baudrate of the HC05.

arduino_baud.PNG

What does AT mens or defines
I.e bt=Bluetooth in same way what is AT IN Bluetooth comand mode please mail me to vksbharadwaj.10@gmail.com it is urgent

Don't use a + symbol after the AT, use a dash - See if this works. Mine uses the + to change and the - to query the board. I just got some cheap eBay ones and it was a struggle to figure out the baud rate is 9600 and an Arduino 101 will not program it. I had to go to an UNO.

I HAVE HC 06 module.... it did not respond to the AT commends..... how i can solve that..

I have been struggeling getting AT commands that sets new values to work on some ZS-040 baranded HC-06 units that I recently bought on eBay from China

AT returns OK
AT+NAME returns +NAME:HC-06
AT+NAMENewName returns ERROR:(0)

I have got this working on other HC-06s, but not on this new ones.

AT+VERSION returns VERSION:3.0-20170609

So i tried googeling HC-06 v3.0 and stumbeled over some site that had some AT commands where a = was added between the command and the new value, so then I tried:

AT+NAME=NewName which returned OK

So it looks like something happened in firmware 3?

THE MOST IMPORTANT THING IF USING LINUX:

RUN ARDUINO AS ROOT USER!

Thanks buddy. Worked fine for me, with USB to TTL +Serial monitor of ArduinoIDE. Putty didn't work(I have no idea why). But I ordered HC06 from ebay, what came was HC-04 (but still worked for my purpose). It responded to only limited commands but atleast I was able to rename my device :-). Thanks

0
None
Phimo

2 years ago

Unless I'm missing something in your guide, you seem to be suggesting connecting TTL outputs directly to the HC-05/06 signal inputs. The signal inputs ARE NOT TTL compatible and should only be used with 3.3V logic levels. You need level shifters on the module's signal inputs.

2 replies

Hi Phimo...

Also, in addition to what I said below as a response to rdlockrey's comment, I do have 3 different versions (hardware wise) of the HC-06 with 2 different firmwares - one requiring NL/CR and one none. So I dont know how many hardware boards every Tom Dick and Harry made that sells those modules, but at least my 3 have the level shifters. You can easy check with your meter between pin one of the module and the breakout pin and pin 2 and the breakout pin - if resistance is 0, you are correct you better use a TTL level (3.3v) Arduino OR Serial adapter. Again, all mine had the level shifters + voltage regulators.

Hope it helps someone.

0
None
JamesK66

Reply 11 months ago

rdlockrey- he's talking about signal levels, not the COM/TTY port - it's TTL when referring to a signal level. You should learn what you are talking about before you try to correct someone.

But to Primo - The breakout boards he is using and that most everyone buys have level shifters AND a voltage regulator - no no need for TTL level, CMOS is fine. But to your point, if you do use the board bare, yes, you must use TTL level! There exists somewhere a schematic I found of those little breakout boards that shows them - I'm sure google could find it if you needed.

Note that AT commands sent to the HC-06 must NOT be followed by CR LF.

If you send AT CR LF, then 1 second after receiving the LF, the HC-06 looks at the string and says that "AT CR LF" is not a valid command.

It is necessary to send just AT on its own. The HC-06 will then send OK.

2 replies

I have a couple of these. It seems the ones that reply with version "hc01.comV2.0" will only work with the NO CR/LF. The ones that reply"Firmware version:3.0-20170609" ONLY lf with a CR/LF. It appears to have changed with a firmware update, but I didnt get into them enough yet to see any more differences.

This is not true. The HC06 module I have (Firmware version:3.0-20170609) ONLY responds if you send CR LF after your command.