Tag Archive: HOW TO PAIR TWO BLUETOOTH MODULES

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

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.