The HC-05 Bluetooth Module is a widely used wireless communication module that enables devices to communicate with each other. With its ease of use, reliability, and affordability, it’s no wonder why it’s a popular choice among electronics enthusiasts and professionals alike. Whether you’re working on a robotics project, building a home automation system, or developing an IoT device, the HC-05 Bluetooth Module is an excellent choice for wireless communication.
What is the HC-05 Bluetooth Module?
The HC-05 Bluetooth Module is a wireless communication module that operates in Master/Slave configuration and uses Bluetooth SPP (Serial Port Protocol) to communicate with other devices. It is a small, compact module that is easily integrated into a variety of projects, including robotics, home automation, and IoT devices. It has 6 pins: STATE, RXD, TXD, GND, VCC, and EN/Key. The module is designed to be used with a microcontroller or a computer, and it supports both slave and master modes.
Operation in Master/Slave Configuration
The HC-05 Bluetooth Module can operate in both Master and Slave modes. In Master mode, the module acts as a host device, initiating connections and controlling data transfer. In Slave mode, the module acts as a peripheral device, responding to incoming connections and transmitting data as requested. This flexibility makes the HC-05 Bluetooth Module a versatile tool for a wide range of wireless communication applications.
Bluetooth SPP (Serial Port Protocol)
Bluetooth SPP is a protocol that allows devices to communicate with each other over a serial connection. It is a widely used standard for wireless communication and is supported by most Bluetooth devices. The HC-05 Bluetooth Module uses Bluetooth SPP to establish a wireless connection with other devices, allowing for reliable and efficient data transfer.
Overview of the HC-05 Pins
The HC-05 Bluetooth Module has 6 pins that provide a range of functions:
- STATE: Indicates the module’s status (e.g., connected, disconnected, etc.)
- RXD: Receives data from other devices
- TXD: Transmits data to other devices
- GND: Ground pin for power supply
- VCC: Power supply pin (typically 5V)
- EN/Key: Enables or disables the module (also used for pairing)
These pins provide a simple way to integrate the HC-05 Bluetooth Module into your project, allowing you to easily establish wireless communication with other devices.
Setting Up the HC-05 Bluetooth Module with Arduino
Step 1: Prepare the HC-05 Bluetooth Module
Before connecting the HC-05 Bluetooth Module to the Arduino Board, make sure it is properly prepared. This includes:
- Ensuring the module is in Slave mode (default)
- Setting the baud rate to 9600 (default)
- Pairing the module with the device you want to connect to (if necessary)
Step 2: Connect the HC-05 Bluetooth Module to the Arduino Board
Connect the HC-05 Bluetooth Module to the Arduino Board using the following connections:
- VCC to 5V on the Arduino Board
- GND to GND on the Arduino Board
- RXD to Digital Pin 3 (TX) on the Arduino Board
- TXD to Digital Pin 2 (RX) on the Arduino Board
- EN/Key: the enable pin for command mode to Digital Pin 4 on the Arduino Board (optional)
Step 3: Connect the Arduino Board to a Power Source
Step 4: Upload the Sketch to the Arduino Board
Upload a sketch to the Arduino Board that will communicate with the HC-05 Bluetooth Module. A simple example sketch is provided below:
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(2, 3); // RX, TX
const int enablePin = 4; // Choose a digital pin for the EN pin
void setup() {
 pinMode(enablePin, OUTPUT);
 digitalWrite(enablePin, HIGH); // Set EN pin high to enable the module
bluetooth.begin(9600);
}
void loop() {
bluetooth.println("Hello, Bluetooth!");
delay(1000);
}
#include <SoftwareSerial.h>
This line includes the SoftwareSerial library, which allows us to use digital pins for serial communication.
SoftwareSerial bluetooth(2, 3);
This line creates a SoftwareSerial object named “Bluetooth” and assigns it to digital pins 2 (RX) and 3 (TX).
void setup() {
bluetooth.begin(9600);
}
 In the setup function, the bluetooth.begin(9600)
command initializes the Bluetooth connection at a baud rate of 9600.
void loop() {
bluetooth.println("Hello, Bluetooth!");
delay(1000);
}
 In the loop function, the bluetooth.println("Hello, Bluetooth!");
