What is the HC-05 Bluetooth Module?

The HC-05 Bluetooth module is a simple, versatile, and low-cost device that enables wireless communication between devices like Arduino and a smartphone. It uses the Bluetooth 2.0 standard, allowing for serial communication over a range of 10 meters. Its easy-to-use interface makes it perfect for projects where wireless data transmission is needed.

Specifications of HC-05 Bluetooth Module

Modes of Operation

The HC-05 operates in two modes:

  1. Command Mode: Command mode is used to configure the HC-05 Bluetooth module using AT commands. This mode allows you to change the module's settings, such as baud rate (speed of communication), name of the device, PIN code (used for pairing with other devices), etc.
  2. Data Mode: Once the module has been configured, it is switched to Data Mode to allow wireless communication. In this mode, the HC-05 acts as a transparent bridge between devices (such as between an Arduino and a smartphone) and transmits data over a wireless connection.

Configurations

The HC-05 Bluetooth module can operate in two primary configurations: Slave Mode and Master Mode. These configurations determine whether the HC-05 will wait for a connection or actively initiate one.

1. Slave Mode

In Slave Mode, the HC-05 acts as a slave device that waits for a master device (such as a smartphone or another Bluetooth-enabled device) to connect to it. This means that the module does not initiate communication but listens for connection requests from other devices.

Slave Mode is ideal when the module needs to receive commands or data from another device. For example, in a home automation project, a smartphone could connect to the HC-05 module to control lights or appliances.

2. Master Mode

In Master Mode, the HC-05 acts as the master device and is responsible for initiating connections with other Bluetooth devices. In this mode, the HC-05 searches for nearby Bluetooth devices and initiates the pairing process. Once connected, it can send or receive data from the connected devices.

Master Mode is useful when the HC-05 needs to control or manage other devices. For example, in a robotic system, the master HC-05 can connect to multiple slave devices (such as sensors or motors).

HC-05 Pinout

Wiring HC-05 Module to Arduino

Now, let’s interface the module with Arduino and communicate with Android Phone. 

Hardware Requirements

Arduino Code

// Include Software Serial Library this library makes DIO pins as Serial Pins
#include <SoftwareSerial.h>
//Create software serial object to communicate with HC-05
SoftwareSerial BTSerial(2, 3);  // Now pin 2 and pin 3 of Arduino are Serial Rx & Tx pin Respectively
void setup() {
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
  Serial.println("Initializing Bluetooth Module in Data Mode\n");
  // Begin the soft Serial port and set the data rate for the SoftwareSerial port at 9600 to communicate with Bluetooth Module in Data Mode
  BTSerial.begin(9600);
  Serial.print("Bluetooth Module is Successfully Initialized in Data Mode\n");
}
void loop() {
  // Get Data From Serial Terminal and Push to HC-05
  if (Serial.available()) {
    BTSerial.write(Serial.read());
  }
  // Get Data from HC-05 and push to Serial Monitor
  if (BTSerial.available()) {
    Serial.write(BTSerial.read());
  }
}

Connecting to the Android Phone

Let’s connect the HC-05 module and an Android phone. 

  1. Install a Bluetooth Terminal App: Search for a Bluetooth Terminal App from the Google Play Store. This app will allow you to send and receive data over Bluetooth.
  2. Pair with the HC-05: Turn on Bluetooth on your phone and search for the HC-05 module. Select it to pair with the device (default passkey is 1234 or 0000).
  3. Open the Terminal App: Open the Bluetooth terminal app, connect to the HC-05 module, and start sending messages. The message will be displayed on the Arduino Serial Monitor, and you can also send data from the serial monitor to be displayed on your phone.

To learn about HC-05 module in detail and how to control 12V DC Fan Speed and Direction from Android Application using HC-05 check out:

https://playwithcircuit.com/hc05-bluetooth-module-arduino-tutorial/