IOT

How To Interface HC-05 Bluetooth Module With Arduino Uno?

One of the best examples of wireless connectivity is Bluetooth. It has a wide range of applications. Bluetooth uses a very small amount of power. Are you familiar with the concept of a smartphone-controlled robot or car? In most Smartphone operated robots, one of these two wireless technologies is used. The first is WIFI, and the second is Bluetooth. Another widely utilized wireless method for operating robot cars is a radio frequency (RF). 

Here we are going to interface a Bluetooth Module (HC-05) with Arduino Uno. Then we control the built-in LED of Arduino Uno from a smartphone via Bluetooth.

HC-05 Module 

HC-05 is based on Bluetooth SPP (Serial Port Protocol) module designed as Wireless Serial Communication that allows use with any microcontroller.  It supports the UART protocol for easy transfer and receives data wirelessly. This module is the most demanding and popular due to its low cost and extremely high features.

This module works as both Master and Slave Mode and easy switchable between these two modes. By default, Slave mode is configured. And the configured Modes changed using AT Commands. While working in slave mode, HC-05 cannot initiate a connection to another Bluetooth device but can accept connections. Whereas in Master mode, it initiates a connection to other devices.

This serial port Bluetooth module features fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate) 3Mbps Modulation with a complete 2.4GHz radio transceiver and baseband. Moreover, It supports CSR Bluecore 04‐External single-chip Bluetooth system with CMOS technology and with AFH (Adaptive Frequency Hopping Feature). The HC-05 is a 6 pin wireless serial communication device that is capable to add two-way (full-duplex) wireless functionality to our projects.

 The module communicates using the USART protocol at a baud rate of 9600. Hence it is easy to interface with any microcontroller that supports USART. The onboard LED present on the board indicates the connection status, whether the Bluetooth is connected or not. This red LED blinks continuously in a periodic manner before connecting to the module. When connected to any other Bluetooth device, its blinking slows down to two seconds.

Features of HC-05 Module 

  • Bluetooth serial port Profile
  • Bluetooth protocol: Bluetooth Specification v2.0+EDR
  • Frequency: 2.4GHz ISM band
  • Operating Voltage: 4V to 6V (Typically +5V)
  • Operating Current: 30mA
  • Modulation: GFSK(Gaussian Frequency Shift Keying)
  • Emission power: ≤4dBm, Class 2
  • Sensitivity: ≤-84dBm at 0.1% BER
  • Speed: Asynchronous: 2.1Mbps(Max) / 160 kbps, Synchronous: 1Mbps/1Mbps
  • Working temperature: -20 ~ +75Centigrade
  • Serial Bluetooth module for Arduino and other microcontrollers
  • Range: <100m
  • Works with Serial communication (USART) and TTL compatible
  • Follows IEEE 802.15.1 standardized protocol
  • Uses Frequency-Hopping Spread Spectrum (FHSS)
  • Can operate in Master, Slave, or Master/Slave mode
  • Can be easily interfaced with Laptops or Mobile phones with Bluetooth
  • Supported baud rate: 9600,19200,38400,57600,115200,230400,460800.
  • Dimension: 26.9mm x 13mm x 2.2 mm

Pinout of HC-05

  • EN: Pin for using the Bluetooth in command mode by setting the baud rate to 38400 and giving this pin a HIGH state. By default, the module is in the data model, so this pin has a LOW state
  • VCC: Pin for giving supply to the Bluetooth module that is 5 or 3.3 volts
  • GND: used to ground the Bluetooth module
  • TXD: Pin used for transferring the data through Serial communication on the serial monitor of Arduino IDE
  • RXD: Pin used for receiving the data through serial communication
  • State: To check whether the module is connected or not this pin is mainly used

Components Required

  • Arduino Uno
  • HC-05 Bluetooth Module
  • LED
  • Jumper Wires
  • Bread Board

Software Required

Interfacing Diagram

Interfacing HC-05 Bluetooth Module With Arduino Uno

Connection

  • RXD pin of HC-05 Bluetooth – TXD pin of Arduino Uno
  • TXD pin of HC-05 Bluetooth – RXD pin of Arduino Uno
  • GND pin of HC-05 Bluetooth – GND pin of Arduino Uno
  • VCC pin of HC-05 Bluetooth – 5V output pin of Arduino Uno
  • Positive pin of LED – Pin 13 of Arduino Uno
  • Negative pin of LED – GND pin of Arduino Uno

Now that you’ve made the connection, we need to write code for the HC-05 to enable communication between the Arduino and the HC-05. Since the HC-05 utilizes UART, we’ll need to write UART code or use the built-in libraries to make things easier

Arduino Bluetooth Controller

Hope you installed this app from Google Play Store. This app will act as a Bluetooth remote controller for Arduino. It is very easy to use this app. Open the app and connect to the HC-05 device. Then select the option as switch mode. Now you can control the LED using the app.

Program

char data = 0;           //Variable for storing received data
 
void setup() 
{
    Serial.begin(9600);  //Sets the data rate in bits per second (baud) for serial data transmission
    pinMode(13, OUTPUT); //Sets digital pin 13 as output pin
}
 
void loop()
{
    if(Serial.available() > 0)       // Send data only when you receive data:
    {
        data = Serial.read();        //Read the incoming data and store it into variable data
        Serial.print(data);          //Print Value inside data in Serial monitor
        Serial.print(“\n”);          //New line 
        if(data == ‘1’)              //Checks whether value of data is equal to 1 
            digitalWrite(13, HIGH);  //If value is 1 then LED turns ON
        else if(data == ‘0’)         //Checks whether value of data is equal to 0
            digitalWrite(13, LOW);   //If value is 0 then LED turns OFF
    }                            
}

Description

  • Initialize the serial port (UART) with the default baudrate of the HC-05 Bluetooth module.
  • Initialize pin 13 as the output pin.
  • In loop() we keep checking if any data is available to read from the serial port.
  • If data is available to read, store it in the variable named “data”.
  • If the data read is ‘1’ then the LED is turned ON, else LED will be turned OFF.

Applications

  • Wireless communication between two microcontrollers
  • Communicate with laptops, desktops, and mobile phones
  • Data Logging application
  • Consumer applications
  • Wireless Robots
  • Home Automation

Conclusion:

I hope all of you understand how to interface HC-05 with Arduino Uno. Modify the above code as per your requirements. We MATHA ELECTRONICS will be back soon with more informative blogs soon.

Leave a Reply

Your email address will not be published. Required fields are marked *