Instructables

Modify The HC-05 Bluetooth Module Defaults Using AT Commands

Picture of Modify The HC-05 Bluetooth Module Defaults Using AT Commands
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.
 
Remove these adsRemove these ads by Signing Up
lafiona5 days ago

I have try use AT command for getting the RSSI value.

I'm trying the command "at+inq\n\r" (from datasheet)
but i only get OK and i can't understand that,

can you help me to find where the mistake is?

agentnoise19 days ago

I am unable to get this to work at all. I have gone over these steps 40 million times, any ideas why it might not be working? I have tried Wenabe's method too, and it will not work.

I know you have to first right the key pin high and then connect the 5v but even doing that wont work.

I figured it out. Mine has a button that you have to hold down while it boots in order to right the pin high.

vomov24 days ago

I'm using your code, which gives me the 'OK' after I send 'AT', and I have even succeeded in renaming it. However, if I do this: AT+NAME=THINGY, it gives it the name of "=THINGY". Aside from this, no other commands seem to do anything. Any advice?

bstott made it!1 month ago

Thanks for the education.

ArduDroid-testing.jpg
WhizzWr2 months ago

One IMPORTANT thing, Newline feed (\n) and Carriage return (\r) are needed on every AT command entered. So if you're using Arduino's serial monitor make sure you select "Both NL and CR" on the dropdown.

shanX WhizzWr1 month ago

THANKS!! THAT WAS NEEDED :) :)

accio1 month ago

With Mega, Mega 2560 and Leonardo not all the pins can be used to connect with the HC-05 via SoftwareSerial Library (used in the sketch).

Check http://arduino.cc/en/Reference/SoftwareSerial#.UxIQbXk1jFE

Once I found the right pins, I was able to use the HC_05.ino as is. Very useful!

samuelee2 months ago

Thanks for your instructions !

Unfortunately, after I've connected the circuit, there was no reaction when I applied AT command. Please kindly give your advice !

Details of my equipment :

  1. Arduino UNO R3

2. BT-Board V1.4

samuelee samuelee2 months ago

The LED on the BT board blinked rapidly (not 2-second blinking) throughout the experiment.

_MeRKeZ_2 months ago

That's a great work. Thanks Mr.

CATFARTS23 months ago

Have spent hours, but still get no response to AT commands. My HC-05 is purported to run at 9600 out of box, but no dice setting BTSerial.begin to either 9600 or original 38400 setting. Wiring and order of operations is correct and AT mode blinking is there - I even tried Wenabe's method, but that just put me into data mode (fast blinking) and didnt go back to AT mode. Have tried every line end option but there is absolutely no reply. When I send any text to UNO, only the rx LED lights up and there is no activity in tx LED.

Any help is appreciated.

Goines3 months ago

Thanks a lot, I've managed to get my HC-05 fully loaded up the way I'd like it to be!

I do have one problem though; no devices I have (Windows machines, or phone) will automatically reconnect via Bluetooth when the power is cycled to the HC-05. Have you had problems with this, or do you know how to get previous pairs to re-establish themselves?

Thanks again

Excellent guide, really helpful and well written. Thanks for submitting it.

kf5qgf3 months ago

Just a note, I couldn't get this to work on an Arduino Leonardo, but it does work great on the Arduino Uno.

funky817 months ago
Hi,
I've tried your code and schema here. But somehow it doesnt work. I already make sure my wiring correct. I'm using UNO and HC05 (bought from aliexpress).
What I have already tried is that I connect my UNO directly to PC.
Then I open serial monitor @ 9600. But still I dont get any responses from UNO.

Thank
wenabe funky813 months ago
Hi funky81,
See my reply to Luke534. It might help.
Thanks
techbitar (author)  funky817 months ago
It's not enough to have the same wiring. The order of events outlined in "Step 3: Steps To Switch The HC-05 Into Command Mod" is also important.
jornfranke6 months ago
Hi,

I cannot get it to work. The led blinks off and on every 2 seconds and I see the "Enter Serial Commands: " in the Serial Monitor, but I do not receive an answer when I enter AT.

I am also struggling to connect to it via Linux in normal mode. "hcitool scan" shows me the device, but I cannot connect.

Can you help me?

Thanks.
wenabe jornfranke3 months ago
Hi jornfranke,
See my reply to Luke534. It might help.
Thanks
otb15 months ago
Hello
Here id my code:

const byte rxPin = 10;
const byte txPin = 11;
#include <SoftwareSerial.h>
// set up a new serial port
SoftwareSerial mySerial(rxPin, txPin);
void setup(){
mySerial.begin(9600);
}

void loop(){
if(mySerial.available()){
mySerial.write(mySerial.read()); }
delay(1000); }

It doesn't work. I send AT,but there is no any respond. Can you help me? thanks.

wenabe otb13 months ago
Hi otb1,
See my reply to Luke534. It might help.
Thanks
techbitar (author)  otb15 months ago
It's not just the code that matters, the order of events is very important.
luke5345 months ago
hi techbitar, i have problem with the step 3.6. The HC-05 LED blink on and off rapidly. And then, I type "AT" into the serial monitor but it does not return anything. I have also checked if my wiring is correct. Can you help me?thanks
wenabe luke5343 months ago
Hi luke534,

