Arduino with HC-05 (ZS-040) Bluetooth module – AT MODE

Since writing the below many more modules have been released using the zs-040 breakout boards. Some of the newer ones include modules with a version 3.0-20170601 firmware that work in a slightly different way. I still do not have any of these and so cannot help directly but searching for the firmware should get plenty of hits online and a good place to start is stack overflow and the Arduino forum.

 
Update 20.07.2017

The zs-040 breakout boards are now being used for many different modules and you may not have the exact same boards as those shown below. The modules I am using here use the EGBT-045MS Bluetooth module and have the HC/Wavesen 2.0-20100601 firmware. They also have an EN pin rather than a KEY pin and they have a small button switch just above the EN pin.

There are now newer zs-040 modules that use the real HC SMD modules, these have a newer firmware and include a blue LED at the top right of the SMD daughter board.

There are also modules that use the same breakout board but have different board markings such as the fc-114 modules:
HC-05 FC-114 and HC-06 FC-114. First Look
HC-05 FC-114 and HC-06 FC-114. Part 2 – Basic AT commands
HC-05 FC-114 and HC-06 FC-114. Part 3 – Master Mode and Auto Connect

 

AT Command Mode

AT command mode allows you to interrogate the Bluetooth module and to change some of the settings; things like the name, the baud rate, whether or not it operates in slave mode or master mode.
When used as a master device AT commands allow you to connect to other Bluetooth slave devices.

The HC/Wavesen 2.0-20100601 firmware has different AT modes:
A full mode at 38400 baud.
A partial mode at 38400 baud.
A partial mode at the user settable baud rate.
A partial mini mode (even less commands work) at the user settable baud rate.

Most commands work when in any AT command mode but there are some commands that only work when pin34 is HIGH. This fooled me for quite a while. I now believe the partial/mini AT command mode is a bug in the firmware and I now only recommend using the full 38400 baud rate AT command mode.

HC-05 zs-040

To activate AT mode on the HC-05 zs-040 modules pin 34 needs to be HIGH on power up. The small push button switch connects pin 34 to +3.3v so we can either:
– connect pin 34 directly to +3v3v and power on, or
– hold the button switch closed when starting the module.

Please be aware that for the full AT command mode, pin 34 has to be HIGH all the time and we cannot do this with just the button switch. When in AT command mode with pin 34 not HIGH (LOW or floating) some commands will not work and so, when using the button switch, you need to press and hold it closed when sending some commands.

Using the button switch to enter AT command mode using 38400 baud rate:
– 1. remove power from the module
– 2. Hold the small button switch closed while powering on the module.
– 3. Press and hold the button switch.
– 4. While still holding the button switch closed, apply power.
– 5. When you see the LED come on you can release the button switch.

Enters AT mode with the built in AT mode baud rate of 38400. The baud rate cannot be changed by the user.
This method allows the module to enter AT mode on start but but does not keep pin 34 HIGH and some commands will not work.

Alternatively, if you are using AT command mode for any length of time, make a direct connection between pin 34 and +3.3v. Either solder a wire to the pin or use a clip.
HC-05_AT_MODE_02_BreadBoard_ClipCloseup_01_1200

Using pin 34 to enter full AT command mode using 38400 baud rate.
– 1. Remove power from the module
– 2. Make a connection between pin 34 and +3.3v
– 3. Reapply power.

Enters AT mode with the built in AT mode baud rate of 38400. The baud rate cannot be changed by the user.
If you keep pin 34 HIGH you will enable the “full” AT mode which allows all AT commands to be used.
If you let pin 34 return LOW after power on then “mini” AT mode will be enabled.

 

Connecting the HC-05 to the Arduino

There are a couple of common ways to connect the HC-05 to a computer; via a serial UART adapter or with an Arduino. Here I am using an Arduino.

Build the following circuit and upload the below sketch.

HC-05-AT-Mode-Connections-to-Arduino_800

HC-05 AT Mode - breadBoard_1200_1

– Arduiono 5V to BT VCC
– Arduino GND to BT GND
– Arduino D8 to BT TX
– Arduino D9 to BT RX through a voltage divider (reduce 5v to 3.3V)
– Optional. Connection from pin 34 but do not apply 3.3v yet.

The sketch is a basic serial in – serial out that displays a “>” at the start of a line to high light the user entered command.

I use software serial on Arduino pins 2 and 3 to talk to the HC-05. This means I can still use the hardware serial to talk to the serial monitor on a host computer.

//  Sketc: basicSerialWithNL_001
// 
//  Uses hardware serial to talk to the host computer and software serial 
//  for communication with the Bluetooth module
//  Intended for Bluetooth devices that require line end characters "\r\n"
//
//  Pins
//  Arduino 5V out TO BT VCC
//  Arduino GND to BT GND
//  Arduino D9 to BT RX through a voltage divider
//  Arduino D8 BT TX (no need voltage divider)
//
//  When a command is entered in the serial monitor on the computer 
//  the Arduino will relay it to the bluetooth module and display the result.
//
 
 
#include <SoftwareSerial.h>
SoftwareSerial BTserial(8, 9); // RX | TX
 
const long baudRate = 38400; 
char c=' ';
boolean NL = true;
 
void setup() 
{
    Serial.begin(9600);
    Serial.print("Sketch:   ");   Serial.println(__FILE__);
    Serial.print("Uploaded: ");   Serial.println(__DATE__);
    Serial.println(" ");
 
    BTserial.begin(baudRate);  
    Serial.print("BTserial started at "); Serial.println(baudRate);
    Serial.println(" ");
}
 
void loop()
{
 
    // Read from the Bluetooth module and send to the Arduino Serial Monitor
    if (BTserial.available())
    {
        c = BTserial.read();
        Serial.write(c);
    }
 
 
    // Read from the Serial Monitor and send to the Bluetooth module
    if (Serial.available())
    {
        c = Serial.read();
        BTserial.write(c);   
 
        // Echo the user input to the main window. The ">" character indicates the user entered text.
        if (NL) { Serial.print(">");  NL = false; }
        Serial.write(c);
        if (c==10) { NL = true; }
    }
 
}

Connect the Arduino to the host computer. The LED on the HC-05 should be blinking quickly at about 5 times a second.

If using the connection on pin 34, remove power, connect pin 34 to +3.3v and re-apply power to the module.

If using the button switch, remove power, press and hold the button switch, re-apply power (while holding the button switch). When you see the LED come release the button switch.

The LED should be blinking slowly on/off once every couple of seconds. This indicates AT mode.

 

AT Commands

The HC-05 expects commands to include a carriage return and newline characters (\r\n). You can add these automatically in the serial monitor by selecting “Both NL & CR” at the bottom of the window.
HC-05-ZG1643-B23090W_BothLineEnd
You can also enter them manually in the form AT\r\n. If you forget to add carriage return and newline characters the HC-05 will not respond.

Example commands

AT – simple feedback request. Will return “OK”
HC-05 AT Mode - Serial_AT

AT+VERSION – returns the firmware version.
“+VERSION:2.0-20100601
OK”
HC-05 AT Mode - Serial_VERSION

AT+STATE – returns the current state of the module
“+STATE:INITIALIZED
OK”

AT+ROLE – the possible values are ; 0 – Slave, 1 – Master, 2 – Slave-Loop
Returns
“+ROLE:0
OK”

To change to Master Mode, enter AT+ROLE=1, returns “OK”

AT+UART – returns the baud rate used by the HC-05 in communication mode. The default for the modules I have is 9600. Returns:
“+UART:9600,0,0
OK”

To change the baud rate to 38400 – AT+UART=38400,0,0
Returns “OK”

Windows does not support baud rates above 115200. If you accidentally set the baud rate higher than 115200 you will not be able to use communication mode. You should still be able to enter AT mode at 38400 using method 1 or method 2 above and change the communication mode baud rate to something Windows can handle.

AT+NAME
Querying the modules name with AT+NAME? only works in “full” At mode. If you cannot get AT+NAME? to work you need to bring pin34 HIGH.
Changing the modules name with AT+NAME=newname works in “full” AT mode and “mini” AT mode.

What you should get is:
AT+NAME?, returns
+NAME:HC-05
OK
(or something similar depending what your module is called)

Other commands that require pin 34 to be HIGH are AT+INQ and AT+RNAME. This is not a complete list through.

Full list of AT commands

AT commands list

This list is taken from the EGBT-045MS bluetooth module user guide and not all commands may be supported or work straight away. For example AT+NAME? only works when pin 34 is HIGH.

For more information look at the HC-05 user guide or the EGBT-046S/EGBT-045MS user guide

Next: Linking 2 Bluetooth Modules

Connecting 2 Arduinos by Bluetooth using a HC-05 and a HC-06: Easy Method Using CMODE
Connecting 2 Arduinos by Bluetooth using a HC-05 and a HC-06: Pair, Bind, and Link

 
 

