HC 05 Master Slave Seamless Communication

Share

I have been playing with the HC 05 Bluetooth module in the past week, and found some really good tutorials that teach you how to get started. Many of them cover how to use the HC05 as a slave, with a computer and a script at the other end.

That’s very useful, but there are many scenarios in which you might want two HC 05 modules to communicate with each other, unassisted. You can’t and don’t want to make the module search, pair and connect before you can actually start doing some meaningful communication.

Below, I will describe how to get one HC 05 module to act as a master and another one as a slave. The master will automatically look for, pair with, and establish a connection with the slave, and you can just get on with the communication right away.

Here are how the connections will work.

Connections

Notice that the connections are crossed on one end but not on the other.

P.S. I am assuming you already know how to use the Serial monitor with an Arduino or any other serial terminal with the CP2102 , so I am going to jump right in.

Here are the steps we will follow to accomplish what we need :

Master Configuration
———————

1.Put the module in AT mode :

The HC 05 modules are generally in “transparent mode”, which means that they will take serial data on the Rx and Tx lines and pass them over the wired or wireless link directly, and will not treat anything as an
instruction”. To configure them, they must be put in Command mode. The “Key” pin on the HC 05 modules is not broken out, and needs to be “HIGH” when powered on to enter AT “command” mode.

HC 05 Key Pin

For that, you can either solder a wire and connect it to VCC when powering on the module, or you can simply touch a jumper wire between the Key pin and ground while powering it on. If the module has entered the AT mode, it will be a solid red with no blinking. If not, it will blink very fast, and you should retry. You can disconnect the wire once the module is in AT mode.

2. Make the configurations for pairing :

a. Clear all previously paired devices
On your serial terminal, enter the command : AT+RMAD

If the command was accepted, you will get an “OK” as a response.

b. Set PIN
AT+PSWD=1234
Replace 1234 with your chosen 4 digit PIN.

c. Set role as “1”

AT+ROLE=1
This sets the module as master, which will actively seek for connections with paired devices.

d. Set connect mode as “1”

AT+CMODE=1
This sets the master to connect to any device with the pin. This is necessary for pairing the first device.

d. Reset

AT+RESET
This resets the module and the master starts looking for modules to pair with.

Slave configuration
——————–

1.Put the module in AT mode :

Just like the step above for the master.

2. Make the configurations for pairing :

a. Clear all previously paired devices : AT+RMADD

b. Set PIN : AT+PSWD=1234

c. Set role as “0” : AT+ROLE=0

This sets the module as master, which will actively seek for connections with paired devices.

d. Set connect mode as “1” : AT+CMODE=1

d. Reset : AT+RESET

After this, if both modules are powered on, they will connect and transfer data to each other transparently i.e. It would be as if the Rx and Tx connections of the two microcontrollers were directly connected to each other and the modules themselves would invisibly do their job.

However, we must go one step further to add reliability. We will now change the CMODE setting to make sure the modules only connect to paired devices. Since we have paired with exactly one device, this ensures that in noisy environments with other devices around, nobody can hijack or block your connection.

Master & Slave
—————

1. Put the device in AT mode as above.

2. Set connect mode as “0” : AT+CMODE=0

3. Reset : AT+RESET

1. Set the pin of the master and slave to the same PIN.
2. Set the Role of one module as Master and the other as slave
3. Set the Mode of the modules as “1” to connect with each


Resources
1. https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pair-two-modules/

2. AT Command sheet

3. Alternate way of doing this using AT+BIND

4. Using the CP2102 with your Serial Terminal

 

Share