Free Shipping for orders over ₹1999

support@thinkrobotics.com | +91 93183 94903

Bluetooth Module HC-05 with Arduino: A Comprehensive Guide

Bluetooth Module HC-05 with Arduino: A Comprehensive Guide



The Bluetooth module HC-05 is a widely used wireless communication device that enables seamless data exchange between devices. When integrated with Arduino, it unlocks the potential for various applications, from home automation to wireless data logging. If you're new to using the Bluetooth module HC-05 with Arduino, this guide will walk you through the essentials, from hardware connections to practical examples.

What is the HC-05 Bluetooth Module?

The HC-05 is a Bluetooth Serial Port Protocol (SPP) module designed for wireless communication. It operates using Bluetooth version 2.0 and can act as either a master or a slave device. Its simplicity and reliability make it a favorite among DIY enthusiasts and professionals for projects requiring wireless control or communication.

Key Features

  • Operating Voltage: 3.6V–6V
  • Communication Range: Up to 10 meters
  • Baud Rate: Default 9600 bps
  • Modes: Master and Slave
  • Simple AT commands for configuration

With its ease of use and compatibility, the Bluetooth module HC-05 with Arduino is perfect for creating wireless solutions.

Applications of Bluetooth Module HC-05 with Arduino

Using the HC-05 with Arduino opens doors to various innovative projects, including:

  1. Wireless Home Automation: Control appliances via Bluetooth.
  2. Remote-Controlled Robots: Build a robot that can be operated from your smartphone.
  3. Wireless Data Logging: Monitor and record sensor data remotely.
  4. Bluetooth Communication Devices: Create devices like Bluetooth-enabled keyboards or controllers.

By integrating the Bluetooth module HC-05 with Arduino, you can transform simple projects into versatile, wireless-enabled solutions.

Getting Started: Required Components

To use the Bluetooth module HC-05 with Arduino, gather the following items:

  1. HC-05 Bluetooth module
  2. Arduino board (e.g., Uno, Nano, or Mega)
  3. Jumper wires
  4. Breadboard
  5. Computer with Arduino IDE installed
  6. Smartphone or Bluetooth-enabled device

Step-by-Step Guide to Using Bluetooth Module HC-05 with Arduino

1. Understanding the HC-05 Pinout

The HC-05 module has six pins, but only the following four are commonly used:

  • VCC: Power supply (3.6V–6V)
  • GND: Ground connection
  • TXD: Transmit data to Arduino
  • RXD: Receive data from Arduino

2. Circuit Connections

To connect the HC-05 to the Arduino, follow these steps:

  1. Connect the VCC pin of the HC-05 to the Arduino’s 5V pin.
  2. Connect the GND pin of the HC-05 to the Arduino’s GND.
  3. Connect the TXD pin of the HC-05 to the RX pin of the Arduino (digital pin 0).
  4. Connect the RXD pin of the HC-05 to the TX pin of the Arduino (digital pin 1).

Note: Use a voltage divider or resistor to avoid damaging the HC-05 module if the Arduino transmits at 5V logic levels.

3. Writing the Code

Below is a simple example demonstrating how to send and receive data between the Bluetooth module HC-05 with Arduino and a smartphone.

cpp

Copy code

#include <SoftwareSerial.h>


// Initialize SoftwareSerial on pins 10 (RX) and 11 (TX)

SoftwareSerial BTSerial(10, 11);


void setup() {

  Serial.begin(9600);    // Communication with PC

  BTSerial.begin(9600);  // Communication with HC-05

  Serial.println("HC-05 is ready");

}


void loop() {

  // If data is received from the HC-05

  if (BTSerial.available()) {

    char data = BTSerial.read();

    Serial.print("Received: ");

    Serial.println(data);

  }


  // If data is sent from the Serial Monitor

  if (Serial.available()) {

    char data = Serial.read();

    BTSerial.write(data);

    Serial.print("Sent: ");

    Serial.println(data);

  }

}


4. Uploading the Code

  • Connect the Arduino to your computer via USB cable.
  • Open the Arduino IDE and upload the code.
  • Ensure the correct board and port are selected in the Tools menu.

Once the code is uploaded, your HC-05 is ready to communicate wirelessly.

5. Pairing the HC-05 with a Device

  1. Power up your Arduino and HC-05 module.
  2. On your smartphone or Bluetooth-enabled device, search for available Bluetooth devices.
  3. Select "HC-05" and pair it using the default PIN (1234 or 0000).
  4. Use a Bluetooth terminal app (e.g., Serial Bluetooth Terminal) to send and receive data.

Using AT Commands to Configure the HC-05

The HC-05 can be customized using AT commands, allowing you to change the baud rate, device name, mode, and more. To enter AT mode:

  1. Connect the HC-05 to Arduino.
  2. Hold the “KEY” pin (if available) or use a manual method to enable AT mode.
  3. Use the following code to enter AT mode:

cpp

Copy code

#include <SoftwareSerial.h>


SoftwareSerial BTSerial(10, 11);


void setup() {

  Serial.begin(9600);

  BTSerial.begin(38400);  // Default AT mode baud rate

  Serial.println("Enter AT commands:");

}


void loop() {

  if (Serial.available()) {

    BTSerial.write(Serial.read());

  }

  if (BTSerial.available()) {

    Serial.write(BTSerial.read());

  }

}


Use the Serial Monitor to send commands like:

  • AT+NAME=MyBluetooth: Changes the name of the device.
  • AT+ROLE=1: Sets the device to master mode.
  • AT+BAUD4: Sets the baud rate to 9600.

Tips for Success

  1. Check Connections: Double-check wiring to avoid issues with data transmission.
  2. Use a Resistor Divider: Protect the RXD pin of the HC-05 from high voltage.
  3. Optimize Range: Ensure there are no obstructions between devices for better communication.
  4. Start with Simple Data: Test with basic data exchange before building complex projects.

Practical Applications of Bluetooth Module HC-05 with Arduino

Once you’ve mastered working with the Bluetooth module HC-05 with Arduino, explore these practical applications:

  1. Bluetooth-Controlled Car: Control an Arduino-powered car using your smartphone.
  2. Wireless LED Control: Toggle LEDs wirelessly through Bluetooth.
  3. Smart Home Systems: Enable Bluetooth communication for home appliances.
  4. Sensor Data Transmission: Wirelessly send sensor readings to your phone.

Conclusion

The Bluetooth module HC-05 with Arduino is an excellent choice for adding wireless communication to your projects. With straightforward connections and simple coding, it’s perfect for beginners and advanced users alike. From robotics to smart home systems, the possibilities are endless.

Start exploring today, and let your creativity drive you to build innovative wireless solutions!

Frequently Asked Questions

  1. Can the HC-05 module connect to multiple devices simultaneously?

    No, the HC-05 module supports one-to-one communication and cannot connect to multiple devices simultaneously.

  2. How can I change the default name of the HC-05 module?

    You can change the default name using AT commands. For example, send AT+NAME=NewName in AT mode to set a new name.

  3. What is the difference between HC-05 and HC-06 modules?

    The HC-05 can operate in both master and slave modes, while the HC-06 functions only as a slave.

  4. Why is my HC-05 module not pairing with my device?

    Ensure the module is powered correctly, set to pairing mode, and within range. Use the default PIN (1234 or 0000) for pairing.

  5. Is the HC-05 module compatible with all Arduino boards?

    Yes, the HC-05 works with most Arduino boards, including Uno, Mega, Nano, and others, as long as they have UART or software serial communication capability.

Post a comment