HC-04 vs HC-06: Configuration Differences and SetupThis article compares the HC-04 and HC-06 Bluetooth serial modules, explains their hardware and firmware differences, and provides step-by-step setup and configuration instructions, including AT command examples, wiring, troubleshooting, and practical use cases.
Overview: what these modules are
Both HC-04 and HC-06 are low-cost Bluetooth SPP (Serial Port Profile) modules commonly used to add wireless serial communication to microcontrollers (Arduino, ESP8266/ESP32, STM32), sensors, and DIY projects. They typically expose UART (TX, RX) pins and operate at 3.3–5V logic levels depending on the board variant. Despite similar appearances, they differ in role, AT-command support, and configuration flexibility.
Key quick facts
- HC-04: often a configurable master/slave module (varies by firmware).
- HC-06: typically a slave-only module with more limited AT command set.
Hardware differences
Physical modules for HC-04 and HC-06 often look nearly identical: small breakout boards with a 4-pin header (VCC, GND, TXD, RXD), an LED indicator, and sometimes state and key pins. Differences are mostly firmware-based, but some board variants include a KEY or EN pin used to enter command mode or control role.
- Power: commonly 3.3–6V on breakout; many boards include an onboard regulator permitting 5V supply.
- Logic levels: the Bluetooth IC itself runs at 3.3V; some breakout boards include resistors or level shifting for 5V MCU compatibility.
- Pins:
- VCC, GND, TXD, RXD — standard.
- KEY/EN — used on some modules to force AT-command mode or switch role.
- STATE/LED — indicates pairing/connection status.
Firmware & role differences
HC-06
- Typically a slave-only device (cannot initiate connections).
- AT command set is limited but sufficient to change baud rate, name, and PIN.
- Often easier for simple applications where the microcontroller acts as the master (e.g., smartphone or PC connecting to the module).
HC-04
- In many releases HC-04 can be configured as master or slave (depends on manufacturer firmware).
- May support a broader AT command set, allowing scanning for devices, pairing as master, and extended configuration.
- Because there is variation between manufacturers, always check module labeling or test AT commands to confirm capabilities.
Common use cases
- Wireless serial link between a microcontroller and a smartphone/tablet/PC.
- Remote sensor data logging.
- Wireless control of robots, RC vehicles, or home automation devices.
- Replacing wired serial cables for convenience during development.
Wiring and basic connection
Typical 4-pin wiring:
- VCC -> 5V (or 3.3V depending on board; check label)
- GND -> GND
- TXD -> RX of microcontroller (use level shifting if MCU is 5V and module needs 3.3V)
- RXD -> TX of microcontroller (use voltage divider or level shifter)
Important: Many HC-0x modules’ TX pins output 3.3V logic and are safe for 5V microcontrollers’ RX. However, the module’s RX pin often requires 3.3V levels — use a voltage divider or level shifter if driving it from a 5V MCU.
Example Arduino UNO wiring:
- HC-0x VCC -> 5V (if board has regulator) or 3.3V (if not)
- GND -> GND
- TXD -> Arduino digital pin 10 (SoftwareSerial RX)
- RXD -> Arduino digital pin 11 (SoftwareSerial TX) via divider
Entering AT command mode
AT commands configure the module (name, baud rate, PIN, role). Methods to enter AT mode vary:
HC-06
- Usually enters AT mode only when not paired and before establishing a connection.
- Some modules require a specific baud rate (commonly 38400) and commands must be sent without line endings or with CR+LF depending on firmware.
- Typical behavior: power module, do not pair from phone, open serial terminal at module default baud, send “AT” — expect “OK”.
HC-04
- Often includes KEY or EN pin: hold KEY HIGH (to VCC) while powering on to enter AT mode.
- If no KEY pin, some HC-04 variants enter AT mode at a specific baud or require no connection/pairing.
- Many HC-04 variants require CR+LF line endings and use 38400 baud for AT mode.
Because there are many clones, if AT mode does not respond, try alternate baud rates (9600, 19200, 38400, 57600) and different line ending settings.
Common AT commands and examples
Note: exact commands and formats vary by firmware. Commands below cover typical variants.
-
Test communication:
- Send: AT
- Response: OK
-
Get version:
- AT+VERSION? or AT+VERSION
- Response: firmware version string
-
Set/get name:
- Get: AT+NAME? or AT+NAME
- Set: AT+NAMEnewname or AT+NAME=newname
- Example: AT+NAMEMyBTModule
-
Set/get baud rate:
- Get: AT+BAUD? or AT+BAUD
- Set: AT+BAUD4 (example mapping differs by module)
- Common mapping (module-dependent):
- AT+BAUD1 = 1200
- AT+BAUD2 = 2400
- AT+BAUD3 = 4800
- AT+BAUD4 = 9600
- AT+BAUD5 = 19200
- AT+BAUD6 = 38400
- AT+BAUD7 = 57600
- AT+BAUD8 = 115200
-
Set PIN:
- AT+PIN1234 or AT+PIN=1234
-
Set role (HC-04 variants):
- AT+ROLE=0 (slave) or AT+ROLE=1 (master) — exact syntax may vary.
-
Restore factory:
- AT+RESET or AT+ORGL
Examples (typical sequence):
- Power module with KEY high (HC-04) or ensure unpaired (HC-06).
- Open serial terminal at default baud (commonly 38400 or 9600).
- Type AT — expect OK.
- AT+NAMERoboCar — expect OKsetname or similar.
- AT+PIN0000 — sets PIN to 0000.
- AT+BAUD4 — sets baud to 9600.
Example: configuring HC-06 from Arduino Serial Monitor
- Wire HC-06 TX -> Arduino RX (pin 0), HC-06 RX -> Arduino TX (pin 1) via divider if required; power module.
- Open Arduino IDE Serial Monitor.
- Set “Both NL & CR” line ending and choose 38400 (or module default).
- Send AT — reply should be OK.
- Send AT+NAME=MyModule — reply OKsetname.
- Send AT+PIN=1234 — reply OKsetPIN.
- If changing baud, set via AT+BAUDn, then restart module and change Serial Monitor speed to new baud.
Note: using hardware Serial pins conflicts with USB connection — many prefer SoftwareSerial on different pins.
Troubleshooting
-
No response to AT:
- Try different baud rates (9600, 19200, 38400, 57600).
- Ensure module is not paired/connected.
- Use KEY/EN pin high while powering for HC-04 variants.
- Check wiring and ground commonality.
- Ensure correct line endings (CR, LF, or both) per firmware.
-
Can’t pair with phone:
- Confirm PIN (common defaults: 1234 or 0000).
- Ensure module is in slave/discoverable mode.
- Check LED blink rate (fast blinking = not connected; slow = connected on many modules).
-
Garbage characters on serial:
- Baud mismatch between MCU and module. Match both sides.
- Voltage level issues — ensure RX line to module is 3.3V-tolerant.
-
Module resets or unstable:
- Power supply insufficient — use stable 5V/3.3V with enough current (50–100mA peak).
- Bad clone module — try with another board.
Security and limitations
- These modules implement legacy Bluetooth SPP (Bluetooth 2.0/2.1) — not BLE. They are simple and widely supported but lack modern BLE security and features.
- Default PINs are weak (⁄0000). For sensitive uses, change PIN and pair only with trusted devices.
- Range is typically 10 meters (class 2), but varies by antenna and environment.
Practical project ideas
- Wireless serial console for an Arduino robot.
- Bluetooth remote control app for home automation.
- Serial-to-Bluetooth data logger sending sensor readings to a phone.
- Replacing expensive proprietary modules for hobbyist projects.
Quick configuration checklist
- Identify module type (HC-04 may be master-capable; HC-06 usually slave-only).
- Check for KEY/EN pin and module default baud.
- Use level shifting for MCU TX -> module RX if MCU uses 5V.
- Enter AT mode (KEY high or unpaired) and probe with common baud rates.
- Change name, PIN, baud, and role as needed; reboot after settings that require it.
Conclusion
HC-04 and HC-06 are affordable and useful for adding wireless serial to embedded projects. The HC-06 is simpler and generally slave-only with a restricted AT command set; the HC-04 often offers more flexibility (master role and extra commands) but varies by vendor. Knowing wiring, how to enter AT mode, and common AT commands will let you configure either module for most hobbyist applications.
If you want, specify your exact module markings or post the module’s default responses and I’ll give precise AT commands and steps for that unit.
Leave a Reply