HC04/06 Bluetooth Module Configuration: Setup and Troubleshooting

Written by

in

The HC-04 and HC-06 are popular, low-cost Bluetooth serial modules used to add wireless communication to Arduino projects. Key Differences: HC-04 vs. HC-06

HC-06: Works only as a Slave device. It cannot initiate connections to other Bluetooth modules, but it can accept connections from phones or computers.

HC-04: Often a generic variant or clone of the HC-05/06 series. Depending on the specific firmware version, it may support Master/Slave switching or run strictly as a Slave like the HC-06. Hardware Setup and Wiring

To configure these modules using an Arduino, you must connect them to the board’s serial pins. HC-04/06 Pin Arduino Pin (via SoftwareSerial) VCC Powers the module. GND Common ground. TXD RX (e.g., Pin 10) Module transmits data to Arduino. RXD TX (e.g., Pin 11)

Arduino transmits data to module. Requires a voltage divider.

⚠️ Crucial Voltage Warning: While the module’s VCC pin requires 5V, the RXD data pin operates at 3.3V logic. Sending a 5V signal from an Arduino TX pin can damage the module. Use a simple voltage divider (a 1kΩ and a 2kΩ resistor) between the Arduino TX pin and the HC-05/06 RXD pin to step down the voltage safely. Entering Configuration (AT Mode)

Unlike the HC-05, which requires holding a button to enter AT mode, the HC-06 enters configuration mode automatically whenever it is powered on but not paired to any device.

Look at the onboard LED. If it is flashing rapidly, it is in AT mode and ready for configuration.

Default communication speed (baud rate) for a brand-new HC-06 is typically 9600 or 38400 bps. Configuration Sketch (Code)

Upload this sketch to your Arduino. It creates a bridge between your computer’s Serial Monitor and the Bluetooth module using SoftwareSerial.

#include // Define Arduino pins connected to HC-06 TX and RX SoftwareSerial BTSerial(10, 11; // RX, TX void setup() { Serial.begin(9600); // Communication speed with Computer Serial.println(“Enter AT commands in the Serial Monitor:”); // Set to default module baud rate (usually 9600 or 38400) BTSerial.begin(9600); } void loop() { // Read from HC-06 and send to Computer if (BTSerial.available()) { Serial.write(BTSerial.read()); } // Read from Computer and send to HC-06 if (Serial.available()) { BTSerial.write(Serial.read()); } } Use code with caution. Essential AT Commands

Open your Arduino IDE Serial Monitor. Set the line ending dropdown to “No line ending” or “Both NL & CR” (depending on your specific HC-06 firmware clone; start with “No line ending”). Set the baud rate to 9600. Type these commands and press Enter: Test Communication Command: AT Expected Response: OK Change Bluetooth Name Command: AT+NAMEyourname (e.g., AT+NAMEMyArduino) Expected Response: OKsetname Change Pairing PIN/Password Command: AT+PIN1234 (Sets PIN to 1234) Expected Response: OKsetPIN Change Communication Baud Rate Command: AT+BAUD4 (Sets baud rate to 9600) Command: AT+BAUD8 (Sets baud rate to 115200) Expected Response: OK9600 or OK115200

Note: If you change this, you must change BTSerial.begin() in your code to match. Troubleshooting Tips

No response to AT: Try switching your Serial Monitor line ending settings between “No line ending”, “Warm return”, and “Both NL & CR”.

Garbled text output: The baud rate in your BTSerial.begin() function does not match the module’s internal speed. Try switching between 9600 and 38400.

Cannot find the device on phone: The module cannot be discovered while it is connected to the Arduino Serial Monitor in AT mode if an active configuration command is processing, or if it is already paired with another device nearby. Unplug and replug the module’s power to reset it. To help you get your project running smoothly, tell me:

What specific error or behavior are you experiencing with your module? Which Arduino board (Uno, Nano, Mega) are you using?

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *