The HC-05 Bluetooth Module is a versatile and powerful device for wireless communication. It operates on Bluetooth 2.0 technology and can be used to establish a serial connection between two devices, enabling them to communicate over a short range of up to 10 meters (class 2). Common applications of the HC-05 include wireless control systems, data logging, and remote sensor monitoring. It is particularly popular in the DIY electronics community for projects involving Arduino, Raspberry Pi, and other microcontrollers.
Pin Number | Name | Description |
---|---|---|
1 | KEY | Used to switch between command and data mode (active high) |
2 | VCC | Power supply (3.3V to 6V input, typically 5V) |
3 | GND | Ground connection |
4 | TXD | Transmit data (connect to RXD of the host device) |
5 | RXD | Receive data (connect to TXD of the host device) |
6 | STATE | Indicates the module status (paired/not paired) |
7 | EN | Module enable pin (active high) |
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX
void setup() {
pinMode(9, OUTPUT); // HC-05 key pin
digitalWrite(9, HIGH); // Enable AT command mode
Serial.begin(9600);
Serial.println("Enter AT commands:");
BTSerial.begin(38400); // HC-05 default speed in AT command mode
}
void loop() {
// Read from HC-05 and send to Arduino Serial Monitor
if (BTSerial.available()) {
Serial.write(BTSerial.read());
}
// Read from the Serial Monitor and send to HC-05
if (Serial.available()) {
BTSerial.write(Serial.read());
}
}
This example demonstrates how to set up a basic serial communication between an Arduino UNO and the HC-05 Bluetooth module. The code initializes a SoftwareSerial
instance to communicate with the HC-05 module and sets up the serial communication with the PC for debugging.
Q: What is the default baud rate of the HC-05? A: The default baud rate for communication is 9600 bps, but it can be changed using AT commands.
Q: Can I use the HC-05 with a 3.3V microcontroller? A: Yes, the HC-05 can be interfaced with 3.3V logic directly. However, ensure that the VCC is supplied with the correct voltage.
Q: How do I reset the HC-05 to factory settings?
A: You can reset the HC-05 by issuing the AT command AT+ORGL
.
Q: Can the HC-05 be used as both master and slave? A: Yes, the HC-05 can be configured as either a master or a slave device using AT commands.
This documentation provides a comprehensive guide to using the HC-05 Bluetooth Module. For further assistance, consult the datasheet or contact technical support.