The HC-06 is a widely used Bluetooth module that enables wireless communication between devices. It operates as a slave device, meaning it can only accept connections from a master Bluetooth device such as a smartphone or a computer. Common applications include wireless control for robotics, serial communication between microcontrollers, and DIY electronics projects that require Bluetooth connectivity.
Pin Number | Name | Description |
---|---|---|
1 | KEY | Used to switch the module to AT command mode |
2 | VCC | Power supply (3.6V to 6V) |
3 | GND | Ground connection |
4 | TXD | Transmit Data, connects to RXD of the host device |
5 | RXD | Receive Data, connects to TXD of the host device |
6 | STATE | Indicates the status of the Bluetooth connection |
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
// Open the serial communication
Serial.begin(9600);
mySerial.begin(9600); // Set the baud rate for the HC-06
Serial.println("Enter AT commands:");
}
void loop() {
// Forward what Serial received to Software Serial Port
if (Serial.available()) {
mySerial.write(Serial.read());
}
// Forward what Software Serial received to Serial Port
if (mySerial.available()) {
Serial.write(mySerial.read());
}
}
This code sets up a pass-through from the Arduino's serial monitor to the HC-06, allowing you to send AT commands directly from the serial monitor to configure the HC-06.
Q: Can the HC-06 act as a master device? A: No, the HC-06 is designed to function as a slave device.
Q: How do I change the name or PIN of the HC-06? A: You can change these settings using AT commands when the module is in AT command mode.
Q: What is the range of the HC-06 Bluetooth module? A: The typical range is up to 10 meters without obstacles, but this can vary depending on the environment and interference.
Q: Can I use the HC-06 with iOS devices? A: The HC-06 uses the SPP (Serial Port Profile), which is not supported by iOS. You would need a module that supports Bluetooth Low Energy (BLE) for iOS compatibility.