I have the same problem as you have using HC-05 on break out board. After doing several hours of tinkering I manage to make it work.

How to get the hc-05 w/ breakout board to AT mode. After doing step 3.4 of Techbitar, perform the following:

Step 1: Remove PIN34 (KEY) of HC05 from D09 of arduino and connect PIN34 to GND.
Step 2: Supply power to the HC-05 module.
Step 3: Remove PIN34 (KEY) from GND and Input high level (NOTE: 3.3V NOT 5V) to this pin.

The module should enter to AT mode. The baud rate for serial communication is 9600 and the Arduino Serial Monitor should be set to "NL + CR"

I hope this will help.
wenabe wenabe3 months ago
Hi Luke534,
Forgot to tell you that I change the baud rate to "BTSerial.begin(9600)" on the sketch.
hakbari4 months ago
HI... NICE post. My problem is when i type "at" it will reply ok,ok,ok.... continuously without stooping. i expect "ok" one time but it return so many "ok".. same thing happen with "error". if i write any wrong at command, hc-05 continuously reply "error(0)","error(0)",.... and to stop i had to press enter. if this will happen continuously, i have dough, how could i interface hc-05 with micro-controller. Otherwise it works fine... i googled it but...didn't get any answer... please reply if you have any solution. thanx in advance
rea5245 hakbari4 months ago
hakbari, I had this too. It turns out it was caused by the terminal program I was using to send AT commands. It was sending a CR but not a LF. If the LF is sent, the HC-05 doesn't keep sending responses.
johnpaularul4 months ago
Hi Techbitar
Your page is really useful for me.
I have paired my HC-05 with a android tablet successfully. I don't know how to send a .jpg file from my pc to android tablet via HC-05 using AT Commands.. Please tell me about file transfer (like a image or mp3 file) via HC-05 to the paired device..
jbernardo24 months ago
i'm also curious if i can broadcast a character to multiple slave dongles?
pudrik5 months ago
Techbitar: have you managed to pair the dongle with multiple slave dongles?
troubadixx5 months ago
I can connect and enter AT commands.
However, I get gibberish instead of plain text as replies to my AT commands.
For example AT gives me "ϧ" instead of "OK"
For ecample AT+VERSION? gives me †…"«ª¢©*Õ奒¸ÁµIab°˜›˜Ì#áϧ" instead of "VERSION....OK"

Can someone help, pretty please :-)

(Already tried my second module b/c I thought I may have fried the first one. But I get the exact same behavior...)

BIG THANKS in advance
pudrik troubadixx5 months ago
Try Changing (worked for me)
from
BTSerial.begin(38400);
to
BTSerial.begin(9600);
troubadixx pudrik5 months ago
Thanks!
Tried already, but didn't work for me.
Changing from Linux to Windows (and the latest Arduino IDE) did work for me, though.
pudrik troubadixx5 months ago
I might point out that all Modules ive tried are preset to 9600 Baud and not 38400
Also the LINGOR dongle HC-06? seem to have newer firmware and CR / LF doesnt seem to matter that much unlike the HC-05 ive tried that was really really picky on all kinds of things, finaly tried Realterm (open source terminal software) and works like a charm.
techbitar (author)  troubadixx5 months ago
This can be a sign of mismatched baud rates.
Techbitar: Thanks for the answer!

Lucasaad: Thanks for sharing. I was about to give up - but knowing I wasn't alone with this kept me going and let to a solution :-)

My first thought was as well 'baud rate mismatch'. But like in lucasaad's case, the HC-05 understands the incoming commands and can be programmed. Strange...

Second thought was about other terminal settings like stop bit, parity bit, or encoding. So I played with some settings there - but no success.

Third thought was 'what the heck, let's try on Windows' (I'm normally working on a Ubuntu machine). Woooosh - it works!?!? I have no clue why, but it works. Same HC-05 module, same hardware, same wiring, same source code - different OS (Win7 instead of Linux), different version of Arduino IDE (latest 1.05 on Win).

Now I'm curious and will investigate further.

Lucasaad: what OS / Arduino IDE are you on? Any chance to give it a try on another setup?

TL;DR Don't know why (yet), but while it didn't work for me under Linux, it works like a charm under Windows.

techbitar (author)  troubadixx5 months ago
Good notes. Thanks for sharing.
yeah, but is strange,
is i send AT\rn\n i receive "ϧ" but of i put the wrong command like ATE\r\n i receive "Ū©§)OJLŠŠ" , i can change the HC-05 name and other commands,
The HC-05 receive the command in a baud raute but apparently send in other, I verify the parity bit and stop bit, all is correct (default is the same arduino and hc-05)



Same problem here,
if HC-05 send the OK by bluetooth to android i receive normally in Blueterm app
in the Serial Monitor returns ϧ instead OK, but the commands works
I need take informations for the arduino
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!