Sunteți pe pagina 1din 16

Bluetooth HC05- How to pair two modules | alselectro https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pa...

All about Microcontrollers,Tips on Pc,Android phone,Electronics

Filed under: BlueTooth/WIFI — 36 Comments
October 21, 2014
It is quite simple to pair a Bluetooth module from your Android phone.But bit tricky to pair it with
another HC‐05 module.In this post I’ll describe the method of pairing 2 BT modules.One of the module
is assigned ROLE as MASTER  & the other left as SLAVE.

By default all HC05 modules are SLAVEs.Using AT commands the module can be configured as we
like.

To configure the SLAVE we make use of an Arduino UNO board.Not much of configuration needed
for slave.We can leave it to defaults.But to know the ADDRESS of the slave you’ve to follow this
procedure.

Before connecting the HC05 module , upload an empty sketch to Arduino. This bypasses the Boot
loader of UNO & the Arduino is used as USB‐UART converter.

void setup() {}

void loop() {}

After uploading this empty sketch,remove USB power from Arduino & do the following connections
with HC05 Slave :

——————————————‐

1 of 16 1/22/2018 1:22 AM
Bluetooth HC05- How to pair two modules | alselectro https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pa...

ARDUINO        HC05

Rx(pin0 )  —>     Rx                Remember it is one to one connection here & not cross connection

Tx (pin1) —‐>    Tx

+5v     ——‐> VCC

GND     ——‐> GND

+3.3V  ——–> KEY

————————————————‐

Now provide the USB cable power to Arduino.The HC05 module enters the Command mode with
Baud Rate 38400.

Open the Serial Monitor of Arduino .

Ensure to select “BOTH NL & CR”  & Baud Rate as 38400 at the bottom of the serial monitor.This is
very important as the Bluetooth module HC05 expects both Carriage Return and Line Feed after every
AT command.

If you type in AT & click on SEND button you should get an OK confirmation from the HC05 module.

If you get ERROR(0) try again to enter the Command mode.If there is no response then check whether
correct COM port has been assigned in Arduino IDE & confirm Baud Rate is 38400 , “Both NL & CR”
selected.

Type in AT+NAME?    to get the name of the module.You can change the name as you like with

AT+NAME=HC05_SLAVE

The password by default is  1234 .Confirm that with AT+PSWD?

2 of 16 1/22/2018 1:22 AM
Bluetooth HC05- How to pair two modules | alselectro https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pa...

The ROLE of the module can be known by typing  AT+ROLE?

You can change it by AT+ROLE=0    0 for SLAVE & 1 for Master. Leave it as 0 as we want this module
to be SLAVE.

You should know the Address of this module to make it PAIR with another.Type in

AT+ADDR?  

& note the Address.Here it is  14:2:110007.

While using this address in AT commands you should replace the colon with a comma , like

14,2,110007

Now remove the KEY connection from the HC05 module & disconnect the power.

Again provide the power to see STATUS LED on the module blinking fast indicating that it is looking
for a PAIR.

MASTER Module setup

To configure another module as MASTER a simple USB to TTL converter is used.

             

Following are the connections between HC05 & USB‐TTL module.

————————————————

  HC‐05          USB‐TTL

   VCC    —–>   +5V

    GND   —–>   GND

    Tx      ——>   Rx        Note the CROSS connection here

    Rx      ——>  Tx

    KEY     ——> +3.3V      

————————————————‐

We make use of a Terminal Software TERATERM to configure the MASTER.The advantages of this

3 of 16 1/22/2018 1:22 AM
Bluetooth HC05- How to pair two modules | alselectro https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pa...

Terminal software are

– It supports CR+LF Carriage Return and Line FEED after each command , which is a must for HC05

– Sends command with zero Transmit delay , as the HC05 module interprets commands immediately.

You can download TERATERM  here

Open the TERATERM terminal & select SERIAL & the port number where the USB‐TTL module is
connected.

Under SETUP –> Terminal select CR+LF for TRANSMIT

Also check mark “Local Echo “ so that you see what you type.

4 of 16 1/22/2018 1:22 AM
Bluetooth HC05- How to pair two modules | alselectro https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pa...

Under SETUP –> SERIAL PORT select the Baud Rate as 38400 , 8N1

If you type in AT you should get an OK response.

Reset the module by issuing AT+ORGL  which restores the module to original state.

You can change the name to user friendly one by typing AT+NAME=usergivenname

AT+RMAAD  will release the module from any previous PAIR.

AT+PSWD=1234  to set the password as 1234

AT+ROLE=1  changes the ROLE of the module to MASTER

5 of 16 1/22/2018 1:22 AM
Bluetooth HC05- How to pair two modules | alselectro https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pa...

AT+CMODE=1

Allows connecting to any address.

Default is CMODE = 0 which allows connection to only bound address.

Start SPP profile library (needed to do any Bluetooth transmitting/receiving):

Serial Port Profile (SPP)

While Bluetooth specifications define how the technology works, profiles define how it’s used.

If you’re replacing a serial communication with Bluetooth, SPP is the profile for you. SPP is great for
sending bursts of data between two devices. It’s is one of the more fundamental Bluetooth profiles.

Using SPP, each connected device can send and receive data just as if there were RX and TX lines
connected between them.

Initialize the SPP Profile library by typing

AT+INIT  

If you get ERROR(17) , it means you’ve already issued this command & you can
continue ignoring the error.

Start searching:inquire surrounding bluetooth devices

AT+INQ

A short list of devices found should appear, one of them will be the slave module.

The format of the output is as follows:
+INQ:address,type,signal   e.g.  14:2:110007,0,7FFF

Type can be ignored. The signal will be 7FFF since inquire is in standard mode.

Copy the address part of the devices found, for example 14:2:110007 and change the colons to

6 of 16 1/22/2018 1:22 AM
Bluetooth HC05- How to pair two modules | alselectro https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pa...

commas – 14,2,110007.

To find out which device is the slave module you will need to query each address for its name:
AT+RNAME? <address>

Replace <address> with address of device like 14,2,110007

Response should be +RNAME:HC05_SLAVE if you’re using a master module as a slave.

And now to actually connect to the SLAVE

AT+LINK=<address>

AT+LINK=14,2,110007

You can watch the status LEDs of both slave & master.The fast blinking Status LED  starts flickering
slowly & the Pairing LED goes steady.

Now you can remove the KEY connection from master & Reset the module by removing the power &
connecting back.

On powering back the MASTER ,the Slave gets paired with it automatically which can be verified by
the LEDs on board.The paired devices are remembered even after disconnecting power.

Now these two modules can replace the physical serial connection of your project.

Bluetooth networks (commonly referred to as piconets) use a master/slave model to control when and
where devices can send data. In this model, a single master device can be connected to up to seven
different slave devices. Any slave device in the piconet can only be connected to a single master.

The master coordinates communication throughout the piconet. It can send data to any of its slaves
and request data from them as well. Slaves are only allowed to transmit to and receive from their
master. They can’t talk to other slaves in the piconet.Maximum 7 devices are allowed in this piconet
network.

Watch this support video :

7 of 16 1/22/2018 1:22 AM
Bluetooth HC05- How to pair two modules | alselectro https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pa...

Pairing HC‐05 BLUETOOTH Modules
 

     

8 of 16 1/22/2018 1:22 AM
Bluetooth HC05- How to pair two modules | alselectro https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pa...

Report this ad

Report this ad
Tags: BLUETOOTH MODULES AS ZIGBEE, HOW TO PAIR TWO BLUETOOTH MODULES,
PAIRING HC05 MDULES
Comments RSS (Really Simple Syndication) feed

Venkat
October 29, 2014 at 10:59 pm
Thank you sir. Its very useful for my project.

Reply
remy
November 29, 2014 at 12:47 am
very good job thanks

Reply
remy
December 3, 2014 at 9:22 pm
hi have try a master with several slaves??

thanks

Reply

9 of 16 1/22/2018 1:22 AM
Bluetooth HC05- How to pair two modules | alselectro https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pa...

alselectro
December 4, 2014 at 2:41 pm
At a time a Master can pair with One Slave only

Reply
VIANY GUPTA
December 15, 2014 at 1:37 pm
Sir can we configure bluetooth module using 8051 kit through RS232. I mean just by
removing microcontroller and connect bluetooth TX & RX pin in place of P3.1 & P3.2.

Vinit Kumar
December 9, 2014 at 11:37 am
Hello Sir !! I am trying to pair a HC‐05 with HC‐06 Bluetooth module . HC‐05 is the master and
HC‐06 is the slave . I am using Arduino UNO to connect HC‐05 and Arduino Mega ADK to
connect HC‐06 . The 2 Bluetooth modules is getting paired but the data that is being sent from
HC‐05 the master module , is not being received exactly by the slave module . Like if i am sending 1
, the slave is receiving 255 255 or 254 255 . Any other data except 1 , the slave is receiving similar
values 255 254 or 248 255 . Whatever data is being received by the slave module , i am printing it on
the serial monitor . I have tried both normal mode and the SoftwareSerial mode. The Modules are
getting paired at all times as you have mentioned even after removing the power plug and
reinserting it . But the valid data is not being received .