command sends the string “Hello, Bluetooth!” over the Bluetooth connection. The delay(1000)
command then pauses the program for 1 second (1000 milliseconds) before repeating the loop.
Step 5: Test the Connection
Test the connection by opening the Serial Monitor in the Arduino IDE and checking for the “Hello, Bluetooth!” message. If the message is received, the HC-05 Bluetooth Module is properly connected and configured.
Configuring the HC-05 Bluetooth Module using AT Commands
Sending AT Commands
Basic AT Commands
Here are some basic AT commands used to configure the HC-05 Bluetooth Module:
- AT: Checks the module’s status and returns “OK” if it’s working properly.
- AT+PSWD=xxxx: Sets the password for pairing (replace “xxxx” with your desired password).
- AT+NAME=xxxx: Sets the module’s name (replace “xxxx” with your desired name).
- AT+UART=9600,1,0: Sets the baud rate, data bits, and parity (replace “9600” with your desired baud rate).
- AT+VERSION?: Returns the module’s firmware version.
- AT+ORGL: Returns the module’s default settings.
Advanced AT Commands
Here are some advanced AT commands used to configure the HC-05 Bluetooth Module:
- AT+ROLE: Sets the module’s role (Master or Slave).
- AT+IAC=xxxx: Sets the module’s address (replace “xxxx” with your desired address).
- AT+CLASS=xxxx: Sets the module’s device class (replace “xxxx” with your desired class).
- AT+INQM=xxxx: Sets the module’s inquiry mode (replace “xxxx” with your desired mode).
Example of Configuration
Here’s an example of how to configure the HC-05 Bluetooth Module using AT commands:
- Send AT to check the module’s status.
- Send AT+PSWD=1234 to set the password to “1234”.
- Send AT+NAME=MyBluetoothModule to set the module’s name to “MyBluetoothModule”.
- Send AT+UART=9600,1,0 to set the baud rate to 9600.
- Send AT+ROLE=1 to set the module to Master mode.
Note: Make sure to send each command followed by a carriage return (Enter) in the Arduino Serial Monitor and wait for the response before sending the next command. Â
Arduino code for sending AT commands to the HC-05 Bluetooth Module using Arduino Serial Monitor.
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(2, 3); // RX, TX
const int enablePin = 4; // Choose a digital pin for the EN pin
void setup() {
 pinMode(enablePin, OUTPUT);
 digitalWrite(enablePin, HIGH); // Set EN pin high to enable the module
bluetooth.begin(9600);
delay(1000);
}
void loop() {
sendATCommand("AT"); // Check status
delay(1000);
sendATCommand("AT+PSWD=1234"); // Set password
delay(1000);
sendATCommand("AT+NAME=MyBluetoothModule"); // Set name
delay(1000);
sendATCommand("AT+UART=9600,1,0"); // Set baud rate
delay(1000);
sendATCommand("AT+ROLE=1"); // Set role to Master
delay(1000);
}
void sendATCommand(String command) {
bluetooth.println(command);
while (bluetooth.available() > 0) {
char c = bluetooth.read();
Serial.print(c);
}
Serial.println();
}
This code is an Arduino sketch that uses the SoftwareSerial library to communicate with a Bluetooth module (HC-05) connected to digital pins 2 and 3 (RX and TX respectively). Here’s a breakdown of the code:
Include SoftwareSerial library
#include <SoftwareSerial.h>
This line includes the SoftwareSerial library, which allows for serial communication on any digital pins.
SoftwareSerial bluetooth(2, 3); // RX, TX
This line defines a SoftwareSerial object named “Bluetooth” and assigns it to digital pins 2 (RX) and 3(TX).
void setup() { ... }
The setup function is called once at the beginning of the program. It:
- Initializes the Bluetooth module with a baud rate of 9600 using
bluetooth.begin(9600)
. - Waits for 1 second using
delay(1000)
.
Loop function
void loop() { ... }
The loop function is called repeatedly after the setup function. It:
- Sends the AT command “AT” to check the status of the Bluetooth module using
sendATCommand("AT")
. - Waits for 1 second using
delay(1000)
. - Sends the AT command “AT+PSWD=1234” to set the password to “1234” using
sendATCommand("AT+PSWD=1234")
. - Waits for 1 second using
delay(1000)
. - Sends the AT command “AT+NAME=MyBluetoothModule” to set the name to “MyBluetoothModule” using
sendATCommand("AT+NAME=MyBluetoothModule")
. - Waits for 1 second using
delay(1000)
. - Sends the AT command “AT+UART=9600,1,0” to set the baud rate to 9600 using
sendATCommand("AT+UART=9600,1,0")
. - Waits for 1 second using
delay(1000)
. - Sends the AT command “AT+ROLE=1” to set the role to Master using
sendATCommand("AT+ROLE=1")
. - Waits for 1 second using
delay(1000)
.
Send AT Command function
void sendATCommand(String command) { ... }
This function sends an AT command to the Bluetooth module and prints the response. It:
- Sends the command using
bluetooth.println(command)
. - Waits for a response using
while (bluetooth.available() > 0) { ... }
. - Reads and prints each character of the response using
char c = bluetooth.read(); Serial.print(c);
. - Prints a newline character using
Serial.println()
.
Note: This code assumes that the Bluetooth module is properly connected to the Arduino board and that the baud rate and other settings are correct.
Pairing the HC-05 Bluetooth Module with a Bluetooth Device
Step 1: Make sure the HC-05 Bluetooth Module is in pairing mode
Step 2: Search for available Bluetooth devices on your device
Step 3: Select the HC-05 Bluetooth Module from the list of available devices
Step 4: Enter the pairing code (if required)
Step 5: Wait for the pairing process to complete
Step 6: Verify the connection
Sending and Receiving Data using the HC-05 Bluetooth Module
Connect the HC-05 Bluetooth Module to the Arduino Board using the following connections:
- VCC to 5V on the Arduino Board
- GND to GND on the Arduino Board
- RXD to Digital Pin 3 (TX) on the Arduino Board
- TXD to Digital Pin 2 (RX) on the Arduino Board
The HC-05 Bluetooth Module allows you to send and receive data wirelessly using Bluetooth technology. Here’s a step-by-step guide on how to send and receive data using the HC-05 Bluetooth Module:
Sending Data
To send data using the HC-05 Bluetooth Module, follow these steps:
- Connect the HC-05 Bluetooth Module to your microcontroller or single-board computer (e.g., Arduino or Raspberry Pi).
- Use the serial communication protocol (e.g., Serial Monitor in Arduino IDE) to send data to the HC-05 Bluetooth Module.
- Use the command “AT+SND=<data>” to send data to a connected device. Replace “<data>” with the actual data you want to send (e.g., “AT+SND=Hello, Bluetooth!”).
Receiving Data
To receive data using the HC-05 Bluetooth Module, follow these steps:
- Connect the HC-05 Bluetooth Module to your microcontroller or single-board computer (e.g., Arduino or Raspberry Pi).
- Use the serial communication protocol (e.g., Serial Monitor in Arduino IDE) to receive data from the HC-05 Bluetooth Module.
- Use the command “AT+RCV” to receive data from a connected device.
Arduino code that demonstrates how to send and receive data using the HC-05 Bluetooth Module:
SoftwareSerial bluetooth(2, 3); // RX, TX
void setup() {
bluetooth.begin(9600);
}
void loop() {
bluetooth.println("AT+SND=Hello, Bluetooth!"); // Send data
delay(1000);
bluetooth.println("AT+RCV"); // Receive data
while (bluetooth.available() > 0) {
char c = bluetooth.read();
Serial.print(c);
}
Serial.println();
delay(1000);
}
Raspberry Pi code that demonstrates how to send and receive data using the HC-05 Bluetooth Module:
import serial
ser = serial.Serial('/dev/ttyUSB0', 9600)
while True:
ser.write(b'AT+SND=Hello, Bluetooth!\r\n') # Send data
time.sleep(1)
ser.write(b'AT+RCV\r\n') # Receive data
while ser.inWaiting() > 0:
print(ser.read())
time.sleep(1)
Note: Make sure to adjust the pin numbers, baud rate, and serial communication protocol according to your setup.
The code is a Python script that uses the serial library to communicate with a serial device (in this case, a Bluetooth module) connected to a USB port. Here’s a breakdown of the code:
import serial
This line imports the serial library, which allows Python to communicate with serial devices.
ser = serial.Serial('/dev/ttyUSB0', 9600)
This line creates a serial object named “ser” and connects it to the serial device at the path “/dev/ttyUSB0” with a baud rate of 9600.
while True::
 This line starts an infinite loop that will continue to run until the program is stopped.
