The HC-05 and HC-06 Bluetooth modules have become one of the most widely used solutions for providing wireless connectivity to Arduino projects. Thanks to their versatility y affordable priceThese devices allow wireless communication with computers, smartphones and other Bluetooth-enabled devices.
If you are looking to integrate these modules into your projects, it is essential to know their differences, its configuration method and how to properly connect them to Arduino. In this article, we'll explore in detail everything you need to get the most out of them.
What are the HC-05 and HC-06 Bluetooth modules?
The HC-05 and HC-06 Bluetooth modules They are small electronic devices that allow the wireless communication via the Bluetooth 2.0 protocol. They are widely used in projects robotics, domótica and other microcontroller-based systems.
Both modules offer similar functionalities, but have a key difference:
- HC-06: It only works in slave mode, which means it cannot initiate a connection, only respond to requests from master devices.
- HC-05: It can operate in master mode o slave mode, allowing you to both initiate and receive Bluetooth connections.
Technical characteristics
- Operating voltage: 3.3V - 5V.
- Transmission frequency: 2.45 GHz.
- communication speed: Configurable between 1200 and 1382400 baud.
- Reach distance: Approximately 10 meters without obstacles.
- Compatible with standard Bluetooth devices (PC, mobile phones, etc.).
Differences between HC-05 and HC-06
Although both modules look similar, they present important functional differences:
Feature | HC-05 | HC-06 |
---|---|---|
Operation mode | Master and slave | Only slave |
Configuration | More options using AT commands | limited options |
Settings button | Yes | No |
Connecting the Bluetooth module to Arduino
To use these modules with Arduino, it is essential to perform the correct connection of the pins:
- VCC: Connects to 5V in most cases. Some models operate on 3.3V only.
- GND: Connects to GND on Arduino.
- TX: Connects to the Arduino RX pin.
- RX: Connects to the TX pin of Arduino. In some cases, it is recommended to place a voltage divider to prevent damage from voltage levels.
How to configure the Bluetooth module with AT commands
To modify parameters such as the module name, password and Transmission speed, we must use the AT commandsThe procedure varies depending on the module:
AT mode in HC-06
The HC-06 automatically enters AT mode when it is not paired with another device. Once connected to the Arduino, we can send commands from the serial monitor.
AT mode in HC-05
The HC-05 requires you to hold down its integrated button when powering up the module to enter AT mode. In this state, the LED flashes slowly instead of quickly.
Most used AT commands
- AT: Check if the module is responding.
- AT+NAME=name: Changes the visible name of the module.
- AT+PSWD=key: : Change the pairing key (default is 1234).
- AT+UART=9600,0,0: Set the transmission speed.
- AT+ROLE=0: Configures the module as a slave (HC-05 only).
- AT+ROLE=1: Sets the module as master (HC-05 only).
Code example for Arduino
This basic code allows you to receive and send data between Arduino and a Bluetooth device.
#include SoftwareSerialBT(10, 11); // RX, TX void setup() { Serial.begin(9600); BT.begin(9600); } void loop() { if (BT.available()) { Serial.write(BT.read()); } if (Serial.available()) { BT.write(Serial.read()); } }
With this code, any data sent from a mobile phone or PC will reach the Arduino and be displayed on the serial monitor. Similarly, any data entered on the serial monitor will be sent to the Bluetooth device.
Communication tests with PC and smartphone
To verify that the module is working correctly, we can pair it with a PC or smartphone. On Windows, we can use programs , the Hyperterminal o PuTTY, while on Android there are applications like BlueTerm that allow communication via Bluetooth.
Configuring the module as Master or Slave
If we use an HC-05 and we want it to automatically pair with another Bluetooth module, we must set it to mode TeacherTo do this, we can use these commands:
- AT+ROLE=1 → Activate Master mode.
- AT+CMODE=0 → Set up connection with a specific device.
- AT+BIND=xx:xx:xx:xx:xx:xx → Specifies the address of the slave device.
On the other hand, a slave module (HC-06 or HC-05 in slave mode) simply waits for the connection from a teacher.
This article covers in detail all the necessary aspects for using and configuring the HC-05 and HC-06 Bluetooth modules with Arduino. From their technical differences to how to establish communication with other devices, understand these characteristics will allow you to take advantage of all the capabilities of these modules in different electronic projects.