The Bluetooth HC-06 module is a widely-used wireless communication device that enables serial communication via Bluetooth technology. It is designed for transparent wireless serial connection setup and is often used in microcontroller projects to provide a bridge between the microcontroller and Bluetooth-enabled devices such as smartphones, laptops, and tablets.
Pin Number | Name | Description |
---|---|---|
1 | KEY | Used to switch between AT command mode and communication mode |
2 | VCC | Power supply input (3.3V - 6V) |
3 | GND | Ground connection |
4 | TXD | Transmit data (connects to RXD of microcontroller) |
5 | RXD | Receive data (connects to TXD of microcontroller) |
6 | STATE | Indicates the status of the Bluetooth module |
// Example code for connecting the HC-06 Bluetooth module to an Arduino UNO
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(10, 11); // RX, TX
void setup() {
// Start the serial communication with the host computer
Serial.begin(9600);
while (!Serial) {
; // Wait for serial port to connect.
}
// Start communication with the Bluetooth module
bluetooth.begin(9600);
Serial.println("Bluetooth module is ready");
}
void loop() {
// Check if data has been received from the Bluetooth module
if (bluetooth.available()) {
char received = bluetooth.read();
Serial.print("Received: ");
Serial.println(received);
}
// Check if data has been received from the serial monitor
if (Serial.available()) {
char sent = Serial.read();
bluetooth.write(sent);
}
}
Note: The SoftwareSerial
library is used to create a serial connection on pins 10 and 11, which are not the default serial pins on the Arduino UNO. This allows you to communicate with the HC-06 module while still using the default serial connection for debugging and communication with the host computer.