DEV Community

Cover image for Wireless Communication Between Two Arduino Boards Using HC-05 Bluetooth Modules
Vaani Jain
Vaani Jain

Posted on

Wireless Communication Between Two Arduino Boards Using HC-05 Bluetooth Modules

Wireless communication between microcontrollers is useful when two electronic circuits need to exchange data without a physical connection. One straightforward way to achieve this with Arduino is by using HC-05 Bluetooth modules.

In this project, two Arduino UNO boards communicate wirelessly through two HC-05 Bluetooth modules. One module is configured as the Master, while the other operates as the Slave. The Master sends commands, and the Slave receives those commands, performs the required operation, and sends a response.

This setup is useful for understanding UART-based wireless communication, Bluetooth pairing, and master-slave architecture in embedded systems.

Understanding the HC-05 Bluetooth Module

The HC-05 is a Bluetooth module that supports serial communication through a UART interface. It can operate in either Master or Slave mode.

In Slave mode, the module waits for another Bluetooth device to establish a connection. In Master mode, it can initiate a connection with a specific Bluetooth device.

For communication between two Arduino boards, we need two HC-05 modules. One must be configured as the Master and the other as the Slave.

The Master Arduino acts as the controlling unit. It sends commands to the Slave Arduino, which processes the received data and returns a response.

Connecting the HC-05 Bluetooth Module to Arduino UNO

Before configuring the Bluetooth modules, we need to establish serial communication between the HC-05 and Arduino UNO.

The HC-05 communicates through UART, but Arduino UNO's hardware serial pins (0 and 1) are also used for USB communication and code uploading. Therefore, we can use the SoftwareSerial library to establish serial communication through digital pins 2 and 3.

The connections are as follows:

The HC-05 TXD pin connects directly to Arduino digital pin 2, which acts as the software serial RX pin.

The HC-05 RXD pin connects to Arduino digital pin 3, which acts as the software serial TX pin. However, the HC-05 RX pin is not 5V tolerant. A voltage divider using 1kΩ and 2kΩ resistors is required to reduce the Arduino's 5V output to approximately 3.3V.

For the voltage divider, connect the 1kΩ resistor between Arduino pin 3 and the junction point. Connect the 2kΩ resistor between this junction and GND. The HC-05 RXD pin connects to the same junction.

The VCC pin of the HC-05 connects to the Arduino 5V supply, and GND connects to Arduino GND.

The same UART connection arrangement is used when configuring both Bluetooth modules.

Configuring the HC-05 Modules Using AT Commands

The HC-05 module supports AT commands that allow us to change its operating mode, device name, connection settings, and other parameters.

Before sending these commands, the module must be placed in AT command mode.

For the HC-05 module with an AT-mode button, disconnect the USB cable after uploading the configuration program to Arduino. Press and hold the button on the Bluetooth module, reconnect the USB cable while keeping the button pressed, and continue until the module enters command mode.

The Arduino Serial Monitor should be configured with a baud rate of 9600 and both NL and CR line endings.

The HC-05 communicates at 38400 baud in command mode. The SoftwareSerial connection to the module should therefore use 38400 baud for AT command communication.

To verify that the module has entered command mode, send the following command:

AT

The module should respond with:

OK

Once communication is established, we can configure the two modules separately.

Configuring the Slave Bluetooth Module

The HC-05 operates in Slave mode by default. However, it is useful to configure its name and verify its role before pairing it with the Master.

First, change the device name using:

AT+NAME=SLAVE

Next, configure the module as a Slave:

AT+ROLE=0

The module should return an OK response after accepting each command.

Now, retrieve the Bluetooth address of the Slave module:

AT+ADDR?

The module returns its address in hexadecimal format. Keep this address because it will be required when configuring the Master module.

The default communication parameters of the HC-05 include a baud rate of 9600 bps, 8 data bits, 1 stop bit, no parity, and no hardware handshake. The default passkey is generally 1234 or 0000.

Configuring the Master Bluetooth Module

After configuring the Slave module, connect the second HC-05 module to Arduino and put it into AT command mode using the same procedure.

First, change its name:

AT+NAME=MASTER

Configure it to operate in Master mode:

AT+ROLE=1

Next, set the connection mode to a fixed Bluetooth address:

AT+CMODE=0

Now, bind the Master module to the Slave module using the address obtained earlier.

For example:

AT+BIND=0021,13,03BB60

