Introduction
This article provides a detailed guide on how to set the HC-05 Bluetooth module to serial mode, which will enable it to communicate with a computer via a COM port.
Prerequisites
Before proceeding, ensure you have the following:
- HC-05 Bluetooth module
- USB to TTL Serial converter
- Computer with a COM port or a USB-to-COM adapter
- Arduino IDE or any other serial terminal software
Setting HC-05 Bluetooth Module to Serial Mode
Follow these steps to set the HC-05 Bluetooth module to serial mode:
- Power on the HC-05 module and the USB to TTL Serial converter.
- Connect the HC-05 module to the USB to TTL Serial converter as follows:
- VCC (3.3V or 5V) to VCC (5V or 3.3V) on the converter
- GND to GND on the converter
- TXD to RXD on the converter
- RXD to TXD on the converter
Connect the USB to TTL Serial converter to the computer's COM port or USB-to-COM adapter.
- Open the Arduino IDE or any other serial terminal software.
- Set the baud rate to 9600.
- Connect to the COM port associated with the USB to TTL Serial converter.
- Press and hold the reset button on the HC-05 module while powering it on. Release the button after a few seconds.
- Enter the following command sequence:
AT+ROLE0\r
// Set the HC-05 to slave mode
AT+UART=38400,0,0,0\r
// Set the baud rate to 38400
AT+CMODE=1\r
// Set the communication mode to serial
Press Enter after each command.
- If the module responds with "OK" for each command, the HC-05 is now set to serial mode and can communicate with the computer via the COM port.
Code Example
Here's an example of how to send data from the computer to the HC-05 module using the Arduino IDE:
Serial.begin(38400); // Set the baud rate
while (!Serial) {
; // Wait for serial connection
}
Serial.println("Hello, HC-05!"); // Send data to the HC-05