Interfacing HC-05 Bluetooth Module With Arduino

by Rachana Jain in Circuits > Arduino

641 Views, 5 Favorites, 0 Comments

Interfacing HC-05 Bluetooth Module With Arduino

20240803_201608.jpg

In this project, we'll learn how to interface an HC-05 Bluetooth Module with an Arduino Uno. We'll establish a communication link between an Android smartphone and the Arduino, using HC-05 for wireless control.


Supplies

  1. Arduino Uno: https://amzn.to/4dtZ7st
  2. HC-05 Bluetooth Module: https://amzn.to/3XQNerK
  3. Breadboard: https://amzn.to/3MSFi2U
  4. Jumper wires: https://amzn.to/47x6G00
  5. 12V Supply Adapter: https://amzn.to/3ztsZHf
  6. 1k and 2k Resistor: https://amzn.to/4exfbKz

HC-05 Bluetooth Module

Slide2.PNG

What is the HC-05 Bluetooth Module?

The HC-05 is a Bluetooth module designed for wireless communication. It can be used in a master or slave configuration, making it versatile for a variety of Bluetooth applications, such as controlling devices remotely via a smartphone.

Specifications of HC-05 Bluetooth Module

  1. Bluetooth Protocol: Bluetooth 2.0 + EDR (Enhanced Data Rate)
  2. Operating Voltage: 3.3V (Internally regulated from 5V)
  3. Range: Up to 10 meters
  4. Communication: UART interface (9600 baud rate by default)
  5. Baud Rates: 9600, 19200, 38400, 57600, 115200, 230400, and 460800

Modes of Operation

The HC-05 can operate in two modes:

  1. Command Mode: Used for configuring the module as Master or Slave.
  2. Data Mode: Used for transmitting and receiving data between devices.

In this project, we'll primarily focus on Data Mode, where the HC-05 will communicate with the Arduino and a smartphone.

Configurations

The HC-05 Bluetooth module can be configured in two main modes, each serving a distinct role in communication: Slave Mode and Master Mode.

Slave Mode: In this mode, the module waits for a connection request from a master device, such as a smartphone, laptop, or another Bluetooth-enabled device.

Key Characteristics:

  1. The HC-05 does not initiate any connection on its own.
  2. It responds to the connection requests sent by a master device.
  3. Suitable for applications where the module simply receives data from or responds to the master device.

Master Mode: The HC-05 takes on the responsibility of initiating connections to other Bluetooth devices.

Key Characteristics:

  1. The module searches for available Bluetooth devices (typically slave devices).
  2. It actively initiates connections, enabling communication with other modules or devices.
  3. Useful in scenarios where the HC-05 needs to control multiple devices or manage connections to slave devices like sensors or other Bluetooth modules.

HC-05 Pinout

The HC-05 has 6 pins:

  1. Enable/Key: It is used to control the module’s power state. 
  2. VCC: Connect to a 5V supply.
  3. GND: Ground.
  4. TXD: Transmit pin, connected to the RX pin of the device it communicates with.
  5. RXD: Receive pin, connected to the TX pin of the device it communicates with.
  6. State: Used to provide status information about the module’s connection state.

Basic Communication of HC-05 With Android Phone

Slide3.PNG

To interface the HC-05 Bluetooth module with the Arduino's limited serial interfaces, we use pins 2 and 3 of the Arduino as custom Rx (receive) and Tx (transmit) pins through software serial communication.

To communicate with the HC-05 without interfering with the USB connection, we reassign pins 2 and 3 for UART communication using the SoftwareSerial library. The Rx pin of the HC-05 module is not 5V tolerant (it operates at 3.3V), so to avoid damaging the module, a voltage divider is needed to step down the Arduino’s 5V signal to a safe 3.3V.

