Modify the HC-05 Bluetooth Module Defaults Using AT Commands

842,025

459

242

Introduction: Modify the HC-05 Bluetooth Module Defaults Using AT Commands

About: Did I unplug the solder iron?
UPDATES
September 4, 2013: Featured on Hackaday.com http://goo.gl/qxvWkd
September 1, 2013: Featured on DangerousPrototypes.com http://goo.gl/K4kH9g

INTRODUCTION

In this guide, I will explain how to use Arduino to change the settings of the ubiquitous HC-05 Bluetooth module using the AT command set. The HC-05 comes with a rich set of AT commands to perform various tasks such as changing the module's default settings including changing the pass code, the device name, and the baud rate. But the process of switching the HC-05 into AT command mode for first time users of the module is not straight forward and the docs takes short cuts. There are a couple of ways to do this. I have picked the one I think is the easiest  I will do my best to illustrate the process in simple to follow steps. You can find the full set of AT commands in the attached datasheet.


BACKGROUND

The HC-05 Bluetooth module and its siblings are by far the most popular and inexpensive Bluetooth modules used for RF communications by microcontroller hackers. It costs less than $10 on ebay and it's easy to implement. I have published two guides based on the HC-05 Bluetooth module.  The first guide explains how to use the HC-05 with the Arduino. The second is an Android app that simplifies controlling Arduino from your smart phone over Bluetooth using the HC-05. In both cases, the default settings for the HC-05 were fine. 

In the process of using the HC-05 for a project, I ran into a situation where I needed to change the defaults for the module. For example, the default baud rate on the HC-05 is 9600. That's slow for high-speed transmission. The HC-05 can go as high as 1382400 baud rate according to the HC-05 reference. Also, the HC-05 has a default device name of HC-05. Having two or more of those devices in the same area can be confusing. You can use an AT command to change the device name. Also, the pin code default is 1234. You may wish to change that for some projects to ensure basic security.

After spending some time searching the web I realized many people are having a hard time changing the default settings for the HC-05. Switching the HC-05 from data transmission mode to configuration mode, to send AT commands to the HC-05, involves a few wiring and software acrobatics.  Add to the mix all the variations of the HC Bluetooth module family and the various vendor settings and you get the picture. 

This guide only covers the HC-05 module with the breakout board. 

WARNING

The HC-05 is a 3.3V system but the breakout board offers current limiting resistors for some protection. While it's not advisable to keep the HC-05 connected to the 5V Arduino Uno pins, for this short exercise I decided to skip the voltage dividers which I use to drop 5V to 3.3V. I advise you to use voltage dividers whenever you connect the HC-05 pins to  5V pins such as the Arduino Uno. If you skip the voltage divider, do so at your own risk.

Step 1: Components & Wiring

I have tested this guide with the following:

PARTS
WIRING
  • HC-05 GND --- Arduino GND Pin
  • HC-05 VCC (5V) --- Arduino 5V
  • HC-05 TX --- Arduino Pin 10 (soft RX)
  • HC-05 RX --- Arduino Pin11 (soft TX)
  • HC-05 Key (PIN 34) --- Arduino Pin 9

Step 2: The Arduino Code for HC-05 Command Mode

This Arduino program (HC_05.ino) does two things. It takes the AT commands you enter from the Arduino IDE Serial Monitor and sends those commands to the HC-05. The program then reads the output of the HC-05 and displays it on the Arduino IDE Serial Monitor. You can also use a terminal emulator such as Tera Term instead of the Arduino Serial Monitor. 

The Arduino communicates with the HC-05 using the SoftwareSerial ports while the Arduino communicates with the user via the Serial Monitor.


/*

AUTHOR: Hazim Bitar (techbitar)
DATE: Aug 29, 2013
LICENSE: Public domain (use at your own risk)
CONTACT: techbitar at gmail dot com (techbitar.com)

*/


#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX

void setup()
{
  pinMode(9, OUTPUT);  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
  digitalWrite(9, HIGH);
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  BTSerial.begin(38400);  // HC-05 default speed in AT command more
}

void loop()
{

  // Keep reading from HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())
    Serial.write(BTSerial.read());

  // Keep reading from Arduino Serial Monitor and send to HC-05
  if (Serial.available())
    BTSerial.write(Serial.read());
}

Step 3: Steps to Switch the HC-05 Into Command Mode

For the HC-05 module to switch to AT command mode, the HC-05 pin 34 (often referred to as the Key pin) needs to pulled HIGH but in a certain order of events explained below. When the HC-05 enters the AT command mode, it will communicate at 38400 baud rate. Follow these steps in the stated order to switch to the HC-05 to AT command mode. 

  1. Wire the HC-05 and Arduino Uno per instructions.
  2. BEFORE YOU CONNECT THE ARDUINO TO THE USB remove the VCC (power) red wire from the HC-05 so it's not getting any power from the Arduino. All other wires are still connected.
  3. Now connect the Arduino Uno to the USB cable extended from your PC.
  4. Make sure the HC-05 module is NOT PAIRED with any other Bluetooth device.
  5. Re-connect the Arduino Uno 5V wire to the HC-05's VCC (5V power) pin.
  6. The HC-05 LED will blink on and off at about 2 second intervals. Now the HC-05 is in AT command mode ready to accept commands to change configuration and settings.
  7. To test if everything is wired correctly,  open the Serial Monitor from the Arduino IDE and type "AT" and click SEND. You should see an "OK"
  8. If you don't see an "OK" check your wiring.

