The HC-05 is a widely used Bluetooth module that enables wireless communication between devices. It operates in the 2.4 GHz ISM band and can be used to establish a serial connection between microcontrollers, computers, smartphones, and other Bluetooth-enabled devices. Common applications include wireless control systems, data logging, and user interface components for various electronic projects.
Pin Number | Name | Description |
---|---|---|
1 | KEY | Used to switch between command and data mode (active high) |
2 | VCC | Power supply (3.3V to 6V) |
3 | GND | Ground connection |
4 | TXD | Transmit Data (connect to RXD of MCU) |
5 | RXD | Receive Data (connect to TXD of MCU) |
6 | STATE | Indicates the connection status |
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX
void setup() {
pinMode(9, OUTPUT); // KEY pin if needed for mode switching
digitalWrite(9, LOW); // Normal operation mode
Serial.begin(9600);
BTSerial.begin(9600); // HC-05 default speed in AT command more
}
void loop() {
// Read from HC-05 and send to the Arduino Serial Monitor
if (BTSerial.available()) {
char c = BTSerial.read();
Serial.write(c);
}
// Read from the Serial Monitor and send to HC-05
if (Serial.available()) {
char c = Serial.read();
BTSerial.write(c);
}
}
Q: How do I change the baud rate of the HC-05?
A: You can change the baud rate using AT commands. Enter AT mode by pulling the KEY pin high and use the command AT+UART=<baud rate>,<stop bits>,<parity>
to set the desired baud rate.
Q: Can I connect multiple devices to the HC-05 at the same time? A: No, the HC-05 can only be connected to one device at a time in slave mode.
Q: How do I know if my HC-05 is in AT command mode? A: The HC-05 enters AT command mode when the KEY pin is held high on power-up. The LED will blink in a different pattern compared to normal mode, typically a slower blink rate.
Q: What is the default password for pairing the HC-05? A: The default password is usually '1234' or '0000'.