So you want to two HC-05 modules to automatically connect together, as soon as they're powered up and with zero code? Well this is your lucky day since this can be done using the AT+BIND command.
Let's do this thing!
For this, you will need:
- 1 Arduino (I'm using UNO)
- 2 HC-05 modules
- 1 breadboard
- Wires
- Arduino IDE (I'm using version 1.0.5-r2)
Step 1 - Code and Wires
To bind the two HC-05s, we will need to input AT commands manually which can be done using this
simple code made by
techbitar.
1.1 Upload
the code to your Arduino.
1.2 Using one of your 2 HC-05, follow very carefully the
wiring instructions (this is where most people make mistakes.)
Note that the pins layout on your HC-05 might be different so read the pin label and be sure to connect the right ones.
Step 2 – Configure the Slave
2.1 Make sure the power wire(5.0v or 3.0v) is disconnected from the HC-05
2.2 Make sure the Key wire is connected to pin 9
2.3 In the Arduino IDE, goto the Tools\Serial Monitor menu
2.4 The two following settings are correctly set (at the bottom right of the window):
2.4.1 Line ending should be set to “Both NL & CR”
2.4.2 Baud speed should be set to “9600 baud”
Note: f you had to modify those settings, I suggest to close and re-open the Serial Monitor dialog
2.5 When the Arduino is reseted (opening the Serial Monitor dialog will force a reset) you should see the following text “Enter AT commands:” in the Serial Monitor dialog.
2.7 Connect the power wire(5.0v or 3.0v) on the HC-05. You should see the red light slowly blinking (once every ~2 seconds)
2.8 In the Serial Monitor, type AT and press Enter (or click the Send button). The module should return OK right away
2.9 In the Serial Monitor, type AT+ROLE=0 and press Enter. This will set the module in Slave mode. You can verify that it worked by typing AT+ROLE? (It should return +ROLE:0)
2.10 In the Serial Monitor, type AT+BIND= and press Enter. This will remove any existing binding. You can verify that it worked by typing AT+BIND? (It should return +BIND:0:0:0)
2.11 In the Serial Monitor, type AT+ADDR? and press Enter. This will return the MAC address of this HC-05 module. For example: my module's address is 00:13:03:19:14:07 and the command is returning +ADDR:13:3:191407. As you can see the zeros are stripped out and the formating is a bit different but, as you will soon see, this will not be a problem. Write down on a piece of paper this MAC address.
2.12 Disconnect the power wire from the HC-05 and remove this HC-05 from the breadboard. It is now ready to act as the Slave module.
Note: Don't disturb the wiring since you will use it to configure the second module.
Step 3 – Configure the Master
*Start by installing the second HC-05 on the breadboard. Exactly where the first module was plugged.
3.1 Make sure the power wire(5.0v or 3.0v) is disconnected from the HC-05
3.2 Make sure the Key wire is connected to pin 9
3.3 In the Arduino IDE, goto the Tools\Serial Monitor menu
3.4 The two following settings are correctly set (at the bottom right of the window):
3.4.1 Line ending should be set to “Both NL & CR”
3.4.2 Baud speed should be set to “9600 baud”
Note: f you had to modify those settings, I suggest to close and re-open the Serial Monitor dialog
3.5 When the Arduino is reseted (opening the Serial Monitor dialog will force a reset) you should see the following text “Enter AT commands:” in the Serial Monitor dialog.
3.7 Connect the power wire(5.0v or 3.0v) on the HC-05. You should see the red light slowly blinking (once every ~2 seconds)
3.8 In the Serial Monitor, type AT and press Enter (or click the Send button). The module should return OK right away.
3.9 In the Serial Monitor, type AT+ROLE=1 and press Enter. This will set the module in Master mode. You can verify that it worked by typing AT+ROLE? (It should return +ROLE:1)
3.10 In the Serial Monitor, type AT+BIND=13,3,191407 and press Enter (of course here you should be using your MAC address that you have noted on step 2.12). This will force the Master module to automatically link (bind) to the Slave. You can verify that it worked by typing AT+BIND? (It should return +BIND:13:3:191407)
3.11 Disconnect the power wire from the HC-05 and remove this HC-05 from the breadboard. It is now ready to act as the Master module.
Done.
Now if you power both modules, they will connect right away. It doesn't matter if you power one before the other one. They will always initiate the connection automatically. All you need to use them in your next Arduino project is to open a Serial port and communicate through it.
Edit 1: Get more info on HC-05 through this
previous post and this
video.
This post is featured on: