Bluetooth Module HC-05

Topics Covered

Overview

The Bluetooth module HC-05 is a compact and cost-effective wireless communication module commonly used for establishing Bluetooth connections between electronic devices. It operates in the 2.4GHz ISM frequency band and supports Bluetooth 2.0+ EDR (Enhanced Data Rate) protocol. With its easy-to-use serial interface, it can be integrated into various microcontroller projects. The HC-05 module offers both Master and Slave modes, enabling it to act as a central controller or peripheral device in a Bluetooth network. Its versatility, low power consumption, and wide compatibility make it a popular choice for hobbyists and engineers in building wireless applications and IoT devices.

HC-05 Bluetooth Module

HC-05 Bluetooth Module

The HC-05 Bluetooth module is a versatile and widely used wireless communication module that enables easy and efficient Bluetooth connectivity between electronic devices. It has gained popularity in the electronics and maker communities for its simplicity, cost-effectiveness, and compatibility with a wide range of microcontrollers and platforms.

Key Features:

  • Bluetooth Version: Operates on the Bluetooth 2.0+EDR (Enhanced Data Rate) protocol.
  • Operating Frequency: Utilizes the 2.4GHz ISM (Industrial, Scientific, and Medical) frequency band.
  • Serial Interface: Communicates with microcontrollers and devices through a simple UART interface.
  • Master and Slave Modes: Supports both Master and Slave roles, allowing it to initiate or accept connections.
  • AT Commands: Configurable using AT commands for various settings such as device name and pairing code.
  • Low Power Consumption: Designed for energy efficiency, suitable for battery-powered applications.
  • Range: Provides reliable communication within a typical range of up to 10 meters (approximately 33 feet).
  • Compatibility: Compatible with a wide range of microcontrollers, including Arduino and Raspberry Pi.
  • Data Rate: Supports data transfer rates up to 2.1 Mbps in EDR mode.
  • LED Indicators: Often equipped with LEDs for power and status indication, aiding in troubleshooting and diagnostics.

HC-05 Bluetooth Module Pins

HC-05 Bluetooth Module Pins

Here's an overview of the HC-05 module pins and their functions:

  • VCC (Voltage Supply): This pin requires a supply voltage of 3.6V to 6V DC. It powers the HC-05 module. Be cautious not to exceed the specified voltage range to avoid damaging the module.
  • GND (Ground): This is the ground connection, providing the reference voltage for the module. It should be connected to the ground (0V) of your power supply or microcontroller.
  • TXD (Transmit Data): The TXD pin is used to transmit data from the HC-05 module to an external device like a microcontroller. You connect this pin to the RX (receive) pin of the device that will receive data from the HC-05.
  • RXD (Receive Data): The RXD pin is used to receive data from an external device into the HC-05 module. You connect this pin to the TX (transmit) pin of the device that will send data to the HC-05.
  • STATE (Status): The STATE pin provides information about the current state of the HC-05 module. It is often used to check if the module is in a discoverable or connected state. When not used, this pin can be left unconnected.
  • EN (Enable/Key): The EN pin, sometimes labelled KEY, is used to set the module in either AT (command) mode or communication mode. By applying a high or low signal to this pin, you can switch between these modes. In AT mode, you can configure the module using AT commands sent over the TXD and RXD pins.
  • LED Indicator Pins: HC-05 modules often have two LEDs, one for power (PWR) and one for status (LED). These LEDs provide visual feedback about the module's operation. The PWR LED typically lights up when the module is powered, while the LED indicator may blink or change colours to indicate different states like pairing or data transmission.
  • 34-Pin Header (Optional): Some HC-05 modules come with an additional 34-pin header. This header provides access to other pins and features of the module, such as the PIO (General Purpose Input/Output) pins, which can be used for various purposes like button inputs or status monitoring.

Specification of HC-05 Bluetooth Module

  • Bluetooth Version: Bluetooth 2.0+EDR (Enhanced Data Rate) protocol support.
  • Operating Frequency: Operates in the 2.4GHz ISM (Industrial, Scientific, and Medical) frequency band.
  • Communication Range: Typically has a range of up to 10 meters (approximately 33 feet) under ideal conditions.
  • Serial Interface: Uses a straightforward UART (Universal Asynchronous Receiver-Transmitter) communication interface.
  • Operating Voltage: Requires a voltage supply in the range of 3.6V to 6V DC.
  • Power Consumption: Designed for low power consumption, featuring sleep modes to conserve energy.
  • Master and Slave Modes: Supports both Master and Slave roles for versatile Bluetooth network configurations.
  • AT Commands: Configurable via AT commands to customize settings such as device name and pairing code.
  • Data Rate: Supports data transfer rates of up to 2.1 Mbps in EDR (Enhanced Data Rate) mode.
  • Compatibility: Compatible with a wide range of microcontrollers, including Arduino, Raspberry Pi, and more.
  • LED Indicators: Often equipped with LEDs for power and status indication, facilitating troubleshooting.
  • Applications: Suitable for a variety of applications, including IoT devices, robotics, home automation, and remote control systems.

Modes of Operation

Command Mode

  • Purpose: Command Mode, also known as AT Command Mode, is primarily used for configuring the HC-05 module's settings and parameters. In this mode, the module listens for AT commands sent via the serial interface (TXD and RXD pins) and responds accordingly.
  • Activation: To enter Command Mode, you typically need to set the EN (Enable/Key) pin to a specific state, often by connecting it to either a high or low voltage level. The exact method may vary depending on your module's specific configuration.
  • AT Commands: Users send AT commands to the module to perform actions like changing the device name, setting the pairing PIN, adjusting the baud rate, and more. For example, sending AT+NAME=MyDevice changes the Bluetooth device name to MyDevice.
  • Configuration: In Command Mode, you can customize various parameters to suit your project's requirements, making it a versatile mode for tailoring the module's behaviour.

Data Mode

  • Purpose: Data Mode, also known as Communication Mode, is the operational mode where the HC-05 module establishes Bluetooth connections with other devices and facilitates the exchange of data. In this mode, the module acts as a bridge for wireless communication between devices.
  • Activation: After configuring the module's settings in Command Mode, you typically exit Command Mode to allow the module to enter Data Mode automatically. In Data Mode, the module actively seeks and establishes Bluetooth connections with paired devices.
  • Data Transfer: In Data Mode, the module handles the actual data transmission between the connected devices. For example, it can transmit sensor data from a microcontroller to a smartphone or receive control commands from a mobile app to control a robotic device.
  • Master and Slave Roles: Depending on your application, the HC-05 module can operate in Master or Slave mode in Data Mode. In Master mode, it initiates connections with other Bluetooth devices, while in Slave mode, it accepts incoming connections.

Programming HC-05 with Microcontroller

  • Connections: Connect HC-05 TX to microcontroller RX, and HC-05 RX to microcontroller TX. Provide VCC and GND connections.
  • Power Supply: Ensure a 3.6V to 6V power supply for the HC-05 within its specified range.
  • Enable/Key Pin: Activate HC-05's Command Mode by setting the EN pin to a specific state (consult documentation).
  • Serial Communication: Initialize microcontroller serial communication at the correct baud rate (e.g., 9600 bps).
  • Enter Command Mode: Send "AT" command to HC-05. An "OK" response confirms entry into Command Mode.
  • Configuration: Use AT commands to customize settings, e.g., AT+NAME=my_device for the device name.
  • Exit Command Mode: Exit Command Mode by resetting or power cycling the HC-05; it will auto-switch to Data Mode.
  • Data Communication: In Data Mode, send/receive data through the HC-05 via UART interface.
  • Pairing and Communication: Establish pairing between HC-05 and Bluetooth device for wireless data exchange.