What could be the possible problem ?

Reply
alselectro
December 15, 2014 at 3:25 pm
check out the baud rate of both the Arduino serial monitors.Note that while configuring BT the
connection between Arduino & BT is one to one i.e Rx‐Rx Tx‐Tx .Once the configuration is over
remove the 3.3v connection at wakeup point & connect Tx‐Rx & Rx to Tx

Reply
Venkat
December 15, 2014 at 1:53 pm
Is networking possible in Bluetooth..? Awaitig your reply..?

Reply
alselectro
December 15, 2014 at 3:20 pm
Networking with BT is called PICONET where they say one Master can communicate with max
7 slaves.But practically when I tested , at a time only one slave can pair with the master.When
power is removed for the 1st slave ,automatically 2nd slave gets connected to master.

Reply
Vinay gupta
December 15, 2014 at 2:03 pm
Sir, can we configure bluetooth device using 8051 kit through RS232.? I mean by removing
microcontroller and connect TX and RX pin of bluetooth in place of P3.0 and P3.1.

Reply
alselectro
December 15, 2014 at 2:30 pm
Not possible.In case of Arduino we make use of the USB‐UART IC (seen near to the USB

10 of 16 1/22/2018 1:22 AM
Bluetooth HC05- How to pair two modules | alselectro https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pa...

socket) & bypass the bootloader by uploading empty sketch.In case of 8051 it is not possible.Buy
a USB‐TTL board which is less than Rs.200 to configure BT.

Reply
Chenty
January 8, 2015 at 5:50 pm
Hello Sir, I didn’t find in the web clearly if an HC‐05 Master Bluetooth can pair and communicate
with HC‐06 Slaves, supposing they are configured correctly as you mentioned above. I mean, an
HC‐05 Master can only pair and communicate with HC‐05 Slaves due to they have the same
firmware and the HC‐06 Slaves have Linvor firmware?

Reply
alselectro
January 8, 2015 at 8:10 pm
HC05 can be paired with HC06 module.Pairing must be initiated from HC05. As HC06 is a
SLAVE ONLY module ,it cannot initiate a pair by itself.
HC06 enters AT mode automatically when not paired to any other device.There is no LED
indication for AT mode, as you see in HC05.Just power up HC06 & enter the AT
commands.HC06 doesn’t wait for carriage return.You’ve to enter AT commands in notepad &
copy paste on to Teraterm terminal.
To know the address of slave you can issue AT+NIT & then AT+INQ to know the surrounding
device’s address.
Now you can pair with that address using AT+LINK.
The firmware is nothing to do with wireless protocol.It is for internal operation to bluetooth.For
wireless you initiate
Bluetooth SPP protocol by AT+INIT .

Reply
Chenty
January 8, 2015 at 9:22 pm
Thanks for your soon reply, I also want to know if it is possible an HC‐05 Master in one
arduino UNO can pair and communicate with two HC‐06 (or HC‐05) Slaves, each one in its
Arduino UNO, and in other moment the HC‐05 Master be configured as a Slave Bluetooth
to be pair and communicate with an Android’s Master Bluetooth, and then the HC‐05 Slave
Bluetooth be again a HC‐05 Master Bluetooth to communicate again with the other HC‐06
Slaves?

alselectro
January 8, 2015 at 10:48 pm
A master can be paired to max of 7 slaves.But practically when I tested , at a time only one
slave communicated with master.When power to first slave was switched off,
automatically the second slave got paired with master.
From Android phone HC05 can be easily paired.But further relaying to slaves is not possible.

Chenty
January 24, 2015 at 9:54 pm
Hello again, can you tell me how can I read and parse into the arduino IDE the data list returned of
slaves discovered when the Master send the AT+INQ command. I want to know where and how
are store the data returned of the slaves encountered.

Reply
Alex
February 9, 2015 at 6:20 am

11 of 16 1/22/2018 1:22 AM
Bluetooth HC05- How to pair two modules | alselectro https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pa...

Hello Saravanan, Greetings from Toronto/Canada!

Great video, I’m wondering if you can help me with something. I have an HC‐05 and an HC‐06.
Instead of trying to connect both together, I’m trying to connect the HC‐05 to my Bluetooth
PlayStation 3 controller. I think the PS3 Controller is a slave only, that’s why I need to use the
HC‐05 in master mode with the Arduino.