Step 4: Example HC-05 AT Commands

You can send  AT Commands to the HC-05 from the Arduino IDE Serial Monitor while the Arduino is running the attached Arduino program.

I have listed a few popular AT commands that will change the HC-05 device name, pass code, and speed. You will find a full set of AT commands from the attached HC-05 reference PDF file.

(remove double quotes from AT command)
  • To return HC-05 to mfg. default settings: "AT+ORGL"
  • To get version of your HC-05 enter: "AT+VERSION?"
  • To change device name from the default HC-05 to let's say MYBLUE enter: "AT+NAME=MYBLUE"
  • To change default security code from 1234 to 2987 enter: "AT+PSWD=2987"
  • To change HC-05 baud rate from default 9600 to 115200, 1 stop bit, 0 parity enter: "AT+UART=115200,1,0"


12 People Made This Project!

Recommendations

  • STEM Contest

    STEM Contest
  • Role Playing Game Challenge

    Role Playing Game Challenge
  • CNC Contest

    CNC Contest

242 Comments

0
rbright
rbright

10 months ago

Trick I found to get working into AT Mode is as follows:
1) After downloading code power unit down and then remove Vcc connection to Bluetooth device (This step may not always be required so may be able to leave connected leave Vcc connected)
2) Hold Bluetooth's little button in & while held in plug USB into UNO then release button and the BT LED should flash at 2 second rate
3) Next reconnect Vcc to Bluetooth (that is if you needed to do this in step 1 above) and in Serial Monitor try command AT+VERSION? which should now work.
4) Power UNO down by removing USB cable and plug back in and all should be working with BT LED flashing at fast rate.

ENJOY...

0
rbright
rbright

Reply 10 months ago

ALSO .... On Serial Monitor ensure 'Both NL & CR' selected

Cheers

0
mukulmagotra98
mukulmagotra98

Question 1 year ago

I am facing a issue print of enter at command is coming ..but there is indefinite no. of ÿÿÿÿÿÿÿÿÿÿÿ are coming and on the 38400 lots of ΦΦΦΦΦΦΦ are coming ..ther is no response of all the AT commands i am just getting these y's and phi's...it is in cofig mode as i am getting those slow pulses of led

0
Bonjax
Bonjax

Answer 11 months ago

Make sure you choose "Both NL & CR" (\r\n) option next to baud rate. Commands must be terminated with \r\n.

0
MSPRao
MSPRao

1 year ago

I have made a successful NAME AND PSWD change but since then when I try to connect to the device my mobile shows the new name and accepts the new password but immediately disconnects and hc 05 blinks indefinitely...

0
JulianoC12
JulianoC12

Question 1 year ago

Hi, i am facing a uncommom problem. I have the hc-05 module always on AT mode. Can not change it. The led do never flash at 2hz frequency. Pairing not possible. Hc-05 firmware version(v5.3) without bind button. Someone can give me a help please??

0
vishnu_
vishnu_

Question 2 years ago

sir my bluetooth is not replying with "OK" on serial monitor.since i have made all connection and program as per your instruction. please help me to overcome from this error.
thank you

0
vishalwins
vishalwins

Answer 2 years ago

Please share your wiring diagram that you have done for AT mode.

0
vishnu_
vishnu_

2 years ago

For it is not replaying with "OK" on serial monitor;
please any one help me ......
thank you;

0
coopertn
coopertn

3 years ago

How do you take the module out of ATCommand Mode without unplugging the whole Arduino? Thanks for making tutorial... It helped me a lot.

0
DavidB552
DavidB552

Reply 2 years ago

to be safest I would unplug the whole thing then unplug the en pin then boot it up again

0
john wybrow
john wybrow

3 years ago

Is it possible to set 2 HC-05 as master and communicate with each other in a bio-directional communication configuration? I want to start communication from either side.

0
DavidB552
DavidB552

Reply 2 years ago

so im not 100% what you meant but a master is just the one that starts the link.

once its done either can send or get data from each other

0
FahadK23
FahadK23

2 years ago

CANT MAKE IT IN MASTER MODE BY GIVING COMMAND OF AT+MODE=1

PLEASE HELP

0
DavidB552
DavidB552

Reply 2 years ago

well how far did you get ?

0
DavidB552
DavidB552

Question 2 years ago

so after quite some time I got this to work question 4 second delay between a button press on the master and it registering as an output on the slave

is there any way to decrease this ?

0
JeanneB38
JeanneB38

Tip 2 years ago


UpvoteHi everyone.
Don't forget to select Both NL&CR in the AT commands page if you want an answer :)
0
Pavanvvs
Pavanvvs

2 years ago

How to connect HC-05 module with other HC-05 module.

0
shubhamslngh
shubhamslngh

2 years ago

my hc-05 module cant go into ATmode i have tried everything please help me

0
didemş1
didemş1

Question 2 years ago

No reply from AT commands ..Even my Bluetooth is unconnected to the VCC I can still see blinking from Bluetooth. We have an ongoing project and we spent 2 days to figure it out. Please reply it ! =)