271 thoughts on “Arduino with HC-05 (ZS-040) Bluetooth module – AT MODE”

    • +1 I agree with montassar. I was not able to get all the AT commands until I read this posting. The at+name? was making me nuts. Now, I hold the button and the command works.

      Thanks!

      Reply
      • I never leave a comment, but this article is amazing. I bought bluetooth module to communicate with my electric skateboard 4months ago but nothing work so I leave the bluetooth module. And now thanks to this article it works fine ! I’m so happy !

        Reply
    • Hello,
      me2.
      I did all in your description, but there is no echo from the HC05 (zs-040).

      I connected EN to + 5V
      I pressed the button or did not …

      nothing happens.

      the HC05 is still blinking with 1 Hz.

      Reply
      • @Wilii

        If you connected EN to +5 V, you may have fried your HC-05 module. When connecting signal inputs (including Rx and EN) to a 5 V Arduino output, the connections MUST to go through a voltage divider circuit (as Martyn has shown in his diagrams) or you risk damaging something. Also, be aware that some versions of the carrier board (ZS-040) may not have the EN pin connected to the HC-05 module pin 34.

        Reply
  1. hey, i have this problem, the comunication it’s not going well, it send to me characters like this: ϧ†…. I tried a lot of ways and it’s always the same, :
    AT mode.
    Remember to to set Both NL & CR in the serial monitor.
    BT STATE =
    ««ª ª’•ªFU
    b•´ŠÄ……ϧ†…
    i think it is a problem in the comuniction between the arduino whit my module HC-05 zs404

    Reply
    • In my case (HC-05, ZS-040) it was solved using code posted by twelti on the site http://forum.arduino.cc/index.php?topic=290847.0
      /*
      AT+ORGL (Restore the factory default state)
      AT+UART=115200,0,0 (Set baud rate to 115200, one stop bit and no parity bit)
      AT+NAME=TinyG
      */
      #include
      #define rxPin 10
      #define txPin 11
      SoftwareSerial mySerial(rxPin, txPin); // RX, TX
      char myChar ;
      void setup() {
      Serial.begin(9600);
      Serial.println(“AT”);
      mySerial.begin(38400);
      mySerial.println(“AT”);
      }
      void loop() {
      while (mySerial.available()) {
      myChar = mySerial.read();
      Serial.print(myChar);
      }
      while (Serial.available()) {
      myChar = Serial.read();
      Serial.print(myChar); //echo
      mySerial.print(myChar);
      }
      }

      Reply
    • Go to your serial montor on top right corner and change the baud rate to 9600 which is in the bottom left side of the app

      Reply
    • It sounds like you have the wrong baud rate.

      The modules I have use different speeds; AT mode is 38400, and communication mode is 9600.

      // Start the software serial – baud rate for AT mode is 38400
      BTserial.begin(38400);

      Remember there are 2 different serial communications.
      1 – The arduino to the computer at 9600
      2 – The blue tooth module to the Arduino at 38400

      The baud rate shown in the serial monitor is for the communication between Arduino and computer.

      Reply
  2. this is the last scetch i’m using. i also tried change the baud ratio in the BTserial, i tried whith 1200, 2400, 4800, 9600 etc, but i only have “response” using 38400. I even used the AltsoftSerial library and diden’t work. I check in the net and some other few people has the same problem but no one seems find a solution.

    char serialByte = ‘0’;
    const byte LEDPIN = 13;

    #include
    SoftwareSerial BTserial(10, 11); // RX | TX

    void setup()
    {
    pinMode(LEDPIN, OUTPUT);

    // communication with the host computer
    Serial.begin(9600);

    // Start the software serial – baud rate for AT mode is 38400
    BTserial.begin(38400);

    // LED to show we have started the serial channels
    digitalWrite(LEDPIN, HIGH);

    // Give the user time to enter AT mode
    // wait for the user to enter a ‘1’ to start
    Serial.println(“After entering AT mode, type 1″);
    while (serialByte !=’1′)
    {
    serialByte = Serial.read();
    }

    Serial.println(” “);
    Serial.println(“AT mode.”);
    Serial.println(“Remember to to set Both NL & CR in the serial monitor.”);

    Serial.print(“BT STATE = “);
    BTserial.println(“AT+STATE” );
    Serial.println(” “);
    delay(100);

    }

    void loop()
    {
    // listen for communication from the BT module and then write it to the serial monitor
    if ( BTserial.available() ) { Serial.write( BTserial.read() ); }

    // listen for user input and send it to the HC-05
    if ( Serial.available() ) { BTserial.write( Serial.read() ); }
    }

    and this its what happen when i executed it

    After entering AT mode, type 1

    AT mode.
    Remember to to set Both NL & CR in the serial monitor.
    BT STATE =
    ««ª ª’•ªFE
    b•´ŠÄ……ϧ†…

    Reply
    • I can’t duplicate the problem. I do get some garbage when I use an incorrect baud rate but it is intermittent. As soon as I use 38400 everything works fine.

      Try different pins, for example use Pin 2 and 3 and reseat all the connections.

      Reply
    • hey, did you find the solution to the problem? I got the exact same result as yours on my serial monitor. Thanks in advance!

      Reply
      • The closest I have been to recreating the problem is through using the wrong baud rate.

        Try the different baud rates and note the responses you get. One of then should work but it may not be 38400.

        Reply
        • Hi Pablo and Fibo,

          I was having the same problem, weird characters from the BT Module. It happend to me before, some libraries won’t work fine with the latest version of the Arduino IDE, I was using v 1.6.

          I tried the very same sketch with the Arduino IDE v 1.0 and it all went perfect. Try to download it from the arduino site.

          Hope this work for you.

          Reply
  3. Hi, I got two problems with this HC-05 module.
    1. When I type AT+NAME? I got no response. I do not understand why is that so, I got all responses for AT+ROLE? AT+PSWD? but not AT+NAME? Can answer this ?

    2. I can’t search this HC-05 Bluetooth module with my ios devices. I can find it with other android devices but not my iphone or ipad. How to solve ?

    Reply
    • Updated reply.

      AT+NAME? only works when pin34 is HIGH.
      If using the button switch, close the switch just before sending the command.

      The HC-05 and HC-06 do not work with idevices. Apple products do not support the Bluetooth protocol that the HC-05 /06 units use. If you want to connect to an idevice you will need a BT module that uses BLE / Bluetooth 4.0.

      Reply
  4. we are using ARDUINO MEGA and we also encountered the same problem after entering “AT” then “1”, the serial monitor respond is “BT STATE”. we tried “38400” and “9600” but didnt get any response.

    but when we used ARDUINO UNO. we got an “OKAY” respond from the serial monitor.

    WHY IS THAT SO?
    we really need to use the ARDUINO MEGA

    any help?

    Reply
    • thanks for very informative desription about AT commands applied to HC-05, have you tried to change baudrate on HC-06 using AT+UART ? I failed to change baudrate on my HC-06. thanks

      Reply
  5. Hello Martyn! Thank you for sharing your work. I have successfully connected my uno with hc05 and due with hc05 too and have paired them using AT+LINK Both the hc05 have started blinking together now i want to transfer data from uno to due I have connected a microphone with uno and here is the receiver code of uno :
    #include
    #define rxPin 11
    #define txPin 10
    SoftwareSerial myserial= SoftwareSerial(rxPin,txPin);
    int analogpin=0;
    void setup(){
    Serial.begin(9600);
    myserial.begin(9600);
    }
    void loop(){

    int b=analogRead(analogpin);
    Serial.println(b);
    delay(1000);
    myserial.write(b);

    }
    And on due i have used this code
    void setup()
    {
    Serial.begin(9600);
    Serial1.begin(9600);
    )
    void loop()
    {
    int a=Serial1.read();
    Serial.println(a);
    }
    But the data appearing on the serial monitor of uno is not going on due .
    Can you please help its urgent

    Reply
    • Confirm that they are actually talking to each other. You can do this with 2 serial monitors. You can also set one to send test data; for example “1234” every second.

      Reply
    • hi, how did you paired the two HC 05 bluetooth modules?

      my serial monitor always respond “FAIL” during the “AT+LINK” command.

      i need help thank you:)

      Reply
    • Hello Alman.
      Did you configure a HC-05 using a Arduino due?

      I am trying to do it but having nothing in response from the module.

      Reply
      • I haven’t used a Due but it should work with the HC-05 albeit with some changes.

        The Due has 4 hardware serials so you should use one of these for talking to the HC-05 rather than software serial.

        Since the Due is a 3.3v device you do not need the voltage divider on the HC-05 RX pin. Connect the Due TX pin directly to the Due RX pin.

        The HC-05 needs at least 3.6v on the vcc pin to work correctly. I believe the Due has a 5V out pin, use this rather than the 3.3v out pin.

        Have a look at https://www.martyncurrey.com/using-an-arduino-mega-with-a-hc-05-zs-040-at-mode/.
        This is for the mega but uses hardware serial1 and the same as using serial1 on the Due.

        Reply
        • i have tried the way you mentioned it didn’t work but when I connected the RX pin to RX pin of the board and the TX pin to TX pin then it worked.
          any help :)

          Reply
  6. Starting the bluetooth module

    AT mode.
    Remember to to set Both NL & CR in the serial monitor.
    Enter AT commands

    BT STATE = +STATE:INITIALIZED
    OK
    ERROR:(16)
    OK
    +INQ:3014:8:190258,1F00,7FFF
    OK
    +RNAME:CARDEA_SLAVE
    OK
    FAIL
    +INQ:3014:8:190258,1F00,7FFF
    OK

    any idea why do we get a “FAIL” response? thank you

    Reply
    • RNAME requires the mac address of the remote device: See page 10 of the EGBT-046S/EGBT-045MS user guide. You can download the user guide from https://docs.google.com/file/d/0BxdLxDCD6HidSkRaRTVuNERrQjg/edit

      7. Query Remote Bluetooth Device’s Name

      Command
      AT+RNAME?<addr>

      Response
      +NAME:<name>
      OK

      where <name> = Device name
      <addr> = 48 bit bluetooth address
      in NAP,UAP,LAP format

      Example: Query remote Bluetooth device having address = 00:02:72:0A:3C:7F
      Bluetooth address in NA:UAP:LAP format = 0002:72:0A3C7F
      From Host controller:
      AT+RNAME?0002,72,0A3C7F
      EGBT-045MS response if remote device name is “HC-05”
      +NAME:HC-05
      OK
      EGBT-045MS response if remote device name is unresolved
      FAIL

      I have a HC-06 module with the address = 30:14:10:17:11:79
      This means the command = AT+RNAME?3014,10,171179
      and this gets me:
      +RNAME:HC-06_1
      OK

      The HC-06 is name “HC-06_1”

      RNAME only works for me when pin 34 on the HC-05 is HIGH. When pin 34 is LOW or not connected I get nothing, no reply and no error message.

      Are you able to use AT+INQ and AT+RNAME with pin 34 LOW or not connected?
      On the modules I have I have to set pin 34 HIGH before the commands give a reply.

      Reply
      • the serial monitor responds properly AT+INQ and AT+RNAME, pin 34 is HIGH.
        we only get “FAIL” respond evertytime we use AT+LINK.

        we cannot pair the master and slave module

        Reply
        • the serial monitor is not responding in AT+INIT, AT+INQ, AT+LINK when we are using the METHOD 1. USE THE BUTTON SWITCH

          any help? thanks

          Reply
          • You need to keep pin 34 HIGH. Certain commands like AT+INQ etc need pin 34 to be HIGH. If pin 34 is LOW or not connected then the module does not respond (no reply and no error message).

            This means keeping the button switch closed or adding a connection to pin 34 directly. The button switch, when closed, connects pin 34 to +3.3v

            I am going to solder a wire to pin 34 to make switching HIGH/LOW a bit easier to do. A wire connected to the top of the button switch should also work.

            I have updated the guide and the new information may be helpful to you.

            Reply
            • Hello.
              Your tutorial was the only one using which I could successfully access the full AT functionality.
              But even after powering the PIN34, as soon as I enter the command : AT+INQ, the LED starts blinking fast and there is no other response. As per your advice, I pressed the switch while doing this, but again the same happened…but this time, it prints “OK” instead of printing the addresses.
              I am using the same version as yours.
              Please HELp1

              Reply
    • I will try to do a write up on this but in the meantime here are the basic steps

      Pin34 on the HC-05 needs to be HIGH for all commands to work.

      1. make sure the baud rates on the HC-05 and the HC-06 are the same
      2. make sure the passwords on the HC-05 and the HC-06 are the same
      3. find the address of the slave module
      4. pair with the slave device
      5. bind the slave device
      6. set the HC-05 to only connect with paired devices
      7. link to the slave device

      1 and 2 are self-explanatory

      3. find the address of the slave module. You can do this using the HC-05:
      Turn on the HC-06. Turn on the HC-05

      On the HC-05 do the following:
      – Clear any previously paired devices – AT+RMAAD
      – Put the HC-05 in Master Mode – AT+ROLE=1
      – After changing the mode you may need to reset the module – AT+RESET
      – Allow the HC-05 to connect to any device – AT+CMODE=0
      – Set inquiry to search for 5 devices and 9 seconds – AT+INQM=0,5,9
      – Initiate the SPP profile – AT+INIT (if SPP is already active you will get an error(17) which you can ignore)
      – Search for other devices – AT+INQ

      This will bring up a list of found devices. One of them should be the HC-06.
      The reply should be in the format +INQ:address,type,signal
      The address will show something like +INQ:15:FF:F3241B,1F00,7FFF

      To use the address in AT commands you need to change the colons into commas. If you get more than one found device you check the names with: AT+RNAME?15,FF,F3241B

      Once you have confirmed you have the correct module and correct address you need to pair it with the HC-05

      4. pair with the slave device – AT+PAIR=<addr>,<timeout>
      e.g. AT+PAIR=15,FF,F3241B,9
      If the HC-05 cannot pair with the HC-06 within 9 seconds you will get an error message.

      5. bind the slave device – AT+BIND=<address>

      6 set the HC-05 to connect to bound devices only – AT+CMODE=1

      7 Link to the slave device – AT+LINK=<address>

      Once set, on start up the HC-05 should automatically connect to the HC-06.

      Let me know how you get on.

      Reply
  7. Hello, do you happen to know any way in which an hc-05 would suddenly malfunction (as in not respond to AT commands and serial communication problems)? Or have you heard of any such cases?

    I’ve already gone through several hc-05’s.
    I have absolutely no idea why this happens as there isn’t any commonality between the malfunctioning (it doesn’t happen as a direct result of something – one moment, it works and when I try again later on it just suddenly doesn’t).

    Reply
    • I haven’t come across this. My modules have been fairly robust – dropped on the floor, connected the wrong way, etc.

      If the LED is working normally then you know the module is still alive?

      Are you using a voltage divider on the RX pin? You can damage the mini Bluetooth module by connecting 5V directly to it.

      Reply
      • Turns out I was sending 5v signals to BT Rx pin despite connecting 3.3v to the vcc. I guess that was slowly damaging the modules. Hopefully no more of them will die.

        Thank you for the advice!

        Reply
  8. hi martyn,

    i have read from other source that it is possible to connect 2 slaves to only 1 master module if your bluetooth module supports “multi instance SPP”

    do you have an idea on how to do this? and how to determine if your bluetooth module supports the “multi instance SPP” ?

    thank you :)

    Reply
    • sorry, I have never done this. It does sound interesting and if possible may be an easy way to create a small network. Not sure when I will get time to investigate though.

      Reply
  9. Hello,
    Thanks for sharing fine information.
    Instructions for Arduino UNO, it only worked on ports 10-11 9600 x 9600
    I have the HC-05 zs-040 with the button on breakout board over EN Pin.

    First you have to program arduino UNO with the code below, without the data pins plugged otherwise, it does not upload, then you connect data cables to pins 10rx-11 tx with voltage divider and power arduino with the module fully connected, then just open the terminal and push the small button on the module for some seconds, the led continues to flash fast as before ( I didn´t manage to work with it blinking slow) all the commands work, some you have to hold the small button while tapping enter. Hope it throws some light to others with the same problem

    // Basic Bluetooth sketch HC-06_01
    // Connect the Hc-06 module and communicate using the serial monitor
    //
    // The HC-06 defaults to AT mode when first powered on.
    // The default baud rate is 9600
    // The Hc-06 requires all AT commands to be in uppercase. NL+CR should not be added to the command string

    #include
    SoftwareSerial BTserial(10, 11); // RX | TX
    // Connect the HC-06 TX to the Arduino RX on pin 2.
    // Connect the HC-06 RX to the Arduino TX on pin 3 through a voltage divider.
    //

    void setup()
    {
    Serial.begin(9600);
    Serial.println(“Enter AT commands:”);

    // HC-06 default serial speed is 9600
    BTserial.begin(9600);
    }

    void loop()
    {

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

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

    }

    Reply
  10. Hello,
    I am unable to connect to the AT mode, only the third method worked but the settings are reduced. I have a GW-040 model, used this tutorial to be identical. Does anyone know any specific tutorial for this model (GW-040) or that works.

    Reply
  11. Hi, I’m trying to connect my zs-040 module with my android phone using the AT+LINK command but the only response i get is FAIL. All other commands are working. what could be the problem with AT+LINK=AA,70,39F04A

    Reply
    • You didn’t say but I am assuming you have the HC-05.

      I’m not 100% certain but I believe you have to initiate the connection from the phone.

      Are you able to establish a connection from the phone to the BT module when using the phone to initiate the connection?
      If you have the HC-05, does the phone appear when you scan for bluetooth devices using the HC-05?

      Reply
  12. Hi Martyn, first of all i wanna tell you it’s great to have all this information about hc 05. Thanks for sharing the information needed. I have a problem and hope you can help me, when sending an AT command, I can only send one at a time, and after that, no value is return, I have to disconnect the VCC from BT and reconnect it to send another AT command, what you think can be the solution ?.

    Reply
  13. Can you explain what you mean by one at a time. Do you mean the first command works but the second,third etc does not?
    Are you sure you are in AT mode?
    Does “AT” work, do you get the “OK” reply?

    What model HC-05 do you have? Do you have the zs-050?
    Do you have the correct line endings set?
    Can you make contact with another device, for example an Android device?

    Reply
    • Exactly, first command works but the second,third etc doesnt.
      im sure that AT mode is on cause led blinks each 2 seconds (aprox), and when send an AT command i ge an OK, but only the firts time.
      I got a zs-040, and i already tried some AT comands. Also i tried to connect with my android, and it works.

      Reply
  14. Do you have “Both NL & CR” set in the serial monitor?

    using sketch “Basic Bluetooth sketch HC-05_02_9600+ECHO” what do you get in the serial monitor?

    Reply
    • When sending an “AT” command, I got “OK” reply only at first time, and after that, no value is return when I tried same thing 2nd,3rd time etc. I have connected BT HC05 module to computer with USB to TTL converter (CP2102). Connection is correct and I have tested each and every baud rate as well.
      While if I connect this BT module with my android then data communication is working fine.
      The thing is only I can’t able to get response to any command while AT command mode is enabled again(Conclude because led blinks each 2 seconds (aprox)).
      what you think can be the solution ?.

      Reply
      • All I can suggest is:

        Confirm what module you have. There are several that look the same but use different firmware. Once you know look for the data sheet.

        If you get an OK then you have the correct baud rate and need to try different command formats. Try different line end characters.

        Reply
  15. In your method 2 you are using a transistor on ground to switch power to the module. Then in your sketch you have

    // set pin 34 HIGH
    digitalWrite(BT_PIN34, HIGH);
    delay(100);

    // turn on the HC-05
    digitalWrite(BT_POWERPIN, HIGH);

    But setting pin 34 high while you have the ground disconnected (BT_POWERPIN is still low) will do nothing as without ground the high on pin 34 has no place to go.

    Reply
      • If this works it’s pure luck as there will be a race condition between VCC and Pin 34 when ground is connected [digitalWrite(BT_POWERPIN, HIGH)]

        Reply
        • I’ve tested the above circuit and it appears to work fine. It may be that there is protection on the BT module.

          However, you are correct that there may be an issue and I have updated the guide. The example now uses a PNP transistor on the high side.

          Reply
  16. Hi, when the hc-05 sends for example the ok response, does is send \r\n at the end of the data or end sort of characters that shows that it wont transmit anymore.. As doing an array and pasting the response send by the bt on an lcd. Thnks

    Reply
    • Yes there are NL and CR characters after the visible characters. If you are displaying the received data on an LCD you will need to remove them.

      You can perform a simple test by comparing the character just received with 10 or 13. 10 = NL. 13 = CR

      c = Serial.read();
      if (c==13) { … }
      if (c==10) { … }

      The NL character is the last character so if c==10 you are at the end of the line.

      Reply
  17. I used method 1 to my HC-05 and Uno board. but It doesn’t work… as yours. there isn’t any response in serial monitor when I type “AT”. What is the problem?… :(
    I think my HC-05 enters AT mode because the red led blink in 2s interval. but AT mode doesn’t work i think. please let me know how can I do it…

    Reply
  18. It sounds like you have the wrong baud rate or the connections are not correct.

    1. Double check the connections.

    2. Using the Basic Bluetooth sketch HC-05_AT_MODE_01 sketch, run the sketch, open serial monitor and cycle the power of the HC-05. If you do not get a start up message, try a different baud rate. Start at 9600 and keep going until you find one that works.

    Reply
  19. I can get the HC_05 led to blink slowly but it will not give any feedback to my AT commands.
    have tried 9600 and 38400 as AT baudrate but no luck.
    Any suggestions?

    Reply
    • Have you selected “Both NL & CR” in the serial monitor?

      Check the connections. You can follow the second example on the https://www.martyncurrey.com/arduino-with-hc-05-bluetooth-module-in-slave-mode/ page. If 9600 does not work try other baud rates.

      Using the same sketch, open serial monitor and then cycle the power to the BT module. If you have the correct baud rate you should get a start up message. If you do not get a message, change the baud rate, recompile etc and try again.

      It is worth confirming you are in AT mode. Start the BT module in normal mode and use an Android device to scan for BT devices. Your HC-05 should be listed. Now put the HC-05 in to AT mode and rescan. The HC-05 should now disappear. If it still shows then it is not in AT mode.

      Lastly, try to confirm what module you have. Newer ebay modules are using the same breakout board but use a a different firmware. See the FC-114 posts.

      If you are still having trouble post a photo of your module and let me know what name is reported when you scan for BT devices.

      Reply
  20. Thank you for your reply :)
    I had written a long reply with lots of data and details when I discovered that a 10M resistor had slipped into my stack of 1M’s and was playing a trick on my voltage divider.
    Thank you for your post.

    Reply
  21. Hello,May I know how to wire the two pins marked in HC-05,STATE and EN.Could you please specify how two wire these two pins generally?

    Reply
  22. great work, thanks

    with the method1 for hc05 zs-040, you can query name with AT+NAME? without connection pin34
    just press the push button and send command serial monitor, it responds
    +NAME:HC-05
    OK
    and i think same for “full AT” commands, beware if you change baudrate uart

    Reply
  23. Hi Martyn!
    I shorted pin 34 with EN pin. But now I cannot see my LED on BT module blinking 5 times a second by providing digital LOW to EN pin. Anyhow, if I provide digital HIGH to EN pin it blinks on/of f every second. What am I doing wrong here? How can I control configuring BT module either in Command mode or in Data mode as per my wish through my Arduino Code. Kindly help!

    Reply
    • Start the BT module first, then bring pin 34 HIGH. This puts you in AT mode using the user defined baud rate. To exit AT mode bring pin 34 LOW.

      I think Example 4 is what you need. This allows the Arduino to control entering and exiting AT mode.

      Reply
  24. Hi,

    I have pin 34 high (3.3v) and still AT+INIT, AT+INQ, AT+PAIR etc do not work, hence not getting no response what so ever when I enter the AT commands.

    Any suggestions?

    Thanks,

    Kyle.

    Reply
  25. Hello Martyn,
    I have 2 arduino uno boards, each connected with HC05(with button and EN pin-ZS040). Of these I want to use my 1 HC05 module as master for some time say for a period of 1 minute and then as a slave for same period of time (1 minute); at this time I want to keep my other HC05 module as slave for first one minute and then as master for other minute. Within this span I want these 2 modules to connect with each other, exchange information and raise a flag when exchange is over; And then again configure one as master and other as slave and repeat the process. But I am totally confused about how should I do this using just arduino code without any human intervention. Could you kindly help and guide me here?

    Reply
  26. Hi Bhoomika,

    Unfortunately I don’t have the time to create the code but this would be a really good way to learn Ardiono and Bluetooth.

    If you are not sure about controlling the HC-05s start with a manual process, get the 2 Arduinos communicating manually (you enter the commands via the serial monitor) and after you have worked out what commands to use and when you can create a sketch and let the Arduino do it.

    Start with example 4 above. Change the code so that the Arduino controls when the BT module uses Master mode and when it uses Slave mode. I would suggest adding an LED to the Arduino to show the mode the HC-05 is using. When doing the code use millis() rather than delay. You can find more information by search for “blink without delay” on the Arduino forums. After you have got the first Arduino working start on the second.

    .

    Reply
  27. Hi,
    I tried to follow your excellent guidelines to make a connection with a PC instead of an Arduino but I have not been able to make it work.

    Will you be so kind to include some guidelines on how to do it with a PC?

    Thanks in advance!!

    Reply
    • It is my understanding that the PC has to be the master device and has to initiate the connection. This means the HC-05 should be in slave mode. Turn on the HC-05 and then use the PC to search for Bluetooth devices.

      Reply
  28. Hi Bhoomika,
    remember you need to add “\r\n” to the end of commands. BTserial.println(“AT”) should work but I prefer to add manually using print rather than println – BTserial.print(“AT\n\r”)

    Reply
    • The only way I know in AT mode is to issue a LF and CR. This results in an error but once you have the error you can send new commands again. In data mode I don’t think you can flush the modules buffer.

      Reply
  29. Hi Martyn,
    thanks for a great tute. I’m using HC 05 and HC 06 on two nano clones wired as per your tute.
    I followed it exactly and got the two BT units communicating however the two serial monitors only display (x,€ ϴ) when sent alpha-numeric chars from the other monitor. Also the SM on master displays the sent characters as typed. It looks like a baud rate issue but the baud rates are all set to 38400.

    Any suggestions would be appreciated.
    cheers Steve

    Reply
  30. Hi, thank you very much for this tutorial it helped me a lot but I still have a problem. I get the OK respond and also the ones to AT+NAME and others but when I want to change the name or the password using commands as AT+NAMEmyname or AT+PSWDnnnn it sends me ERROR(0)
    Do you have an idea of what the problem could be ? (sorry for my bad english)

    Reply
    • Do you have pin34 HIGH?

      Pressing the small button switch makes pin34 HIGH so just before sending the commands press and hold the button switch. Wait for the reply and then you can release.

      Reply
  31. I have read many of your post about hc-05 module. I also experimenting with HC-05 FC-114 and eventually enter into AT mode following instruction here (after so many failed attempt) so thanks.

    But I wonder how many type of break-out board and firmware available out there? so far I assume you have encounter three type of breakout board (FC-114, ZS-040, FS-040 ) and bolutek firmware. But my FC-114 have firmware version: 2.0-20100601 which i’m not sure whose firmware is that (linvor, bolutek, or another).

    So can you point out a list of difference between various board and firmware you have encounter? thanks

    Reply
  32. Hi,

    Thank you for sharing your work!
    I have a question, hope you help me.
    I want to tranfer files between two Arduino UNO’s using hc-05 bluetooth module. I have been searching for a couple of hours and seems nobody had similar project with me. Is it possible sending an audio file (.WAV in my case) from an Arduino to another Arduino using hc-05 module?
    Thank you in advance!

    Reply
  33. Hello

    Excelent article, thanks a lot for sharing this.

    I can use and test each and everyone of the AT commands succesfully (Method 2). I can also pair my HC-04 ZS-40 to my Android smart phone but I just don’t know how to stablish a connection between them. I’ll appreciate any hints to acomplish such connection.

    Regards

    Reply
  34. I’ve googled for a long time.. Can’t find out how to exit command mode. anyone? I see you using AT+RESET. Is that the only way? Wondering because if I tie the KEY pin HIGH i’m going to be stuck in command mode every time the module reboots.

    Reply
  35. Please help me!!!
    I followed your instructions and changed the name if my module.
    Then turned off my module and powered it on again.
    I was able to find the new name on my phone and was able to connect it BUT :-(

    My HC-05 Enters Command mode insted of data Transfer mode

    (I am sating that my bluetooth module enters Command mode by looking at the LED blinking)

    Reply
    • I also Tried AT+RESET it resets my name password an all.
      But still if I pair it enters Command mode

      PLS pls help

      Reply
        • Martyn, I tried it.

          No use, Still having the same problem.

          My module has a button on top of EN(key) pin. I have to press in while making the 34pin high. It worked perfectly in command mode. It still does work in Command mode, but when i pair my module it does not show data transfer mode the led bliks like it does in Command mode when paired.

          Please help!!

          Reply
  36. Hello sir.I have make a bluetooth 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?Thank you for your time

    The bluetooth that i use is HC-05

    My code:

    #include

    Servo SERVO_1; // Initialize Servo1

    // Motor Control Variables
    int PWM1 = 9;
    int ENABLE1 = 8;
    int PWM2 = 5;
    int ENABLE2 = 7;
    int PWM3 = 3;
    int ENABLE3 = 4;
    int PWM4 = 6;
    int ENABLE4 = 2;

    void setup() {
    SERVO_1.attach(10);
    Serial.begin(9600);
    pinMode(ENABLE1, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
    pinMode(ENABLE2, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
    pinMode(ENABLE3, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
    pinMode(ENABLE4, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος

    }

    void loop() {

    // see if there’s incoming serial data:
    if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    int incomingByte = Serial.read();
    // action depending on the instruction
    // as well as sending a confirmation back to the app
    switch (incomingByte) {
    case ‘F’:
    moveForward();
    Serial.println(“Going forward”);
    break;
    case ‘L’ : // Case ‘L’ is received,
    SERVO_1.write (180); // Στρίψε Αριστερά.
    SERVO_1.attach(10);
    break;
    case ‘N’:
    turnright();
    Serial.println(“Turning right”);
    break;
    case ‘M’:
    turnleft();
    Serial.println(“Turning left”);
    break;
    case ‘O’ : // Case ‘L’ is received,
    SERVO_1.write (0); // Στρίψε Αριστερά.
    SERVO_1.attach(10);
    break;
    case ‘B’:
    moveBackward();
    Serial.println(“Going forward”);
    break;
    case ‘P’:
    SERVO_1.write(90); // Στρίψε Αριστερά.
    SERVO_1.attach(10);
    break;
    case ‘S’:
    moveNone();
    Serial.println(“Stopping”);
    break;
    default:
    // if nothing matches, do nothing
    break;
    }
    }
    }
    void moveForward() {
    // turn the driving motor on to go forwards at set speed
    digitalWrite(ENABLE1, HIGH);
    digitalWrite(ENABLE2, HIGH);
    digitalWrite(ENABLE3, HIGH);
    digitalWrite(ENABLE4, HIGH);
    analogWrite(PWM1, 255);
    analogWrite(PWM2, 255);
    analogWrite(PWM3, 255);
    analogWrite(PWM4, 255);

    }

    void moveBackward() {
    // turn the driving motor on to go backwards at set speed
    digitalWrite(ENABLE1, LOW);
    digitalWrite(ENABLE2, LOW);
    digitalWrite(ENABLE3, LOW);
    digitalWrite(ENABLE4, LOW);
    analogWrite(PWM1, 255);
    analogWrite(PWM2, 255);
    analogWrite(PWM3, 255);
    analogWrite(PWM4, 255);
    }
    void turnright() {
    digitalWrite(ENABLE1, HIGH);
    digitalWrite(ENABLE2, HIGH);
    digitalWrite(ENABLE3, LOW);
    digitalWrite(ENABLE4, LOW);
    analogWrite(PWM1, 255);
    analogWrite(PWM2, 255);
    analogWrite(PWM3, 255);
    analogWrite(PWM4, 255);
    }

    void turnleft() {
    digitalWrite(ENABLE1, LOW);
    digitalWrite(ENABLE2, LOW);
    digitalWrite(ENABLE3, HIGH);
    digitalWrite(ENABLE4, HIGH);
    analogWrite(PWM1, 255);
    analogWrite(PWM2, 255);
    analogWrite(PWM3, 255);
    analogWrite(PWM4, 255);
    }
    void moveNone() {
    // turn the driving motor off
    digitalWrite(ENABLE1, 0);
    digitalWrite(ENABLE2, 0);
    digitalWrite(ENABLE3, 0);
    digitalWrite(ENABLE4, 0);
    analogWrite(PWM1, 0);
    analogWrite(PWM2, 0);
    analogWrite(PWM3, 0);
    analogWrite(PWM4, 0);
    SERVO_1.detach();
    }

    Reply
    • Hi Jack,

      probably the best method is to use the STATE pin on the HC-05. When the HC-05 is connected the STATE pin goes HIGH. Connect this to the Arduino and then in your sketch keep checking the pin state. HIGH means connected, LOW means not connected.

      Reply
  37. Thank you sir for your reply.I modify the code and now i am getting this error
    case label “S” is not within a switch statement.

    What does this mean?Thank you again for your time

    The modified code:

    #include

    Servo SERVO_1; // Initialize Servo1

    // Motor Control Variables
    int PWM1 = 9;
    int ENABLE1 = 8;
    int PWM2 = 5;
    int ENABLE2 = 7;
    int PWM3 = 3;
    int ENABLE3 = 4;
    int PWM4 = 6;
    int ENABLE4 =12;
    int BTState=2;

    void setup() {
    SERVO_1.attach(10);
    Serial.begin(9600);
    pinMode(ENABLE1, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
    pinMode(ENABLE2, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
    pinMode(ENABLE3, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
    pinMode(ENABLE4, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
    pinMode(BTState, INPUT);
    }

    void loop() {

    //Stop car when connection lost or bluetooth disconnected
    if(digitalRead(BTState)==LOW) { case ‘S’: }

    // see if there’s incoming serial data:
    if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    int incomingByte = Serial.read();
    // action depending on the instruction
    // as well as sending a confirmation back to the app
    switch (incomingByte) {
    case ‘F’:
    moveForward();
    Serial.println(“Going forward”);
    break;
    case ‘L’ : // Case ‘L’ is received,
    SERVO_1.write (180); // Στρίψε Αριστερά.
    SERVO_1.attach(10);
    break;
    case ‘N’:
    turnright();
    Serial.println(“Turning right”);
    break;
    case ‘M’:
    turnleft();
    Serial.println(“Turning left”);
    break;
    case ‘O’ : // Case ‘L’ is received,
    SERVO_1.write (0); // Στρίψε Αριστερά.
    SERVO_1.attach(10);
    break;
    case ‘B’:
    moveBackward();
    Serial.println(“Going forward”);
    break;
    case ‘P’:
    SERVO_1.write(90); // Στρίψε Αριστερά.
    SERVO_1.attach(10);
    break;
    case ‘S’:
    moveNone();
    Serial.println(“Stopping”);
    break;
    default:
    // if nothing matches, do nothing
    break;
    }
    }
    }
    void moveForward() {
    // turn the driving motor on to go forwards at set speed
    digitalWrite(ENABLE1, HIGH);
    digitalWrite(ENABLE2, HIGH);
    digitalWrite(ENABLE3, HIGH);
    digitalWrite(ENABLE4, HIGH);
    analogWrite(PWM1, 255);
    analogWrite(PWM2, 255);
    analogWrite(PWM3, 255);
    analogWrite(PWM4, 255);

    }

    void moveBackward() {
    // turn the driving motor on to go backwards at set speed
    digitalWrite(ENABLE1, LOW);
    digitalWrite(ENABLE2, LOW);
    digitalWrite(ENABLE3, LOW);
    digitalWrite(ENABLE4, LOW);
    analogWrite(PWM1, 255);
    analogWrite(PWM2, 255);
    analogWrite(PWM3, 255);
    analogWrite(PWM4, 255);
    }
    void turnright() {
    digitalWrite(ENABLE1, HIGH);
    digitalWrite(ENABLE2, HIGH);
    digitalWrite(ENABLE3, LOW);
    digitalWrite(ENABLE4, LOW);
    analogWrite(PWM1, 255);
    analogWrite(PWM2, 255);
    analogWrite(PWM3, 255);
    analogWrite(PWM4, 255);
    }

    void turnleft() {
    digitalWrite(ENABLE1, LOW);
    digitalWrite(ENABLE2, LOW);
    digitalWrite(ENABLE3, HIGH);
    digitalWrite(ENABLE4, HIGH);
    analogWrite(PWM1, 255);
    analogWrite(PWM2, 255);
    analogWrite(PWM3, 255);
    analogWrite(PWM4, 255);
    }
    void moveNone() {
    // turn the driving motor off
    digitalWrite(ENABLE1, 0);
    digitalWrite(ENABLE2, 0);
    digitalWrite(ENABLE3, 0);
    digitalWrite(ENABLE4, 0);
    analogWrite(PWM1, 0);
    analogWrite(PWM2, 0);
    analogWrite(PWM3, 0);
    analogWrite(PWM4, 0);
    SERVO_1.detach();
    }

    Reply
  38. The check on the BTstate should not use the case statement.

    use something like (not full code)

    if (BTstate pin == HIGH)
    {
    if (Serial.available() > 0) {
    int incomingByte = Serial.read();
    .
    .
    .

    }

    In this way you are only reading and processing commands when connected.

    Reply
  39. Great and usefull guide!

    I personaly have a bare HC-05 connected to a Teensy LC (3.3V) so I can directly wire everything. Entering AT mode on booting works nice and easy but if I try method 3 or 4 I only get an Error(0) when I write AT :/

    Is this firmware related? And do you know where I can get the firmware your BT module uses?

    Reply
    • After applying power, bring pin 34 HIGH and keep it HIGH. This will enter AT mode using the baud rate you set for communication. If you have not changed the baud rate it will use the default speed which is usually 9600.

      Reply
  40. Martyn,
    thank you for your great work.
    I’ve bought 20 pcs HC-05 / ZS-040 again. The new ones differ from the old ones in that the „STATE” pins don’t show whether the devices are connected or not, but these pin are floating.
    Could you recommend some solution? Perhaps there are commands to set these features.
    Using sw work-around like “AT STATE?” command would mean some problems.
    Regards
    Tamas

    Reply
    • Check which firmware you have and then see if one of the pins on the actual Bluetooth module (the small daughter board) is being used. It may be that the pin used is not connected. If this is the case you can connect a wire directly to the pin.

      Reply
  41. Hi Martyn, you have done a great work explain how the hc-05 works, but i have a trouble, my BT conects but don´t give me an answer when I send “AT” or any other message, I checked all conections and are ok, I´m using an Arduino MEGA, I hope that you can help me

    Reply
    • Hi,
      double check the connections, the resistor values and the baud rate.

      Almost every time somebody reports an issue it is because they have a wrong baud rate, incorrect connection or the resistor are incorrect.

      After rechecking the connections and resistor confirm you are actual entering AT mode by checking the LED blink rate.

      Since you are using the mega, you should one of the extra hardware serials rather than software serial.

      If still having issues take a step back and confirm basic communication works in slave mode. See https://www.martyncurrey.com/arduino-with-hc-05-bluetooth-module-in-slave-mode/

      Reply
  42. Martyn,
    thank you for your great work.

    In method 4, in communication mode HC-04 led is not blinking and in at mode led is blinking @ 2 sec interval, However, I can’t get response from HC-04 in serial monitor for at commands.

    I have checked my connections and resistors value.

    Reply
  43. Hey

    Thanks for the detailed information.

    I’m trying to set things up but I’m conncting hc-05 to my PC using RS232 USB TTL cable. No arduino.

    I’m able to get the led to blink slowly by holding the key down while powering up, which means its in AT mode.

    Set arduino serial to NL+CR, 38400 baud rate.

    Getting no response on AT commands.Just accepts the command but no output. What am I doing wrong?

    Reply
  44. Hi, Martyn

    I am a Beginner Bluetooth Module User!
    I have a HC05 Compatible XM15B Module from
    Sunflower SMART China.

    The Description says HC05/HC06 Compatible???

    My Problem is that i have set the Baud Rate
    with AT+UART=300,0,0 to 300 Baud.
    In HC05 Manual the minimum Baud Rate is set to 1200

    Now i cant get a AT-Command Mode Connection
    to Change the Settings
    It only returns “00000000” or “nul” or nothing at all?
    when I change Baud Rate in Terminal
    i get confusing unknow Characters like C0 FE or so?
    I have now tried a lot on Terminal Settings but nothing
    worked!
    Can you help me,please?
    Thanks
    Hermann Knopp

    Reply
    • If you really have set the baud rate to 300 bps you can either reset the module back to factory settings with AT+ORGL or use a terminal app (such as putty) that can use 300 bps.

      It looks like this module has a slightly different firmware to most common HC05s, therefore, if not already, get the correct data sheet.

      Reply
  45. Hi. In Entering AT Mode Method 3. Close the small push button switch after the HC-05 is powered. U said we need 2 dividers between arduino and Rx of BT. But just one of resistors is realy on the line between Rx BT and arduino. Other one is between Rx and ground. Sorry i didnt understand

    Reply
    • Two resistors connected in this way form a voltage divider.

      The BT RX pin is 3.3V and the Arduino TX pin is 5V so we need to convert the 5v to 3.3v. Using a voltage divider is an easy way to do this.

      As a quick guide to the voltage divider; 1K + 2K = 3K. 1K is a third of 3K so it reduces the voltage by a third.
      One third of 5V is 1.66 and 5-1.66 = 3.33 which is what we want. Putting the resistors the other way would reduce the voltage by 2 thirds.

      For more information on voltage dividers have a look at the Sparkfun tutorial – https://learn.sparkfun.com/tutorials/voltage-dividers

      Reply
      • Oh umm okay. So we need a 2K resistor between RX and GND. Okay that makes a Y shape. I got it. We connect these to RX and TX of arduino. Why we connect them to D2 and D3? We have TX and RX !

        Reply
  46. SoftwareSerial BTserial(2, 3); // RX | TX

    If i change this to ;

    SoftwareSerial BTserial(RX, TX); // RX | TX
    So my pins is to nir.ally RX TX? True logic?

    Reply
    • You cannot simply use RX and TX unless you define them as variables and give them a value.

      While getting things to work, keep it simple, use the actual pin numbers.

      Reply
  47. Hi Marty,

    I designed a specific breakout PCB to access pin 34 on the module using method 4, the PCB layout is based on the module’s datasheet specifications from
    http://www.rasmicro.com/Bluetooth/EGBT-045MS-046S%20Bluetooth%20Module%20Manual%20rev%201r0.pdf

    and this is how the layout looks like

    http://imgur.com/DUrMW6n
    http://imgur.com/X1wKbMr

    I tested the module on this PCB and the communication mode works fine, however, I’m attempting to access the AT mode using method 4 but I’m not getting any results. Can you please advise on what I’m doing wrong here?

    Reply
  48. i have hc-05 (ZS-040) , i can access AT commands when the bluetooth is not paired by device (in my case is android) , my question is why the AT commands is working when the bluetooth is not connected / paired with my android smartphone but doesn’t working when the bluetooth is connected / paired to my android smartphone ?

    Reply
        • that’s right.

          None of the classic Bluetooth modules I have can send AT commands over the connection.There may be some available but I am not familiar with them.

          One that I know that allows it is the HM-10 but that is BLE not classic Bluetooth.

          Reply
  49. Hi,
    I am trying to switch on an led with HC05 and arduino.So when i code the arduino with 1 as on and 0 as off,it works with my phone but if i type 2 also it switches on.Can you find the problem?
    Thnx

    Reply
  50. Thanks for sharing this knowledge. I’m really looking forward to getting started this weekend with this explanation/tutorial to hand :)

    Reply
  51. Hi Martyn.

    I have an issue. I’m trying to change my baudrate. When I load your sketch and connect like in your diagram, I open the serial monitor and this comes up

    Sketch: C:\Users\Josh\AppData\Local\Temp\arduino_modified_sketch_512396\SerialPassthrough.ino
    Uploaded: Oct 20 2017

    BTserial started at 9600

    BUT if I type AT and click Send I dont get any responce. Please help me!

    Reply
  52. Hi, how could I take my HC-05 module out of AT Command Mode without disconnecting the Arduino? I have a system which automatically puts the module into AT Com mode, but then in order for devices to be able to connect it needs to be taken out of AT Command mode and into its normal state… I’ve tried resetting the baud rate and nothing happened. Anyone know how I could take the module out of AT Command Mode and into it’s normal state without disconnecting the arduino?

    Reply
  53. Thanks now my relay board working, first has some proplems but i read sometime all you instruction, and now have paired and BT work fine, only serial monitor all position work crazy, bauds have ok, text coem, but all letter coem own row, change newline or other alltime come only all letters own row. and relay board have different, if send all off relay board have led on and external relay after light off. and send all on relaboard leds have off and external light on,

    Reply
  54. after hours of frustrating tests with no results I figured out that I have to write the AT-commands in capital letters (AT..) instead of (at…) and then I got a response.

    Reply
    • For examples and testing I like to use the serial monitor. This means I cannot use the hardware RX and TX pins.

      If you have a project that does not need to use the serial monitor then the hardware RX and TX pins are the best choice for serial communication.

      Reply
  55. HELP ME,
    i am change the password but error 1D,please solve my problem

    OK
    +PIN:”1234″
    OK
    ERROR:(1D)
    VERSION:3.0-20170609
    OK
    ERROR:(1D)

    Reply
    • Use this “” if you want to change your password.

      example
      AT+PSWD?
      +PIN:”1234″

      you change to 4321
      AT+PSWD=”4321″
      OK

      so now your password has been changed.

      Reply
  56. Thanks Martyn. I never would have figured this out without you — I could not get AT mode to save my life. In my case, the LED was just a red herring. It flashes at ~2.5 Hz upon power-up, and the button has no effect on that no matter when you press it or for how long. The LED only changes to two quick-flashed every couple of seconds upon successful Bluetooth connection. My LED rate has no relationship at all with AT mode. It never crossed my mind that it might only accept AT commands WHILE the button was being held down. A micro (or is it a mini?) binder clip holds that darned button down nicely for me.

    Reply
  57. NIce Tutorial. I Follow this tutorial use HC-05 . I get version is 3.0-20170601. But AT+INQ is ERROR. its show as ERROR(1F). AT+INIT is ERROR (17). Can you help me for this problems ?

    Reply
  58. I have a HC-05 module and I think I´m in AT mode the Led on the board is blinking slowly, like 2 secons ON next two seconds OFF. But when I send some commands I got no answer back pls help me, I need to know the adress from the bluetooth module.

    This is my wiring:

    I have double checked the wiring and I have everything connected like Im supposed to…
    EN -> 3.3V
    Vcc -> 5v
    Gnd -> Arduino Gnd
    Txd -> Pin 9
    Rxd -> Pin 8
    State -> Nothing cause im not using it.

    My HC-05 module:

    https://lh3.googleusercontent.com/VUkOFY-JpizP5igBIftCabtgG4ITsunU_Ax7a97u52b47CjHXbHCiLFyDk6hAqNJEMzUvA=s85

    Reply
  59. Bonsoir,
    Dans mon cas je n’ai absolument aucune réponce du module ! J’ai un HC-05 ZS-040 et je ne parviens pas du tout à le configurer comme je le souhaite ! J’ai essayé toutes vos manip mais rien de fonctionne

    Reply
  60. Hi there, with the Hc-06 I can just use this simple code (below) to change name/pin of the board (just plugging in in D0/1 (TX/RX) after uploading the code to the board and then reset it). Found here -> https://www.youtube.com/watch?v=jKWTVXj8JKo
    However this won’t work with the HC-05. Is it me or can you confirm that this approach won’t work with HC-05?
    Thanks!

    void setup() {
    Serial.begin(9600);
    delay(5000);
    Serial.print(“AT+NAMEHC-06-1”);
    delay(2000);
    Serial.print(“AT+PIN0000”);
    delay(2000);
    }

    void loop(){}

    Reply
    • The HC-06 is in command mode when first turned on. The HC-05 is not.
      The HC-05 has to be put in to command mode manually before (see above) you can change the name. Once you have the HC_05 in command mode you can use a sketch to issue commands.

      Reply
  61. Hi there,
    I have a HC-05 module. I might be in AT mode because the module’s Led is blinking, 2 seconds ON and then two seconds OFF (I connect pin 34 to 3.3V). However, I can’t get any answers back at my AT commands. Could you help me ? Thx

    Ps: Forgive my bad English please ;)

    Reply
  62. HEY, I´m paring HC-05 modules but when I do command AT+ADDR? the response is:

    +ADDR:21:13:AF1

    so when I try to set the master to connect to this address they response this:

    ERROR:(7)

    help me pls

    Reply
  63. Hello ,
    i’am a problem.
    AT reponse is OK
    AT+VERSION reponse is OK
    AT+NAME reponse is OK
    AT+UART no reponse
    AT+STATE reponse is Error 103
    AT+ROLE reponse is Error 103
    AT+CMODE no reponse
    Connections according to this site. Pin 34 to 3,3v
    Please help me

    Reply
  64. Its works, thanks a lot. your process is really good and its works with me, while I tried lots of codes and pin connections but nothing works to change AT mode. AT command not replying anything. but your process perfect as you describing. Thank you

    Reply
  65. I Follow this tutorial use HC-05 . I get version is 3.0-20170601. But AT+INQ is ERROR. its show as ERROR(1F). AT+INIT is ERROR (17). Can you help me for this problems ? Pin 34 is high; other AT commands works fine.

    Reply
  66. Hi Martyn,

    I’m trying to create a wireless setup for measuring ECG from the human body using a Sparkfun AD8232, Nano, and HC-05. My HC-05 doesn’t have ZS-040 written on it, but it has the button and EN pin. So far, I have been able to successfully observe ECG by replacing Serial.begin(9600) with Serial.begin(57600) in the tutorial Arduino code at this link: https://learn.sparkfun.com/tutorials/ad8232-heart-rate-monitor-hookup-guide/all

    So it seems that the arduino baud rate is 57600. The console confirms this when I upload the script from that tutorial:
    Using Port : COM7
    Using Programmer : arduino
    Overriding Baud Rate : 57600
    AVR Part : ATmega328P
    Chip Erase delay : 9000 us

    So I’ve been trying to make sure that the HC-05 operates at this baud rate because the arduino nano/AD8232 combination works with this baud rate when connected to the serial port. I’ve tried using your code as is and following these steps (not using a voltage divider at the moment):

    1. Setup all the connections (apart from voltage divider)
    2. Keep the Rx, Tx pins on the HC-05 disconnected and plug in USB to computer.
    3. Upload the code. Then connect the Rx, Tx pins back to the HC-05.
    4. Disconnect the Vcc on the HC-05, hold the button, connect the Vcc on HC-05, then release button.
    5. Open serial monitor, which is set at 9600 baud rate, both NL&CR chosen, and type ‘AT’ and press enter.

    The serial monitor gives no output in response to the ‘AT’ command:
    Sketch: C:\Users\fahee\Desktop\BTTry4\BTTry4.ino
    23:41:36.589 -> Uploaded: Mar 10 2019
    23:41:36.623 ->
    23:41:36.623 -> BTserial started at 38400
    23:41:36.623 ->
    23:41:40.701 -> >AT

    I have tried holding the button and sending the command, but no difference. I’ve also tried changing the Serial.begin(9600) in your code with Serial.begin(57600) and changing the serial monitor baud rate to 57600, but still doesn’t work. I just want to make sure the baud rate is set correctly on the HC-05. Could you please offer a suggestion?

    Reply
    • Read through a few more comments, starting to think maybe I need the voltage divider. A confirmation would still be helpful though.

      Reply
  67. Hi,

    Ive posted my issue here where Ive uploaded links and sketch. I was wondering if you could take a look. Im unable to get my hc05 to respond to commands, according to the 2 sec blink after powering it up with the button pressed, it should have entered command mode, yet it doesnt respond to any in the SM.

    Reply
  68. Hi! Very accurate post, congrats ;) I’ve got an HC05 with no button and firmware “Firmware V4.2.0,Bluetooth V4.0 LE”. I have no problem accessing the AT Command Mode, and in fact, when I power the module this is the mode in which it gets into. After changing some features (name, pswd, …) I wanna quit the AT command mode so I can link module to phone (which I can’t while being in AT Command Mode, I have read). But I can’t! Is it possible that my pin34 is set HIGH as default or something, and I have to set it LOW (connect to 0V) to quit this mode?

    Reply
    • “Firmware V4.2.0,Bluetooth V4.0 LE is not a HC-05 and this firmware is normally found on devices like the BT05 and AT09.

      try AT+HELP, this should give you a full list of commands.

      Reply
  69. Hey, my module HC-05 works only on highers pins:

    // SoftwareSerial BTSerial( 10, 11 ); // RX | TX +
    // SoftwareSerial BTSerial( 9, 10 ); // RX | TX +
    SoftwareSerial BTSerial( 8, 9 ); // RX | TX +
    // SoftwareSerial BTSerial( 7, 8 ); // RX | TX – ???
    // SoftwareSerial BTSerial( 6, 7 ); // RX | TX – ???
    // SoftwareSerial BTSerial( 5, 6 ); // RX | TX – ???
    // SoftwareSerial BTSerial( 4, 5 ); // RX | TX – ???
    // SoftwareSerial BTSerial( 3, 4 ); // RX | TX – ???

    I can not move it to 3,4 or 4,5, but it works fine on 8,9, or 9,10.
    BOARD_TAG = leonardo

    Me needs highers pins for MotorV2.2 module, so I can not use its both, please help!

    Could you enlighten me?

    Reply
  70. Someone deleted my yesterday message!

    Hey, my module HC-05 works only on highers pins:

    // SoftwareSerial BTSerial( 10, 11 ); // RX | TX +
    // SoftwareSerial BTSerial( 9, 10 ); // RX | TX +
    // SoftwareSerial BTSerial( 8, 9 ); // RX | TX +
    // SoftwareSerial BTSerial( 7, 8 ); // RX | TX – ???
    // SoftwareSerial BTSerial( 6, 7 ); // RX | TX – ???
    // SoftwareSerial BTSerial( 5, 6 ); // RX | TX – ???
    // SoftwareSerial BTSerial( 4, 5 ); // RX | TX – ???
    // SoftwareSerial BTSerial( 3, 4 ); // RX | TX – ???

    I can not move it to 3,4 or 4,5, but it works fine on 8,9, or 9,10.
    BOARD_TAG = leonardo

    Me needs highers pins for MotorV2.2 module, so I can not use its both, please help!

    Could you enlighten me?

    Reply
  71. hello.I researched to every page but I couldnt find any answer.when I provide the correct connections, the led turns off completely after flashing for 5 seconds. When I make the EN pin HIGH, I see meaningless values ​​in the AT commands. Please help, I have been searching for days.

    Reply
    • i also run into this problem,
      everything is working well only for the first 5 seconds, i could do AT commands, but it the BT led is turned off afterward and is not ressponding anything.

      Reply
  72. Hello,

    i have 6 ZS040 Modules in here. I mounted a Arduino as you describe and where able to communicate with one module as expected.
    I i now switch to one of the other modules they blink like the working one with 1hz, but they do not replay to any command.

    So what can i do?

    Reply
  73. I probably made a mistake by asking a question via the “Contact me” facility rather than here.
    I don’t seem to be able to get Putty to work with the HC-05 while in command mode. When I send the “AT\r\n” sequence, the HC-05 responds with “OK”, CONTINOUSLY! Not just once as it is supposed to and in fact, does when I use Tera Term to send the “AT\r\n” sequence!
    Do you use Putty or do you have any idea what might be happening?

    Reply
    • I use putty very occasionally. I normally just use the Arduino serial monitor simply because it is easy to set up and I have it available on all my different computers.

      Confirm what firmware the module has and, if you haven’t already, find the data sheet.

      Reply
  74. Currently, I am working on a project where I am trying to send data at a baud rate of 230400 or 250000. This works when the Arduino is wired to the computer. The data is received through a MATLAB code and the data is read by an Arduino program.
    However, when I use an HC-05 Bluetooth module I can only send data when using a baud rate of 115200 across all programs. But when I program the module to 230400, as well as the MATLAB and Arduino, I do not receive the correct data. I programmed the Arduino to send flaggers after every 3 bytes of data, but I do not see any flaggers in MATLAB when the baud rate is 230400. I am receiving data, but I am not sure what it is since I do not see the flaggers. I am unsure where the issue is if it is the computer, the Bluetooth module, MATLAB, or Arduino. Please let me know how I can receive the correct data, or where the problem most likely is.

    Reply
    • I suspect the baud rate is too much for the BT module but don’t know for sure.

      You could test this by connecting the Arduino directly to a computer using hardware serial. If this works at the required baud rates then it is the BT module. Be aware that 230400 is at the upper limit of what a normal arduino can achieve so it is possible the problem is across both modules.

      Reply
      • I have tried it using the hardware serial and it works fine. So I assume it’s the BT module then. Do you know of a BT module that would be able to work at a baud rate of 230400?

        Reply
  75. I have a ZS-040 board, and when I enter command mode (hold down button and power up), the LED flashes TWICE at the “command mode frequency”, then goes off, and it won’t respond to any commands. If I quickly type AT within those initial seconds, I get an OK, but nothing afterwards.
    So, I wrote an app to fire the 4 commands I wanted to implement, powered the board up with the button held down, immediately sent the commands via the app, then powered off the module. I repeated this but reading the results of the commands sent, and it works OK.
    So my question would be, why on Earth does command mode only last a few seconds, and then…. nothing, no LED, no BT availability?
    Very odd.
    Seems to power up normally and perform as expected otherwise.
    Firmware version is : 3.0-20170601

    Reply
  76. I am trying to run a project at a baud rate of 230400 or 250000. I’ve tried it with this Bluetooth module and it didn’t work (the hardware serial worked though). Are you aware of any Bluetooth modules that could work at a baud rate of 230400?

    Reply
  77. Hi Martyn, let’s see if you’re still here😌
    I can update the all “AT COMMAND” to HC-05 in arduino serial monitor. Every command is saved but except the AT+PSWD.
    AT+PSWD=0000 command seems works and gives OK. But when I restart the arduino, password is changing to default password (1234) . Other result is ok (name, cmode, bind, class, role, uart e.g)
    P.s. I would like to connect Mindwave brain sensor and needs to be pass is 0000
    P.s. HC-05 version is = VERSION:4.0-20190815

    Reply
  78. Thank you for the article. The most critical information for me is that to enter AT mode, one needs to keep the button pressed while powering the module. I broke my brain trying using the EN pin, which seems to be not connected to anything.

    Reply
  79. Have you any experience with the modules currently (late 2023) sold as “new version” on Aliexpress ? I received an HC-05 “new version” a few days ago and have been unable to put it into master mode, whatever advice I’ve taken from your website or others. Holding down the button or pulling pin 34 high makes the LED blink more slowly as expected and I can communicate at 38400 bps, but while AT+ROLE=1 always produces an OK response, AT+ROLE? still reports back zero. AT+INIT never produces an OK response, but there is sometimes a few characters of what look like line noise (perhaps a response sent at a different rate).

    The “new version” appears to have a different chip. It’s labelled BC41C (not BC417) and it’s in a smaller 32 pin PLCC package instead of the BGA type package as in your photos above. Otherwise the module looks very much like that in your first photo on the zs040 board.

    Reply
    • A short while ago I bought a new batch of random HC-06 and HC-05 modules but haven’t had time to try them.
      All I can suggest is lots of online searching and try contacting the seller for datasheets or manufacturer information. Try also searching Chinese websites for BC41C

      Reply
      • Thanks for getting back to me. I think my previous response went into moderation and was lost because I tried to add a photo inline. A photo of my module can be found at this link: https://www.hembrow.eu/tmp/L1040122.JPG

        As you’ll see, it looks a lot like any other HC05 but it uses a smaller PLCC package BL41C. I forgot to mention before that the software version is reported as 20100601. I’ve tried pulling pin 34 high both before boot which results in it staying in AT mode and after. I also tried pulling pin 27 high (that’s elsewhere on your website) which has no effect that I can tell on this module. I also tried changing the value of pin 27 with AT+PIO=4,1 but that returned an ERROR.

        I ordered my module from here: https://www.aliexpress.com/item/1005002082974256.html

        Their photos are accurate – mine looks like their “new version” so I can’t complain that I’ve been sent the wrong part, just that it doesn’t seem to work as a master. Perhaps I would just have been better off asking for the old version.

        Another oddity is that it doesn’t seem to like any AT commands sent to it at human typing speed. Your terminal program doesn’t work for typing anything longer than just “AT”. But if I use BTserial.print(“AT+VERSION?\r\n”), for instance, then that does generate a response. So all the successful responses that I’ve had have been to code sending strings quickly, not to typed commands.

        Reply
  80. Is there any progress with this new board BC41C? I’m trying to put this module to ROLE=1 without success. All other commands are accepted. So frustrating… No information on internet!

    Reply
    • I need help with this too. Please let me know if there are any updates. I have the same modules and mine just don’t respond to AT commands till I set pin 34 to high while the module being on power. Still it doesn’t save any setting as mentioned by David Hembrow.

      Reply

Leave a Comment