fbpx

Configuring HC05 in Master & Slave mode

Those who are landing on page must be working on sending/receiving data via bluetooth between controller boards. So let’s start with how to do that.

HC05, by default acting as a Bluetooth transceiver which is ready to get pair with your smart phone to send and receive data from it. So if you want to make any mobile controlled bluetooth project you don’t need to do additional changes to your bluetooth board. But if you want to send and receive data from HC05 module to another HC05 module, you need to enter some commands in it before using them. So let’s see what are those commands.

Watch out video if reading bores you

This is the complete tutorial video about how to configure HC-05 modules in Master & Slave modes

Setting up HC05 to Enter AT Commands

Before moving towards configuring HC05 in Master or Slave mode, we first need to make our module ready to accept AT Commands.

For that we need to make connections between the controller board and HC05 module as shown in the below mentioned image. We have used Arduino Nano board for our project, you can use any of your Arduino board for this.

AT Commands connections

After making the connections, make sure you press and hold the small pushbutton on HC05 module and then power up the circuit. After powering up when the red light on HC05 module starts blinking slowly (every 2 seconds) then you can release the pushbutton. With this, we successfully configured the module to accept AT commands.

Now open up Arduino IDE and upload below mentioned sketch on your Arduino Nano board. This is the Sketch for Software Serial communication.

#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX

char c = ' ';

void setup()
{
  Serial.begin(9600);
  Serial.println("Arduino is communicating at 9600 baud rate");

  BTserial.begin(38400);
  Serial.println("HC05 is communicating at 38400 baud rate");
}

void loop()
{
  // Keep reading from HC-05 and send to Arduino Serial Monitor

  if (BTserial.available()) {
    Serial.write(BTserial.read());
  }
  if (Serial.available()) {
    BTserial.write(Serial.read());
  }

}

After uploading this code, you need to remove USB cable connected to computer, Press and Hold the button on HC-05 module and then plug the USB cable again to power up. After couple of seconds, the LED on the HC-05 module will start blinking slowly(2sec interval). This reveals that now this module is ready to accept AT commands.

Button on Module
Press and Hold

Now open up serial monitor, make sure the baud rate of Serial monitor is set to 9600. After that just type AT and press Enter. You should get the response as OK which reveals that everything is working perfectly fine.

Typing AT
Response OK

If you are not getting response as OK, you need to cross check couple of things.

  • Checking All wire connections
  • Make sure the light on HC-05 is blinking at interval of 2sec, if not remove cable and press button again & then plug it again
  • Try Changing the baud rate of BTSerial inside the code to 9600 or 115200 and try again

Slave Configuration

After successfully making HC-05 module to work with AT commands, now we are ready to send some commands to make them act like Master or Slave module.

For Slave configurations we need to type 3 commands

  1. AT+UART = 38400,0,0 <- This will change the baud rate to 38400
  2. AT+ROLE = 0. <- This will change role to 0. (0 = Slave, 1 = Master)
  3. AT+ADDR? <- This will give us the Address of the bluetooth module

That was all about the slave module configuration. Now let’s jump to master module configuration

Master Configuration

For master configuration, just remove that previous HC-05 module and insert the second one and follow the same steps to make it accept the AT Commands.

Now to configure it in Master mode, just enter below mentioned commands

  1. AT+UART = 38400,0,0 <- This will change the baud rate to 38400
  2. AT+ROLE = 1. <- This will change role to 1. (0 = Slave, 1 = Master)
  3. AT+CMODE = 0 <- This will allow the master module to connect to 1 single device only
  4. AT + BIND = Address of Slave Module <- This command will make the master module get connected to our slave module

That were the steps to configure the master module.

After Configurations

After configuring Master & Slave module, now you are ready to make communication between them. Just connect both the module on different controller boards and just power them up simply. After couple of seconds both the modules will get connected with each other.

You can confirm that they are connected by looking at the LEDs connected on the bluetooth module. When they start blinking slowly, it reveals that they are connected with each other. After doing this configurations now you can make any project that require bluetooth communication between each other.

We have made one very interesting project using this Master & Slave communication between HC-05 modules. Have a look