1kΩ and 2kΩ resistor are used to create the voltage divider. The free end of the 1kΩ resistor is connected to pin 3 (Arduino's Tx). The free end of the 2kΩ resistor is connected to GND. The junction of the two resistors (where the 1kΩ and 2kΩ resistors meet) is connected to the Rx pin of the HC-05.

The VCC pin of the HC-05 is connected to the 5V pin of the Arduino. The GND pin of the HC-05 is connected to the GND of the Arduino. Pin 2 of the Arduino is connected directly to the Tx pin of the HC-05.

Arduino Code

Upload the following Arduino sketch to communicate between the HC-05 and your Android phone:

// Include Software Serial Library this library makes DIO pins as Serial Pins
#include <SoftwareSerial.h>
//Create software serial object to communicate with HC-05
SoftwareSerial BTSerial(2, 3); // Now pin 2 and pin 3 of Arduino are Serial Rx & Tx pin Respectively
void setup() {
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
Serial.println("Initializing Bluetooth Module in Data Mode\n");
// Begin the soft Serial port and set the data rate for the SoftwareSerial port at 9600 to communicate with Bluetooth Module in Data Mode
BTSerial.begin(9600);
Serial.print("Bluetooth Module is Successfully Initialized in Data Mode\n");
}
void loop() {
// Get Data From Serial Terminal and Push to HC-05
if (Serial.available()) {
BTSerial.write(Serial.read());
}
// Get Data from HC-05 and push to Serial Monitor
if (BTSerial.available()) {
Serial.write(BTSerial.read());
}
}

The Bluetooth Terminal Application

Download Serial Bluetooth Terminal Application.jpg
Step_12_Now Send Message from Serial Terminal in Arduino IDE.png
Step_13_The message from Arduinio Serial Terminal is shown in Serial Bluetooth Terimal Mobile Application in Green Colour..jpg

1. Install the Bluetooth Terminal Application:

  1. Open the Play Store on your Android device.
  2. Search for "Serial Bluetooth Terminal" app.
  3. Install the app on your phone.

2. Enable Bluetooth on Your Phone:

  1. While the app is downloading, turn on the Bluetooth on your Android phone.
  2. Ensure your HC-05 module is powered up and its LED is blinking, which indicates it is discoverable.

3. Pair the HC-05 with Your Phone:

  1. Go to Bluetooth settings on your phone.
  2. Look for HC-05 under "Available devices." (If it’s not listed, check if the HC-05 is powered and in pairing mode, with the LED blinking).
  3. Select HC-05 from the list of devices.
  4. When prompted, enter the default pairing code: either 1234 or 0000.

4. Connect the HC-05 with Serial Bluetooth Terminal:

  1. Open the Serial Bluetooth Terminal app.
  2. Press the three-line button next to the "Terminal" heading to open the menu.
  3. Select the Devices menu option.
  4. Tap the Refresh button to scan for paired devices.
  5. Once the HC-05 is displayed, tap on its name to connect.
  6. Allow any permissions if prompted by tapping Allow.

5. Start Sending and Receiving Data:

  1. After successfully connecting, the status icon in the app’s top right corner should indicate a connection.
  2. In the app’s terminal window, you can type a message and send it.
  3. The message sent from the app will be transmitted to the HC-05, which will display it on the Arduino Serial Monitor in the Arduino IDE (if properly configured).

6. Test Communication from Arduino to Phone:

  1. Open the Serial Monitor in the Arduino IDE.
  2. Type and send a message from the Arduino Serial Monitor.
  3. The message should be received in the Serial Bluetooth Terminal app on the phone, highlighted in green.

Key Points:

  1. Password: Default passwords for the HC-05 are generally "1234" or "0000."
  2. Serial Monitor Feedback: Messages sent from either the Arduino IDE or the mobile app should reflect in both devices' terminals, confirming two-way communication.
  3. LED Status: The LED on the HC-05 will blink rapidly while in pairing mode, but once connected, it will blink more slowly or remain solid.

Conclusion

In this tutorial, we’ve explored how to set up and use the HC-05 Bluetooth module with Arduino, allowing for seamless wireless communication between your projects and external devices.

To learn more about HC-05 module in detail and how to control a 12V DC Fan Speed and Direction from Android Application using HC-05 check out: HC-05 Bluetooth Module Interfacing with Arduino