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
- Bluetooth Standard: v2.0 + EDR
- Operating Voltage: 3.3V to 5V DC
- Baud Rates: 9600, 19200, 38400, 57600, 115200, 230400, and 460800
- Communication Range: Up to 10 meters
- Master/Slave Modes: Configurable via AT commands
- Built-in LEDs: Status indicator
Modes of Operation
The HC-05 operates in two modes:
- 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.
- 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
- EN (Enable): Mode selection pin
- VCC: Power supply pin (3.3V)
- GND: Ground pin
- TXD: Transmit data
- RXD: Receive data
- State: Connection status
Wiring HC-05 Module to Arduino
Now, let’s interface the module with Arduino and communicate with Android Phone.
Hardware Requirements
- Arduino UNO R3
- HC-05 Bluetooth Module
- 1k and 2k Resistance
- Breadboard
- USB Cable Type A to B
- Jumper Wire
- 12V Supply Adapter
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.
- Install a Bluetooth Terminal App: Search...