Android App Interfacing with HC-05

  • Android App Development: Develop an Android app using Java or Kotlin, serving as the interface to control or exchange data with the HC-05 module.
  • Bluetooth Permissions: Request necessary Bluetooth permissions in the AndroidManifest.xml file to enable Bluetooth communication, including Bluetooth and Bluetooth Admin permissions.
  • BluetoothAdapter: Create a BluetoothAdapter instance to manage the device's Bluetooth functionality. Use it to enable Bluetooth if it's not already on.
  • Discover and Pair Devices: Use the BluetoothAdapter to discover nearby devices, including HC-05. Filter the list based on the device name or address. Initiate pairing between your Android device and HC-05 by sending a pairing request.
  • Establish Connection: After pairing, establish a BluetoothSocket connection between your app and HC-05. The socket is the communication channel.
  • Data Transmission: Implement logic in your app to send/receive data via the BluetoothSocket, facilitating control commands, sensor data reception, or other interactions.
  • User Interface (UI): Design a user-friendly interface to control or display HC-05-related information.
  • Error Handling: Implement error handling to manage connection issues.
  • Testing and Deployment: Test the app and HC-05 interface, debug any issues, and deploy the app to your Android device and other relevant devices.

Alternate Options for HC-05 Bluetooth Module

There are several alternative Bluetooth modules to the HC-05, each with its own set of features and capabilities.

Here are some popular options:

  • HC-06: Similar to the HC-05, the HC-06 is a cost-effective Bluetooth module widely used for wireless communication. It primarily operates in Slave mode and is often used in applications where a simple Bluetooth connection is required.
  • HC-08: The HC-08 is a low-energy Bluetooth module, also known as Bluetooth Low Energy (BLE) module. It's suitable for power-efficient applications like wearable devices, sensor networks, and IoT projects.
  • HC-12: The HC-12 is a long-range wireless serial module that operates in the 433MHz frequency band. It's designed for applications that require communication over longer distances, making it suitable for remote control and telemetry systems.
  • nRF24L01: This is a popular 2.4GHz wireless transceiver module that offers reliable communication in a variety of applications. While it's not Bluetooth, it's often used for wireless communication in Arduino-based projects.
  • RN42: The RN42 is a Bluetooth module with a focus on Bluetooth Classic (BR/EDR) and is known for its ease of use and compatibility. It's often used in applications where Bluetooth 2.1 features are needed.
  • BLE Modules (e.g., HM-10): Various Bluetooth Low Energy (BLE) modules, like the HM-10, are available. These are ideal for low-power applications, such as wearable devices and IoT sensors, that require energy-efficient Bluetooth communication.

HC-05 Bluetooth Module interface with Arduino

HC-05 Bluetooth Module interface with Arduino

To interface the HC-05 Bluetooth module with an Arduino and write code for it, follow these steps:

Hardware Setup:

  • Connect HC-05 to Arduino: Wire the HC-05 module to your Arduino. Typically, connect the TXD (Transmit Data) pin of the HC-05 to the RX (Receive) pin of the Arduino (e.g., pin 0), and the RXD (Receive Data) pin of the HC-05 to the TX (Transmit) pin of the Arduino (e.g., pin 1). Connect the VCC (Voltage at the Common Collector) and GND (Ground) pins of the HC-05 to a 5V power supply and ground, respectively.
  • Power Supply: Ensure that the HC-05 module receives a suitable power supply voltage within the specified range.

HC-05 Bluetooth Module Code for Arduino

Here's a simple example of Arduino code to communicate with the HC-05 module and receive data from a paired Bluetooth device:

Conclusion

  • Hardware Connection: Ensure proper hardware connection between the HC-05 module and Arduino, connecting TX and RX pins appropriately.
  • Power Supply: Provide a suitable voltage supply to the HC-05 module within its specified operating range.
  • Arduino Code: Use the SoftwareSerial library to establish a software serial communication between the Arduino and HC-05 module.
  • Serial Communication: Initialize serial communication for debugging (Serial) and Bluetooth (BTSerial) with the desired baud rate (e.g., 9600).
  • Data Transmission: You can also send data to the Bluetooth device using BTSerial.write() when needed.
  • Pairing: Ensure your Android or other Bluetooth device is paired with the HC-05 module before testing the code.