The arduino has a Library called “USB_Host_Shield_Library”. Using this library + Arduino Uno +
USB Shield for Arduino + A USB Bluetooth Dongle, I can connect my PS3 controller with the
arduino and read all the input from the PS3 controller.

My goal is to do the exact same as above but without the USB Bluetooth Dongle or the USB Shield
for the Arduino.

So I’m trying to connect my PS3 Controller Directly to the Arduino Using the HC‐05 Module. But I
also would like to be able to use the Library “USB_Host_Shield_Library” with that type of
connection since it comes with a sketch called “PS3BT” that is already configured to read all inputs
of a PS3 Controller so we can use the Arduino to control things with the PS3 controller. But this
sketch only works when connecting a USB Dongle to a USB Shield NOT when using a HC‐05, so
what changes in the code of “PS3BT” sketch that needs to be made to let it read the PS3 controller
input from HC‐05 instead of USB Dongle?

If you can point me in the right direction about this or make a guide/tutorial I would really
appreciate it.

Thanks,
Alex.

Reply
alselectro
February 10, 2015 at 7:37 am
Hi Alex,
Glad you liked my video.
It’s hard to implement things without the USB Host shield.The library developed by
circuitsathome takes care of handling data from your PS3.USB Host is based on SPI
interface.HC05 is a simple serial device.
If you try to avoid this shield , you need to use some microSD shield for storing received
data.This is again SPI . Better to stick on to the existing USB host & library.Visit this
link http://www.circuitsathome.com/usb‐host‐shield‐hardware‐manual to know the hard work
& time taken to develop this hardware & library.

Reply
indri
February 22, 2015 at 8:46 pm
hi, may i know how i can request data from slaves? hc‐05 to hc‐06

Reply
alselectro
February 23, 2015 at 6:03 am
HC06 is a SLAVE only module & by itself can’t initiate a Pair.As shown in video use a Master
HC05 & pair it with HC06 Slave.
Once it is paired, both modules act as Transceiver.Once pairing is done , even a Slave can
automatically connect with Master when
it it powered up.

12 of 16 1/22/2018 1:22 AM
Bluetooth HC05- How to pair two modules | alselectro https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pa...

Reply
David Paul Dawkins
March 2, 2015 at 6:40 am
Hi, thank you for your handy tips. I can pair my devices and send and receive data. I am using one
HC‐05 and one HC‐06. My HC‐05 seems to have 2 command types. For example I power the device
and tie the key and the device flash every 2 second baud = 38400, the other is when i power up
then just pulse the key once, now i am communicating at a baud of 9600 and can send commands,
flashing twice a second ish, i’ll call this command type 2.

So when I enter the command type 1, reset the device, set to master and…… until i reach the
AT+INIT command, this command puts my device into command type 2, i quickly change the baud
to match and then try obtain and entering the MAC of the Slave into the Master to store it for
future pairing.

This is where my problems start. I only have 2 seconds to get all the commands in before the pairing
automatically commences. I like the fact that the device automatically pairs but this leaves me with
no option is store the MAC address of the slave so the device only pairs with this slave and no
others.

Can you help me store the MAC address?

Is it possible to send command while paired with a device?

Do you know why there are two command modes at different baud rates?
my version is: +VERSION:2.0‐20100601
Another issue is:
AT+NAME, AT+INQ does not respond with any data! like a few other commands! AT+INQM
works…

Finally can you link me to an English datasheet?

The kindest regards to you.

Thank you for time

Dave

Reply
alselectro
March 2, 2015 at 10:53 pm
Before initializing the bluetooth SPP protocol with AT+INIT , you need to set the CMODE to 1 ,
AT+CMODE=1 , which enables pairing with any address.By default this is 0 which allows
to pair with the address that is paired using AT+BIND . After CMODE is enabled , use
AT+INIT. Now inquire for surrounding modules using AT+INQ .It is normal that the LED starts
blinking fast indicating that it is looking for a pair.I think you’ve misunderstood this state as the
module has come out of AT mode.
The module is still in AT mode but searching for surrounding modules.If the slave is powered up
, its MAC address will be displayed under AT+INQ. Now you can pair the slave using AT+LINK
command.If the INQ is not returning any result you can directly LINK to the slave address ,
provided the address is known.
There is no way to store the MAC address. You can AT+LINK to max. of 7 slaves . But
practically , only one slave will be paired to Master at one instant. If the power to slave is OFF
then the second slave will automatically pair with the Master..
The default Baud rate is 9600 . Entering AT mode at 38400 makes INQ faster and linking is made

13 of 16 1/22/2018 1:22 AM
Bluetooth HC05- How to pair two modules | alselectro https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pa...

