Hadoop

Connecting Two HC-05 Bluetooth Together Using Arduino

Hey friends I am going to connect two Arduino bluetooths(HC-05) together.

We don’t need much just an Arduino, two Bluetooths, and a set of wires.

Given below is the schematic.

The code for the Arduino is as follows:

include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX
void setup()
{
Serial.begin(9600);
Serial.println("Enter AT commands:");
BTSerial.begin(38400); // HC-05 default speed in AT command more
}
void loop()
{
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTSerial.available())
Serial.write(BTSerial.read());
// Keep reading from Arduino Serial Monitor and send to HC-05
if (Serial.available())
BTSerial.write(Serial.read());
}

After uploading the code follow the next steps:

For the Slave Bluetooth Module:

Disconnect module. While pressing the button on the module connect it back.
You will see the led on the module is blinking slower. Once every 2 seconds.
This means HC-05 is in the AT command mode.
Now open serial monitor change the baud rate to 9600 and output type as both NL & CR.
Now type AT in send box and send it. if it replies with ok, it means all is well.
But, if it does not, and replies with some error.
Send AT again until it replies with ‘OK’ or check the connections and send AT again.

After getting ‘OK’ response from module enter the following commands one by one:
AT+RMAAD this command will release module from any previous pairing
AT+UART? To check the current baud rate of the module
AT+UART=38400, 0, 0 To set the baud rate as 38400
AT+ROLE? Check the role whether it is slave or master.
It replies with 0 or 1
If the module is a slave it replies 0 and if it is a master device then it will reply with 1
To set the role as a slave device enter AT+ROLE=0
AT+ADDR? check the module address. It should be something like ‘ADDR:21:13:37F1
Note down the address replied by the module. Forex; 21:13:37F1
After getting the address, configuration for the slave module is done.

For the master Bluetooth Module

Enter these AT commands by given sequence.
AT+RMAAD
AT+UART?
AT+UART=38400, 0, 0
AT+ROLE?
Set the role of this module as the master device. AT+ROLE=1
AT+CMODE=0 so that the module will connect to only a single device. The default setting is 0
Now bind this module with the slave device to do this enter,
AT+BIND=” the address of the slave module” For example AT+BIND=”21:13:37F1″
And all is done.

Leave a Reply

Your email address will not be published. Required fields are marked *