Go Down

Topic: Configure and Pair HC-05 and HC-06 Bluetooth Modules (Read 786 times) previous topic - next topic

Power_Broker

Mar 01, 2019, 02:13 am Last Edit: Apr 02, 2019, 12:34 am by Power_Broker
In all my time building projects with Arduinos, nothing has been a more mind-breaking nightmare than trying to pair, bind, and link an HC-05 with an HC-06.

Trying to follow online bluetooth tutorials doesn't help because they are either outdated, ambiguous, or incorrect. No matter what, though, ALL of the current tutorials out there are extremely tedious - requiring all AT commands to be executed by hand.


THE GOOD NEWS:
You can use the attached sketch to automatically pair, bind, and link an HC-05 with an HC-06 in under 30 seconds. You don't need to learn any AT commands!!

Also, this sketch will work if you have multiple hardware serial ports (i.e. Mega) or if you need to use software serial ports (i.e. Uno) - one sketch to rule them all...



EDIT: The most recent code can be found here in the tutorial's Github Repo.


"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

Power_Broker

#1
Mar 01, 2019, 02:19 am Last Edit: Mar 01, 2019, 02:21 am by Power_Broker
If all goes well, you should see something similar to this in your serial monitor:

Quote
<<<=====================================================================>>>
Put HC-05 into AT mode
Ensure Serial Montior line-ending is 'Newline'
Enter the desired name of the HC-06
<<<=====================================================================>>>

Entered name is: myBT

AT
OK
AT+ROLE=0
OK
AT+UART=9600,0,0
OK
AT+CMODE=0
OK
AT+PSWD=1234
OK

AT
OK
AT+NAMEmyBT
OKsetname
AT+BAUD4
OK9600
AT+PIN1234
OKsetPIN

AT+RMAAD
OK
AT+ROLE=1
OK
AT+RESET
OK

<<<=====================================================================>>>
Put HC-05 back into AT mode, press and hold the HC-05 button, and send 'OK' through Serial Monitor
   MAKE SURE THE HC-05's BUTTON IS PRESSED UNTIL TOLD OTHERWISE!!!
<<<=====================================================================>>>

AT
OK
AT+CMODE=0
OK
AT+INQM=0,5,9
OK
AT+INIT
OK
AT+INQ
+INQ:A402:B9:29F454,A010C,7FFF
+INQ:98D3:31:FB8013,1F00,7FFF

<<<=====================================================================>>>
HC-05's button no longer needs to be pressed

Put HC-05 back into AT mode, press and hold the HC-05 button, and send 'OK' through Serial Monitor
   MAKE SURE THE HC-05's BUTTON IS PRESSED UNTIL TOLD OTHERWISE!!!
<<<=====================================================================>>>

AT
OK
AT+INIT
OK
AT+RNAME?A402,B9,29F454
DESKTOP-3MD8VVS
AT+RNAME?98D3,31,FB8013
myBT
   HC-06 found at address: 98D3:31:FB8013
AT+PAIR=98D3,31,FB8013,20
OK
AT+BIND=98D3,31,FB8013
OK
AT+CMODE=1
OK
AT+LINK=98D3,31,FB8013
OK

<<<=====================================================================>>>
HC-05's button no longer needs to be pressed - Modules shoud be paired! :D
<<<=====================================================================>>>
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

Power_Broker

#2
Mar 01, 2019, 10:33 pm Last Edit: Mar 01, 2019, 10:35 pm by Power_Broker
One quick note: In order to put the HC-05 into AT mode, you must:

1.) Disconnect power to the module
2.) If your HC-05 breakout board has a "KEY" pin, set that HIGH (3v3) - if not, press and hold the tiny pushbutton on the top of the module
3.) Reconnect power to the module (5V for most breakout boards)
4.) Drive "KEY" pin low if "KEY" pin present - if not, let go of the pushbutton    <---    Only disengage the "KEY" or pushbutton if the above program says you can, otherwise keep "KEY" high/pushbutton pressed until all AT commands that need your HC-05 in that configuration are done

Also, HC-06 modules can be put into AT mode at anytime - no buttons or extra pins required.

Lastly, the "EN" pin IS NOT THE SAME as the "KEY" pin. "EN" pin will "enable" (turn on and off) the module based on the pin's voltage level.
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

Power_Broker

Currently working on making edits to the tutorial code so that it can also run on boards that do not have extra serial ports - one sketch to work nomatter what sort of board you have ;)
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

Power_Broker

#4
Mar 03, 2019, 05:57 am Last Edit: Mar 03, 2019, 05:58 am by Power_Broker
Good news folks!

I was able to get the softwareserial part of the tutorial working. Now you no longer need a Mega to run this tutorial, now you can use an Uno, a Nano, etc. The sketch attached to the original post has been updated with the new feature.
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

Power_Broker

#5
Mar 14, 2019, 12:44 am Last Edit: Mar 14, 2019, 12:45 am by Power_Broker
I had to update the sketch because the wiring directions in the header comments were incorrect.

Also, I made schematics for the wiring required for this tutorial:





Although it's usually advisable to use a level shifters or voltage dividers for the serial signal from the Arduino TX to the bluetooth RX pins, you really don't need them for this quick setup tutorial.
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

Power_Broker

#6
Mar 21, 2019, 12:04 am Last Edit: Mar 21, 2019, 12:06 am by Power_Broker
In order to understand what is going on in the tutorial code and for general AT command reference for both modules, the datasheets for both modules are attached below.

"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

Power_Broker

Made a Github repository for this tutorial - the most updated sketch for this tutorial will be found here.

As always, please let me know if you run into any problems or have any suggestions to improve or expand this tutorial.
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

Go Up