soon.
Here is the link to the datasheet : ftp://imall.iteadstudio.com/BLOG/2010_07
/More_Powerful_Serial_Port_Bluetooth_Module_MasterSlave.pdf

Reply
Annisa Nadia
March 14, 2015 at 11:38 am
Hi sir, i’ve watched your tutorial and i wanna try it, but i dont have USB TTL. im trying to use the
master with arduino, not USB TTL. so i dont use tera term but i use both arduino. they cant
connect each other. should i use USB TTL and tera term for connecting slave ? please help sir.
thank you 

Reply
alselectro
March 15, 2015 at 9:14 pm
You can very well use the Terminal of Arduino instead of TeraTerm. But remember , while
configuring the Bluetooth module the connection is Tx(bluetooth) to Tx (Arduino) & Rx to Rx.
Once you’ve configured & paired the Master & slave , the connection should be reversed.i.e. Tx
to Rx & Rx to Tx

Reply
dinesh kumar
July 22, 2015 at 5:04 pm
How to broadcast a data from master to multiple slave bluetooth module

Reply
alselectro
July 22, 2015 at 6:04 pm
Bluetooth is for one to one communication. Pairing is possible between 2 devices , but broadcast
is not possible.

Reply
dinesh kumar
August 3, 2015 at 6:32 am
Hello sir,
thanks for reply .
1)May i know whether name of the Bluetooth module can be changed while executing in
Arduino itself by some function call.
2)Can slave modules name can be read by the master module without pairing.

dinesh kumar
August 5, 2015 at 4:03 am
Hello sir,
thanks for reply .
1)May i know whether name of the Bluetooth module can be changed while executing in Arduino
itself by some function call.
2)Can slave modules name can be read by the master module without pairing.

Reply
dinesh kumar
August 15, 2015 at 9:35 pm
Hello sir,
1)May i know whether name of the Bluetooth module can be changed while executing in Arduino

14 of 16 1/22/2018 1:22 AM
Bluetooth HC05- How to pair two modules | alselectro https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pa...

itself by some function call.
2)Can slave modules name can be read by the master module without pairing.

Reply
aloysetech
February 18, 2016 at 4:15 am
Great, you helped me a lot on a massive project   Thank you very much man!

Reply
Neal Radford
March 8, 2016 at 7:02 am
Hi, Thanks heaps for this! With you instruction i finally got my hc‐05 to print to a bluetooth
printer…. after a few days of head scratching i’m afraid to say! 
Thanks again & cheers,
Neal

Reply
Hanif
April 13, 2016 at 9:58 pm
Hello Sir, thanks for the great explanation. I would like to ask, can I use arduino instead USB TTL in
this tutorial? Is it same way to do it as you show in this tutorial?
Thanks again Sir.

Reply
alselectro
April 14, 2016 at 12:02 pm
You can very well use the Arduino as USB‐TTL , either by uploading empty code or by
connecting RST to GND.Now the bootloader of Arduino will be bypassed.But remember to
connect Rx‐Rx & Tx‐Tx in this configure mode.Later in normal operation you’ve to connect the
regular way Rx‐Tx.

Reply
Kulbir SIngh Ahluwalia
July 6, 2016 at 9:31 pm
Hello sir !
Great job !

Here are somethings I think will be helpful :‐

1.Hold the button on the Bluetooth module while giving AT commands.

2. As soon as you connect the slave to it’s power supply, it will blink very fast. That is the time to
give the AT+INQ command in teraterm to the master. (In case AT+INQ does not give any reply.)

3.EN pin on some HC05 modules is the KEY pin.

4.Some modules have 9600 as their Baud rate. So both 38400 and 9600 should be tried.

(PS‐Have lots and lots and lots of patience. Pairing is not as easy as it seems. Lol)

Kulbir, PEC Chandigarh

Reply
RJ

15 of 16 1/22/2018 1:22 AM
Bluetooth HC05- How to pair two modules | alselectro https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pa...

August 4, 2016 at 12:58 pm
Hi. I have a HC‐05 module which i am trying to use with my arduino uno. My BT module has level
3.3v printed beside RX TX pins. Do I need a level shifter for converting 5v to 3.3v for rx tx pins?

Reply
alselectro
August 4, 2016 at 3:03 pm
Its always advisable to use a level shifter.You can also use a 1k series resistor to Rx of BT & a 2k2
to GND.Tx of BT can be directly connected to Rx of Arduino.

Reply

16 of 16 1/22/2018 1:22 AM

S-ar putea să vă placă și