loading
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

<p>One more pitfall - my board had an EN pin in place of KEY. This is different (- and means you can disable the board to save current when not in use). Instead there a button. Pressing this pulls the KEY input to the internal 3v3 line. I found that it could be released after a few seconds and I could rename and change baud rate. Mike</p>
<p>Can you explain more, because i have the same module (EN pin instead of KEY) but no response when i send AT commands </p>
As with the KEY input the button on this board has to be pressed during power on. I believe that for some AT commands the button must be kept pressed. However for the ones like changing name and changing baud rate is seems that holding it for a few seconds after power on is enough. Also the LED flashes slowly when you are successfully in AT mode. Please ask if this does not get you working. Mike
<p>I have the same module with EN instead of key. Is there a similar way to force data mode instead of AT mode?</p><p>No matter how I connect it (even tried only VCC to 5v and GND to GND) the module seems to enter AT mode. Also when i leave the little button completely alone.</p>
<p>Got this to work with my TTL-USB converter<br><br>&gt;&gt;&gt;&gt;&gt; WIRING &lt;&lt;&lt;&lt;&lt;<br> TTL ~~~ HC05<br> 5V &lt;=&gt; VCC<br>3.3V &lt;=&gt; EN<br>TXD &lt;=&gt; RXD<br>RXD &lt;=&gt; TXD<br>GND&lt;=&gt; GND<br><br></p><p>&gt;&gt;&gt;&gt;&gt; INSTR &lt;&lt;&lt;&lt;&lt;<br>1. Attach wires<br>2. Plug in USB-TTL whilst holding the button on the HC05 (4 sec)<br>3. Open up Serial Monitor with baud 38400 (mine was advertised as 9600) and &quot;Both NL &amp; CR&quot;.<br></p>
<p>Note: There is no need to connect the EN pin as there is an internal pullup to 3v3.</p><p>AT mode uses 38400 baud regardless of the operating mode. The operating mode can be set a wide range of speeds. Most will be supplied set to 9600.</p><p>The RX input should be ranged to 3v3. I used 3k3 and 6k8 resistors to drop. Search on &quot;Make-Bluetooth-HC-05-Module-5v-Compatable&quot;.</p>
<p>this is what i get in serial monitor on an UNO </p><p>cant seem t get any AT response from any app or program. also tried ftdi unit.</p><p>it connect via BT but does accept any commands from terminal.. tried a few different sketches and techniques..</p><p>THNX</p>
<p>I had the same problem. You have to set 'Newline' to 'Both NL &amp; CR', if that doesn't solves your problem try to set '38400 baud' to '9600 baud' (That worked for me)...</p>
<p><br>I made all thatand still not working</p>
<p>I have the same problem .. What didi you do so that it works ?</p>
<p>thank you! worked for me so far Im getting responses atleast, havent tried an actual bluetooth connection yet but thanks for your article.</p><p>just a note... I have the HC-05 with the EN Key &amp; the method DrMike suggested worked for mine module</p>
<p>Didn't work at first. I then realised (after using a ftdi cable and Realterm) that I needed to have 'Both NL &amp; CR' selected in the serial monitor for sending the serial data. Hope this helps others avoid this pitfall. Mike</p>
<p>I guess it is different for every module. My HC-05 was on 9600 in both modes.</p><p>My sequence was fairly simple. I used an ftdi module</p><p>Connect the necessary pins:</p><p>tx-rx<br>rx-tx<br>vcc-vcc<br>gnd-gnd<br>state-Vcc</p><p>plug ftdi module in usb,</p><p>open serial monitor, set to 9600 baud</p><p>Press the little 'state' button on the module some 4-5 sec</p><p>enter AT in the serial monitor. if it comes back with 'OK' you are good to go</p>
<p>It works also with Arduino Nano. It is important to remember that HC-05 modules tagged ZS-040 work with power between 3.6 and 6 V and RX and TX at 5V. When I tried to drive RX at 3.3 V , I had no response. Finally, RX and TX work at 9600 b/s , and at 38400 in AT mode.</p>
I connected hc05 module with arduino uno board with connections as- <br>G<br>HC-05 GND --- Arduino GND Pin<br>HC-05 VCC (5V) --- Arduino 5V<br>HC-05 TX --- Arduino Pin 10 (soft RX)<br>HC-05 RX --- Arduino Pin11 (soft TX)<br>HC-05 Key (PIN 34) --- Arduino Pin 9<br>After connecting i m getting rapid blinking of led on hc 05 module but unable to connect with any app on ios neither AT command is getting any response on serial port.<br>Suggest how to connect hc05 with arduino uno and how to use it on ios mobile app
<p>If it has a small button above the EN/KEY/WAKE UP pin, disconnected Vcc, press and hold that button, connect Vcc and it the LED in the module should blink slowly and allow you to enter AT codes.</p><p>Regards,</p>
<p>This worked for me too. Also, after getting the LED to blink slowly, press the Reset button on the Arduino. Exact steps that seem to always work: </p><p>1. Unplug power from HC-05</p><p>2. Upload sketch from this Instructable</p><p>3. Hold in HC-05 button</p><p>4. Reconnect power to HC-05 (wait until LED blinks slowly)</p><p>5. Press Arduino reset button</p><p>6. Open Serial Monitor</p><p>7. Make sure &quot;Both NL &amp; CR&quot; is selected</p><p>8. Type AT commands</p><p>We had 3 people in a workshop this evening and when everyone followed this procedure it always worked. </p>
<p>NOT REPLAY FROM SERIAL MONITOR</p>
<p>i followed your procedure but still i get weird output in for of some other language. but when i put the baud rate to 9600 it shows english and then an error message comes up......plz help</p>
<p>I had steps 3 &amp; 4 reversed above -- my apologies. They should be: </p><p>3. Reconnect power to HC-05</p><p>4. Hold in HC-05 button (wait until<br>LED blinks slowly)</p><p>(9600 baud is correct for the serial monitor)</p>
<p>that worked perfectly</p><p>thanks</p>
<p>pin 34 cannot be connected directly to Arduino PIN 9, use level converter from 5 volts to 3.3 and vice versa or simply use two 1 K ohm resistors between PIN 9 and VSS and connect pin 34 inbetween </p>
<p>i have done whole connection and program but still not work serial comm. is not done and led of HC 05 is blink continuously. </p>
<p>Just what I was looking for, thank you very much.</p>
<p>It work</p><p>Thank you</p>
<p>Great tutorial,</p><p>Thank for the help,</p><p>Roland</p>
<p>I can transmit data from PIC controller -&gt;hc-05-&gt; mobile terminal but can't receive back data into PIC controller from mobile terminal.</p><p>Can any body help me with solution?</p>
<p>hey dudes</p><p>I've got a cz hc 05 bluetooth module</p><p>when i connected this to my arduino mega 2560, it worked fine, with the LED's blinking indicating it was working. I even managed to pair it with my android device. However, soon after i paired it, the module stopped blinking and i cant seem to get it working again..</p><p>Does anybody know what the problem is? Or did is the module broken?</p>
<p>I know have 5 hc-05s here at home and trying to connect to them each with the same generic name was terrible. I have been trying to get my hc-05s into command mode and successfully connect to them for weeks -- as an off and on project. Finally, with this instructable and an Arduino Nano I got it all to work because of connecting to D10, D11 instead of the Tx and Rx on the Nano. Thanks for writing this great instructable. Also, since my hc-05s all have the button, I can just hold that while powering them on and the device enters into AT mode. No need for the additional wire on pin 9 or the associated code.</p>
<p>Hi, instead of your pinout I have:</p><p>state, rxd, txd, gnd, vcc, en</p><p>Is the &quot;en&quot; pin seme as &quot;key&quot; pin? The &quot;state&quot; and &quot;en&quot; pins haven't got pins to connect to breadboard (there are only 4 pins, but other 2 are marked amd seem like they're ready to be soldered to pins, they have holes).<br>Sorry for my english and thanks for answer!</p>
<p>u got output using that bluetooth module ?</p>
<p>when connected tx-rx,rx-tx,gnd-gnd,vcc-5v, starts blinking. when trying to connect, ligts without blinking. But phone says something like couldn&acute;t connect and bluetooth starts blinking again.</p>
<p>Like on this picture: <a href="http://www.martyncurrey.com/wp-content/uploads/2014/10/HC-06_zs-040_01_1200.jpg" rel="nofollow">http://www.martyncurrey.com/wp-content/uploads/2014/10/HC-06_zs-040_01_1200.jpg</a></p>
<p>Hi, I'm working with the arduino Due and SoftwareSerial doesn't work. I'm not that great with the coding, so could you help me out?</p>
<p>Instead of getting an OK after typing AT in the serial monitor, I am getting the following output. Please someone tell me the reason</p>
<p>that my be due to mismatch of buad rate </p>
<p>//Correction :</p><p>#include&lt;SoftwareSerial.h&gt;</p><p>SoftwareSerial BTSerial(10,11);</p><p>String HC05_Responce=&quot;&quot;;</p><p>void setup(){</p><p> pinMode(9,OUTPUT);</p><p> digitalWrite(9,HIGH);</p><p> Serial.begin(9600);</p><p> Serial.println(&quot;Enter AT command:&quot;);</p><p> BTSerial.begin(38400);</p><p>}</p><p>void loop(){</p><p> if(BTSerial.available())</p><p> Serial.write(BTSerial.read());</p><p> if(Serial.available())</p><p> BTSerial.write(Serial.read());</p><p>}</p>
<p>HELLO KJOHARI21</p><p>Instead of no line ending drop the menu down and select &quot;Both NL &amp; CR&quot;</p><p>and try again.</p><p>cheers ;)</p>
<p>HiKjohari21, il think you have to select &quot;both line feed and carriage return&quot; in the serial monitor and it will work.</p><p>Regards.</p>
<p>If there is anyone still struggling out there, I made another instructable detailing how to use this modules in master, and slave mode. It is meant to explain how to get each model into AT mode, and then, to get them working with code.</p><p>https://www.instructables.com/id/Arduino-Bluetooth-Master-and-Slave-Using-Any-HC-05/</p>
<p>Hello to everyone.I have make a bleutooth robot which i can control it via android(tablet) and i have a problem with the code.I want from the robot to stop when connection lost or bluetooth disconnected.Now when the connection lost the robot go ahead and falls on the objects.How to add this line on the code?Can you help me please?The STATE pin of HC-05 when is HIGH is connected and when is LOW is disconnected.I put this on my code but it doesn't stop.Thank you for your time</p><p><br>The bluetooth that i use is HC-05<br><br>My code:<br><br>#include &lt;Servo.h&gt;<br><br>Servo SERVO_1; // Initialize Servo1<br><br>// Motor Control Variables<br>int PWM1 = 9;<br>int ENABLE1 = 8;<br>int PWM2 = 5;<br>int ENABLE2 = 7;<br>int PWM3 = 3;<br>int ENABLE3 = 4;<br>int PWM4 = 6;<br>int ENABLE4 = 12;<br>int STATE=2;<br><br><br>void setup() {<br> SERVO_1.attach(10);<br> Serial.begin(9600);<br> pinMode(ENABLE1, OUTPUT); //&Delta;ή&lambda;&omega;&sigma;&eta; ό&lambda;&omega;&nu; &tau;&omega;&nu; &mu;&epsilon;&tau;&alpha;&beta;&lambda;&eta;&tau;ώ&nu; &omega;&sigmaf; έ&xi;&omicron;&delta;&omicron;&sigmaf;<br> pinMode(ENABLE2, OUTPUT); //&Delta;ή&lambda;&omega;&sigma;&eta; ό&lambda;&omega;&nu; &tau;&omega;&nu; &mu;&epsilon;&tau;&alpha;&beta;&lambda;&eta;&tau;ώ&nu; &omega;&sigmaf; έ&xi;&omicron;&delta;&omicron;&sigmaf;<br> pinMode(ENABLE3, OUTPUT); //&Delta;ή&lambda;&omega;&sigma;&eta; ό&lambda;&omega;&nu; &tau;&omega;&nu; &mu;&epsilon;&tau;&alpha;&beta;&lambda;&eta;&tau;ώ&nu; &omega;&sigmaf; έ&xi;&omicron;&delta;&omicron;&sigmaf;<br> pinMode(ENABLE4, OUTPUT); //&Delta;ή&lambda;&omega;&sigma;&eta; ό&lambda;&omega;&nu; &tau;&omega;&nu; &mu;&epsilon;&tau;&alpha;&beta;&lambda;&eta;&tau;ώ&nu; &omega;&sigmaf; έ&xi;&omicron;&delta;&omicron;&sigmaf;<br> pinMode(STATE, INPUT);<br>}<br><br>void loop() {<br><br> if(digitalRead(STATE)== HIGH)<br><br> // see if there's incoming serial data:<br> if (Serial.available() &gt; 0) {<br> // read the oldest byte in the serial buffer:<br> int incomingByte = Serial.read();<br> // action depending on the instruction<br> // as well as sending a confirmation back to the app<br> switch (incomingByte) {<br> case 'F':<br> moveForward();<br> Serial.println(&quot;Going forward&quot;);<br> break;<br> case 'L' : // Case 'L' is received,<br> SERVO_1.write (180); // &Sigma;&tau;&rho;ί&psi;&epsilon; &Alpha;&rho;&iota;&sigma;&tau;&epsilon;&rho;ά.<br> SERVO_1.attach(10);<br> break;<br> case 'N':<br> turnright();<br> Serial.println(&quot;Turning right&quot;);<br> break;<br> case 'M':<br> turnleft();<br> Serial.println(&quot;Turning left&quot;);<br> break;<br> case 'O' : // Case 'L' is received,<br> SERVO_1.write (0); // &Sigma;&tau;&rho;ί&psi;&epsilon; &Alpha;&rho;&iota;&sigma;&tau;&epsilon;&rho;ά.<br> SERVO_1.attach(10);<br> break;<br> case 'B':<br> moveBackward();<br> Serial.println(&quot;Going forward&quot;);<br> break;<br> case 'P':<br> SERVO_1.write(90); // &Sigma;&tau;&rho;ί&psi;&epsilon; &Alpha;&rho;&iota;&sigma;&tau;&epsilon;&rho;ά.<br> SERVO_1.attach(10);<br> break;<br> case 'S':<br> moveNone();<br> Serial.println(&quot;Stopping&quot;);<br> break;<br> default:<br> // if nothing matches, do nothing<br> break;<br> }<br> }<br>}<br><br>void moveForward() {<br> // turn the driving motor on to go forwards at set speed<br> digitalWrite(ENABLE1, HIGH);<br> digitalWrite(ENABLE2, HIGH);<br> digitalWrite(ENABLE3, HIGH);<br> digitalWrite(ENABLE4, HIGH);<br> analogWrite(PWM1, 255);<br> analogWrite(PWM2, 255);<br> analogWrite(PWM3, 255);<br> analogWrite(PWM4, 255);<br><br>}<br><br>void moveBackward() {<br> // turn the driving motor on to go backwards at set speed<br> digitalWrite(ENABLE1, LOW);<br> digitalWrite(ENABLE2, LOW);<br> digitalWrite(ENABLE3, LOW);<br> digitalWrite(ENABLE4, LOW);<br> analogWrite(PWM1, 255);<br> analogWrite(PWM2, 255);<br> analogWrite(PWM3, 255);<br> analogWrite(PWM4, 255);<br>}<br>void turnright() {<br> digitalWrite(ENABLE1, HIGH);<br> digitalWrite(ENABLE2, HIGH);<br> digitalWrite(ENABLE3, LOW);<br> digitalWrite(ENABLE4, LOW);<br> analogWrite(PWM1, 255);<br> analogWrite(PWM2, 255);<br> analogWrite(PWM3, 255);<br> analogWrite(PWM4, 255);<br>}<br><br>void turnleft() {<br> digitalWrite(ENABLE1, LOW);<br> digitalWrite(ENABLE2, LOW);<br> digitalWrite(ENABLE3, HIGH);<br> digitalWrite(ENABLE4, HIGH);<br> analogWrite(PWM1, 255);<br> analogWrite(PWM2, 255);<br> analogWrite(PWM3, 255);<br> analogWrite(PWM4, 255);<br>}<br>void moveNone() {<br> // turn the driving motor off<br> digitalWrite(ENABLE1, 0);<br> digitalWrite(ENABLE2, 0);<br> digitalWrite(ENABLE3, 0);<br> digitalWrite(ENABLE4, 0);<br> analogWrite(PWM1, 0);<br> analogWrite(PWM2, 0);<br> analogWrite(PWM3, 0);<br> analogWrite(PWM4, 0);<br> SERVO_1.detach();<br>}</p>
<p>Thanks a lot!</p>
<p>I'm encountering a problem :</p><p>I've plug my HC-05 through arduino uno, on the serial monitor it say &quot;ready for AT commands&quot;.</p><p>Then i wrote &quot;AT&quot; in the monitor but no OK answer </p><p>What Should I do ?? </p><p>Thanks</p>
<p>IM HAVING THE SAME PROBLEM</p>
<p>i want to connect HC 05 with RX65N (100 pin). i made pin 34 high HC 05 entering in command mode but it is not responding back</p><p>which register has to be connected between vcc and pin34</p>
<p>My HC-05 is already blinking slowly (every 2s), but when I send 'AT' from serial monitor, I get nothing. I use the same code in this instructable. Someone, please help me.</p>
<p>An enjoyable come across by chance on Youtube so later on in the day I worked through most of the instructable.</p>
What should I do if I receive some unreadable character<br>Plzz reply
<p>hi I just have to get data from the pin 7 of Arduino do I need to configure the hc05 ?</p><p>plzz help me the coding too </p>
<p>do i have to change the default AT setting on bluetooth to make it work with my android</p>

About This Instructable

626,448views

396favorites

License:

Bio: Did I unplug the solder iron?
More by techbitar:IR Remote Control Station for Android - TURN THE TV DOWN SensoDuino: Turn Your Android Phone into a Wireless Sensors Hub for Arduino Modify The HC-05 Bluetooth Module Defaults Using AT Commands 
Add instructable to: