Pairing two HC-05 devices

Dear community,

since almost one week I tried to find a solution for this problem:

For medical simulation, I built six pulseoximeter-mockups and six remote control units. Both circuits are equipped with HC-05 modules, the mockups are slaves and the remote controls are masters.

Three conditions have to be realized:

  1. Every mockup must be combinable with every remote control, and therefore
  2. pairing between any mockup and any remote control must be done easily.
  3. If pairing was succeessful, the master is permitted to connect to only one slave and vice versa

The hardware for this requirements consists of a magnet and a reed contact in juxtaposition in each mockup and remote control. So if a mockup and a remote control are positioned side by side, both reed contacts are closed and give the signal to their microcontrollers to start the pairing process between these two individual devices.

At the moment I´m working with two HC-05 modules on a breadboard to find a suitable sequence of AT commands to pair them.

I tried the following sequences of AT-comands:

Remote control:
AT+ORGL (set default values)
AT+RMAAD (delete addresses of former binded devices)
AT+CMODE=1 (connect to all devices)
AT+ROLE=1 (set device as master)

After a High on the state-pin indicates the successful binding:
AT+CMODE=0 (connect to only one device)

Mockup:
AT+ORGL (set default values)
AT+RMAAD (delete addresses of former binded devices)
AT+CMODE=1 (connect to all devices)

After a High on the state-pin indicates the successful binding:
AT+CMODE=0 (connect to only one device)

After these commands the HC-05 modules only connect if I repower them. However, in both mockups and remote controls the modules are continuously connected to power, so repowering is technically not possible.

The AT+BIND command doesn´t help me, because it requires the address of the device that has to be bound, and this is not known in the particular case.

Can anybody give me a hint how to connect two arbitrary HC-05 devices?

Maybe this helps
http://www.martyncurrey.com/connecting-2-arduinos-by-bluetooth-using-a-hc-05-and-a-hc-06-easy-method-using-cmode/

Hi Nick,

thank you for that link!

The key information for me is, that even if the configuration is completed, the power of he master has to be cycled to make him search for available slave devices.

I hoped that there was any AT command to start the pairing process, but this "bug" seems to be a feature. So´ll have to bite the bullet and create a new PCB with a FET that switches the master´s power off and on again.

If anybody else here knows the "magic" AT-Command to make the master pair to an unknown slave without cycling the power: Give it to me :slight_smile:

Best regards,

Daniel

Sauerbruch:
I hoped that there was any AT command to start the pairing process, but this "bug" seems to be a feature. So´ll have to bite the bullet and create a new PCB with a FET that switches the master´s power off and on again.

No need for a FET, you can just use the EN pin if you have it on your HC-05 breakout PCB!

Also, you can reference my tutorial for pairing, linking, and binding HC-05 and HC-06 modules here. This won't work perfectly for your application (having two HC-05s), but it will give you an excellent starting point. If you get it working, you will be able to get the bluetooth modules to automatically pair and communicate on startup.

Also, if you want to automatically put the HC-05 into AT mode, you will have to wire a digital connection to the HC-05's pin 34 (KEY pin).

AT command mode:
1.) Drive EN pin LOW (turn module off)
2.) Drive KEY pin HIGH
3.) Drive EN pin HIGH (turn module on)
4.) Drive KEY pin LOW
5.) Module is in AT command mode

Well, getting into the AT mode is no problem. But the HC-05-devices I use are already mounted onto a PCB like these:

https://eckstein-shop.de/HC-05-Wireless-Bluetooth-Transceiver-Modul-mit-Adapter-Board?curr=EUR&gclid=EAIaIQobChMI2bW-zKuz4QIVTpPtCh1TXAoqEAQYAyABEgJ-Q_D_BwE

So I only have access to the RXD/TXD/KEY/STATE-pins, but not to the EN pin.

After my work I´ll take a look into your tutorial!

The KEY pin is what you need to configure it, and controlling the power supply is a reasonable approach. There are two levels of programming, and you may have to hold power against the KEY pin to get to the more obscure ones. Check Martyn's site about this.

Sauerbruch:
So I only have access to the RXD/TXD/KEY/STATE-pins, but not to the EN pin.

In that case, you can try powering the HC-05 with a digital I/O pin. The HC-05 draws somewhere around 40mA when transmitting/receiving and such a load it totally within spec of a digital I/O pin. You can do digitalWrite() to turn on or off the HC-05 once wired correctly.

Dear all,

thank you for all answers and suggestions!
After considering all possibilities I decided to power the master via a p-channel FET as a high-side switch, driven by an I/O-port of the microcontroller.
So I can repower the master easiliy and without straining the mc, and after that pairing works safely.

Daniel