Configure Arduino + Bluetooth HC-05 Slave

How to connect Arduino to Bluetooth HC-05 module:


HC-05 is not visible for Android by default - because of "secure device class" of "1f00"
AT+CLASS? 1f00

We will set the Class to "1":
AT+CLASS=1

and the Role to "Slave"
AT+ROLE?
AT+ROLE=0


1.1. Connect Arduino to Bluetooth HC-05 according to the layout:


1.2. Do not supply the power yet

1.3. Connect the HC-05 "key" pin (1st pin from the left) to Arduino "GND" pin


1.4. Power On HC-05 (connect Arduino to USB)

1.5. Reconnect he HC-05 "key" pin (1st pin from the left - not the "GND" pin from the right!) to Arduino "VCC" pin

1.6. Load the Arduino test sketch:

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(5, 4); // RX | TX

void setup()
{
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  BTSerial.begin(9600);  // HC-05 default speed in AT command more
}

void loop()
{

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

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


1.7. Open Arduino Serial Monitor (Tools > Serial Monitor) and run the AT commands:
AT+CLASS?
AT+CLASS=1
AT+ROLE?
AT+ROLE=0

Now restart HC-05 (reconnect Arduino USB) and try to find and pair HC-05 from your Android (Settings > Bluetooth > Discover new devices)
Default HC-05 pin is 1234

Let me know if you have any questions.

References:
http://www.instructables.com/id/Modify-The-HC-05-Bluetooth-Module-Defaults-Using-A/?ALLSTEPS
http://byron76.blogspot.com/2011/09/hc05-firmware.html

9 comments:

  1. android does not detect my bluetooth module !!

    ReplyDelete
    Replies
    1. By default HC-05 has "secure device class" of "1f00" - which is not visible for Android - please change it to "1":
      AT+CLASS=1

      Delete
  2. can anyone please tell me how can i change data rate in Hc-05?

    and how to change the class of device? what will happen if i change the class? whether it would affect the data rate or something?

    ReplyDelete
  3. to change the data rate in HC-05:
    1) unplug the power
    2) connect the "Key" pin to GND
    3) power on
    4) reconnect the "Key" pin to PWR
    5) connect USB-UART to HC-05 (baud 9600/1/none)
    AT+UART=4800,1,0

    To change the class:
    AT+CLASS=1

    the class does not affect the data rate - it just make HC-05 visible for Android

    ReplyDelete
    Replies
    1. thank you andrew..
      you have told about the baud rate(data rate) of UART. i am asking for the Bluetooth RF Transmission Data rate to change. generally the Hc-05 has the 3Mbps data rate(Bluetooth 2.0+EDR)
      can you please acknowledge the same?

      Delete
  4. thank you andrew..
    you have told about the data rate in UART. but i am asking the Bluetooth RF transmission data rate to change. generally HC-05 has 3Mbbs Data rate because it has Blueetooth 2.0+EDR. Can you please acknowledge me to change the data rate.

    ReplyDelete
  5. Hello,
    Can you please let me know how to connect the HC_05 to android using AT+LINK? After pairing, every time on giving AT+LINK AT comment its returning "FAIL". How the connection from the side of HC-05 be established to send the data on serial port to my android?

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
  7. Enter AT commands:
    AV0 MújüAV˜ MêŠjøAVž1 jþ

    when I try to write AT command following thing displays.
    Can anyone help me out with this issue.

    ReplyDelete