Here, the address is divided into three hexadecimal sections. The first section contains four characters, the second contains two characters, and the third contains six characters. Leading zeroes are added where necessary.

The example address must be replaced with the actual address of the Slave HC-05 module.

To verify the binding, send:

AT+BIND?

The returned address should match the Slave module's address. If the returned value is incorrect or contains zeroes, repeat the binding procedure.

Once both modules are configured, they are ready for wireless communication.

Establishing Wireless Communication Between Two Arduino Boards

Now we can connect the two configured HC-05 modules to their respective Arduino UNO boards.

The Master board contains the input devices, while the Slave board handles the motor control operation.

The Master sends commands through its HC-05 module. The Slave module receives the data and forwards it to the Slave Arduino through its UART interface.

The Slave Arduino processes the command and sends a response through the same communication path.

One important point is the power-up sequence. The Slave board should be powered ON before the Master board. When the Master HC-05 starts, it attempts to establish a connection with the Slave using the previously configured Bluetooth address.

When the connection is established successfully, the onboard LED of the Master Arduino turns ON.

Controlling a DC Motor Through Bluetooth

To understand the communication process, consider a practical example in which a 12V DC motor is connected to the Slave circuit through an L293D motor driver IC.

The Master Arduino is responsible for controlling the motor remotely.

Three push buttons are connected to the Master Arduino at digital pins 7, 6, and 5. These buttons perform three operations:

  • The first button rotates the motor in the clockwise direction.
  • The second button stops the motor.
  • The third button rotates the motor in the anticlockwise direction.

A 10kΩ potentiometer is connected to analog pin A0. It is used to adjust the motor speed.

The Master Arduino reads the button states and the analog value from the potentiometer. Based on these inputs, it generates a command and transmits it to the Slave Arduino through the Bluetooth connection.

The Slave Arduino receives the command and controls the motor through the L293D motor driver.

The L293D is used because the Arduino cannot directly drive a 12V DC motor. The motor driver handles the motor supply and switching required to control its direction.

Understanding the Communication Protocol

For reliable communication between the two Arduino boards, the project uses a simple command-response format.

Each command begins with an asterisk (*) and ends with a hash (#). These characters help the receiving Arduino identify the beginning and end of a message.

The first command is an Alive command. It is used to check whether the Master and Slave boards are communicating properly.

The Master sends:

*ALIVE#

If the Slave receives the command successfully, it responds with:

*OK#

The second command is used for motor control. It contains two values: a direction byte and a speed byte.

The command format is:

*DIRECTION_BYTE,SPEED_BYTE#

For example:

*1,255#

The direction byte determines the motor's operating direction, while the speed byte represents the speed value transmitted by the Master.

After receiving and processing a valid command, the Slave sends an acknowledgement:

*OK#

This simple protocol makes it easier to identify incoming messages and verify whether the Slave has received the command.

Hardware and Software Requirements

The hardware setup consists of two Arduino UNO R3 boards, two HC-05 Bluetooth modules with AT-mode buttons and six pins, four resistors (1kΩ and 2kΩ), an L293D motor driver IC, two breadboards, jumper wires, USB cables, three push buttons, a 10kΩ potentiometer, a 12V DC motor or fan, and suitable power supplies.

The software requirements include Arduino IDE version 2.1.1 or above and the SoftwareSerial library.

Monitoring the Bluetooth Connection

The onboard LED connected to digital pin 13 of the Master Arduino can also be used as a connection status indicator.

When the Master successfully connects to the Slave, the LED turns ON and remains ON while the connection is active.

If the Master becomes disconnected from the Slave, the LED turns OFF.

If the LED starts blinking, it indicates that command or response frames are being dropped. In this situation, bringing the two Arduino boards closer can help improve the Bluetooth communication.

Conclusion

Using two HC-05 Bluetooth modules is a simple way to establish wireless communication between two Arduino boards. By configuring one module as Master and the other as Slave, we can create a basic wireless control system without requiring a separate wireless networking protocol.

The same approach can be extended to other applications where one Arduino needs to monitor or control another remotely. Understanding UART communication, AT command configuration, Bluetooth pairing, and command-response handling provides a useful foundation for building more advanced embedded systems.

For the complete Arduino source code, detailed circuit diagrams, pin connections, and step-by-step implementation, refer to the original tutorial published on Play with Circuit:

Wireless Communication Between Two Arduino Boards Using HC-05 Bluetooth Modules

Top comments (0)