ser.write(b'AT+SND=Hello, Bluetooth!\r\n')
This line sends the string “AT+SND=Hello, Bluetooth!\r\n” over the serial connection. The “b” prefix indicates that the string should be sent as bytes, and the “\r\n” at the end represents a carriage return and newline character.
time.sleep(1)
 This line pauses the program for 1 second.
ser.write(b'AT+RCV\r\n')
 This line sends the string “AT+RCV\r\n” over the serial connection, which is a command to receive data.
while ser.inWaiting() > 0:
This line starts a loop that will continue to run as long as data is waiting to be read from the serial connection.
print(ser.read())
 This line reads the available data from the serial connection and prints it to the console.
time.sleep(1)
This line pauses the program for 1 second before repeating the loop.Applications of the HC-05 Bluetooth Module
The HC-05 Bluetooth Module has a wide range of potential applications due to its versatility, reliability, and affordability. Here are some examples of potential applications:
- Robotics: Wireless control of robots, communication between robots and computers, and sensor data transmission.
- Home Automation: Wireless control of home appliances, smart lighting systems, and temperature and humidity monitoring.
- Internet of Things (IoT): Wireless communication between devices, data transmission from sensors to the cloud, and smart home and industrial automation.
- Wearable Devices: Wireless communication between wearable devices and smartphones, health monitoring, and fitness tracking.
- Automotive: Wireless communication between vehicles and smartphones, vehicle tracking, and remote vehicle diagnostics.
- Medical Devices: Wireless communication between medical devices and computers, patient monitoring, and medical device control.
- Industrial Automation: Wireless communication between industrial devices, machine monitoring, and process automation.
- Smart Home Security: Wireless communication between security cameras and smartphones, motion detection, and smart door locks.
- Gaming: Wireless game controllers, game data transmission, and virtual reality applications.
- Education: Wireless communication between devices, interactive learning tools, and virtual classrooms.
- Smart Cities: Wireless communication between devices, smart traffic management, and environmental monitoring.
- Agriculture: Wireless communication between devices, soil moisture monitoring, and smart irrigation systems.
- Environmental Monitoring: Wireless communication between devices, air quality monitoring, and weather monitoring.
- Smart Energy Management: Wireless communication between devices, energy consumption monitoring, and smart grid management.
- Transportation: Wireless communication between devices, vehicle tracking, and smart traffic management.
Advantages of the HC-05 Bluetooth Module
- Easy to UseThe HC-05 Bluetooth Module is easy to use and requires minimal setup. It can be easily integrated into a variety of projects, including robotics, home automation, and IoT devices.
- ReliableThe HC-05 Bluetooth Module is a reliable and stable device that provides a consistent connection. It is designed to withstand interference and dropped connections, making it ideal for critical applications.
- AffordableThe HC-05 Bluetooth Module is an affordable device that offers excellent value for its price. It is a cost-effective solution for wireless communication and is ideal for projects where budget is a concern.
- Compatible with Arduino and Raspberry PiThe HC-05 Bluetooth Module is compatible with both Arduino and Raspberry Pi, making it the best wireless communication module that can be used with a variety of microcontrollers and single-board computers.
- Supports Multiple DevicesThe HC-05 Bluetooth Module can support multiple devices at once, making it ideal for applications where multiple devices need to communicate with each other.
- Small Form FactorThe HC-05 Bluetooth Module has a small form factor, making it easy to integrate into small projects and devices.
- Supports Bluetooth SPPThe HC-05 Bluetooth Module supports Bluetooth SPP (Serial Port Protocol), which allows it to communicate with other Bluetooth devices using a serial connection.
- Easy to ConfigureThe HC-05 Bluetooth Module is easy to configure and can be set up using AT commands.
- Widely AvailableThe HC-05 Bluetooth Module is widely available and can be purchased from a variety of online retailers and electronics stores.
Limitations of the HC-05 Bluetooth Module
While the HC-05 Bluetooth Module is a popular and flexible device, it also has some limitations and challenges that users should be aware of. Here are some of the key limitations:
1. Range and Interference
- The HC-05 Bluetooth Module has a limited range of around 10 meters (33 feet) in open space.
- It can be affected by interference from other Bluetooth devices and radio frequency sources.
2. Data Transfer Speed
- The HC-05 Bluetooth Module has a relatively slow data transfer speed of around 9600 bps.
- This can be a limitation for applications that require high-speed data transfer.
3. Power Consumption
- The HC-05 Bluetooth Module requires a significant amount of power to operate.
- This can be a limitation for battery-powered devices or applications where power consumption is a concern.
4. Compatibility Issues
- The HC-05 Bluetooth Module may not be compatible with all devices or operating systems.
- Users may experience compatibility issues when pairing the module with certain devices.
5. Security Risks
- The HC-05 Bluetooth Module uses a simple password authentication system.
- This can be a security risk if the password is not properly secured or if the module is used in a high-security application.
Troubleshooting Tips and FAQs
Common Issues and Their Solutions
- Issue: HC-05 Bluetooth Module not pairing with another device.
Solution: Check if the module is in pairing mode, ensure the device is compatible, and try resetting the module. - Issue: HC-05 Bluetooth Module not connecting to Arduino/Raspberry Pi
Solution: Verify the module’s baud rate, ensure proper wiring, and check the serial communication protocol. - Issue: HC-05 Bluetooth Module not transmitting/receiving data
Solution: Check the module’s configuration, ensure proper pairing, and verify the data transmission protocol. - Issue: HC-05 Bluetooth Module not powering on
Solution: Check the power supply, ensure proper wiring, and try resetting the module.
Frequently Asked Questions
- Q: What is the HC-05 Bluetooth Module’s range?
A: The HC-05 Bluetooth Module has a range of around 10 meters (33 feet) in open space. - Q: Can the HC-05 Bluetooth Module be used with any device?
A: The HC-05 Bluetooth Module is compatible with most devices that support Bluetooth SPP (Serial Port Protocol). - Q: How do I reset the HC-05 Bluetooth Module?
A: To reset the module, press and hold the EN (Enable) pin for 10 seconds. - Q: Can the HC-05 Bluetooth Module be used for high-speed data transfer?
A: The HC-05 Bluetooth Module has a relatively slow data transfer speed of around 9600 bps. - Q: Is the HC-05 Bluetooth Module secure?
A: The HC-05 Bluetooth Module uses a simple password authentication system, which can be a security risk if not properly secured. - Q: Can the HC-05 Bluetooth Module be used with multiple devices at once?
A: Yes, the HC-05 Bluetooth Module can support multiple devices at once. - Q: What is the HC-05 Bluetooth Module’s power consumption?
A: The HC-05 Bluetooth Module requires a significant amount of power to operate. - Q: Can the HC-05 Bluetooth Module be used outdoors?
A: Yes, the HC-05 Bluetooth Module can be used outdoors, but its range and performance may be affected by environmental factors.
Conclusion
In this blog post, we explored the HC-05 Bluetooth Module, a widely used wireless communication device. We discussed its features, applications, advantages, limitations, and troubleshooting tips. We also provided a comprehensive guide on how to use the module, including setting it up, sending and receiving data, and configuring it for various applications. In summary, the HC-05 Bluetooth Module is a flexible and reliable device that offers wireless communication capabilities for various projects and applications. Its ease of use, affordability, and compatibility with Arduino and Raspberry Pi make it a popular choice among electronics enthusiasts and professionals.
Final thoughts:
- The HC-05 Bluetooth Module is a great option for wireless communication projects, but consider its limitations and compatibility issues before using it.
- Always follow proper setup and configuration procedures to ensure reliable performance.
- Experiment with different projects and applications to fully explore the module’s capabilities.
- Keep in mind the module’s security risks and take necessary precautions to secure your data.
- Stay up-to-date with the latest firmware and software updates to ensure optimal performance.