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 :
——————————————-
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?
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 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.
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
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 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 :
NEW UPDATED VIDEO with code examples :
Thank you sir. Its very useful for my project.
very good job thanks
hi have try a master with several slaves??
thanks
At a time a Master can pair with One Slave only
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.
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 ?
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
Is networking possible in Bluetooth..? Awaitig your reply..?
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.
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.
Not possible.In case of Arduino we make use of the USB-UART IC (seen near to the USB 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.
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?
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 .
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?
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.
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.
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.
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.
hi, may i know how i can request data from slaves? hc-05 to hc-06
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.
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
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 soon.
Here is the link to the datasheet : ftp://imall.iteadstudio.com/BLOG/2010_07/More_Powerful_Serial_Port_Bluetooth_Module_MasterSlave.pdf
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 🙂
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
sir, why during configuration we connect Tx to Tx and Rx to Rx and after that it is cross connection ?
Please can you clarify, i had this doubt for a long time
While configuring BT modules we us this straight connection, provided you upload an empty code ( bare minimum from examples) or just connect RST with GND. This will bypass the Arduino bootloader & only the serial IC is used by the end device which is BT in our case. During normal data transfer the connection must be reverse Rx to Tx & vice versa.
How to broadcast a data from master to multiple slave bluetooth module
Bluetooth is for one to one communication. Pairing is possible between 2 devices , but broadcast is not possible.
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.
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.
Hello sir,
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.
Great, you helped me a lot on a massive project 😀 Thank you very much man!
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
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.
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.
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
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?
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.
Hi. I have a 2 HC-05 module which i am trying to Configure as master and slave but problem is that they have address like this 21:13:1B88 and 21:13:1777. master not accept this address it give me error how i connect this two module ?
Use AT+LINK command with mac address & colons replaced with comma. Or use the AT+BIND command , as some modules accept BIND only
Hey there,
I’ve got two HC-05 modules connected as master and slave. The codes for each have switch/case statements where a signal sent by one module, will switch the mode of the other. For some reason when i disable power and turn it back on, the bluetooth link drops. Any thoughts as to why?
-thanks
Hello sir!
Thanks to your very, very helpful instructions I could pair two HC-05 modules. Everything works as described in your instruction except that I get no data transferred. That means when I control the signal with the storage oscilloscope I have data on the master side and the data received at the slave are just “some” bits. I suppose that are just some start- or stop-bits. I used SPP and “AT+INIT” brought back “OK”.
May there any other fault that I have done?
Thank you and best regards!
Pairing HC05 modules with a key switch is bit different.Watch out my video on pairing with new modules for communication with examples
Does it work if we use both 9600 baud rate?
Sir it is possible to connect HC05 module with EEG headset. kindly guide me it will be very helpful for me.Thanks
Sir, is that possible to follow this procedure(HC-05 Pairing) for communication Arduino Mega and Arduino Uno using 2 pieces of HC-06?
hello sir,
How can I send my send sensor data to pc via Bluetooth.I have googled but I didn’t get any specific answer.
I am running into an issue with my HC-05. I intend to communicate with it from my smartphone and I’d like to be able to enter command mode from the phone over bluetooth. Is it possible to enter at mode from data mode? Previously i used a bluesmirf to do this. I would be in data mode on my phone and send $$$ to enter command mode and — to exit command mode. Is this also possible on HC-05? The reason I need this is I’d like to activate/deactivate one of the pins from my phone to turn a switch on/off. I would appreciate any help.
Dear Sir,
My self Gururaj, doing some project using Bluetooth. My question is that, can we pair and data transfer using Bluetooth module BM71(bm71bles1fc2)(Slave) and HC-05 (Master) Bluetooth?
Thanks
Gururaj
Hi Sir, I made a circuit with arduino board and HC05 module. I am having a mobile app to control the arduino. But it is not getting connected to my mobile. It is showing “pairing rejected by BT05”. As i know HC05 default it will be slave. Anything else to get it connected.
Dear Sir,
Is there any alternative to connect 7 Bluetooth devices as a slave with a master automatically with a delay of some time duration. i.e after a certain duration, it has to disconnect and another slave device has to connect. Practically I also found that only one master and one slave is communicating and I could not found other devices paired with the master. please help me out in this and request to make a video of piconet network