ARDUINO BLUETOOTH HC 05

Program for UART communication is done for Bluetooth interfacing. HC-05 supports UART communication for receiving and transmitting data from/to MCU. Bluetooth module transfers and receives data wirelessly with help of its antenna. So let’s see the interfacing of Arduino Bluetooth HC 05.

CIRCUIT DIAGRAM ARDUINO BLUETOOTH HC 05

Connect +5V and Ground pin of Bluetooth module to +5V and Ground pin of Arduino respectively. The pre-built led in HC-05 Bluetooth module will start blinking continuously. This means the Bluetooth module is on.

Arduino Bluetooth HC 05
Click to Zoom

CONNECTION TABLE INTERFACE BLUETOOTH HC 05 WITH ARDUINO

S.N. Arduino HC-05
1. + 5V + 5V
2. GND GND
3. Rx Tx
4. Tx Rx

BLUETOOTH ARDUINO CODE

void setup() {
  /* To start UART (serial communication) bus with baud rate of 9600
     Here Serial is class and begin is function/method of class Serial
     (All classes in standard form written as first letter capital, here "S")
  */
  Serial.begin(9600);

  /* Transmitting a string "Welcome" from MCU to Serial Channel, here HC05 is connected (on Tx, Rx pins of Arduino)
     Using function Serial.println we are printing data in Serial device connected
     you can use Serial.print also, ln is used for the next line.
  */
  Serial.println("Welcome"); delay(10);
}

void loop() {
  // To check if data is available on Serial port
  if (Serial.available() > 0) {
    /* To read a data from HC05 or via serial communication protocol in character form like 'a', 'b'
        we are using read function/method of Serial
    */
    char data = Serial.read(); delay(10);

    /* Display a data on serial monitor as well on paired Bluetooth device
    */
    Serial.println(data);
  }
}

Baud rate: transmission rate of data in bits per second

There are two more functions which are used to read a data in string form and integer form are following –

  1. parseInt();//it will convert received data in to integer form
  2. readString();//to read a data in string form

After uploading the program now make the connection shown in the circuit diagram below:

Note: Don’t connect Rx and Tx of Arduino to BT while uploading a sketch, it will give you error. Remove Rx, Tx pin while uploading.

CONNECTION ESTABLISHMENT OF BLUETOOTH HC05 AND SMARTPHONE

1) Pair HC-05 module with your smartphone’s Bluetooth using 1234 as password. After getting paired, the LED on HC-05 module will blink intermittently.

To pair: Go to the smartphone Bluetooth settings and find nearby available Bluetooth devices. In this list you will find HC05, select it and then it requires a password which is by default set as 1234 or 0000 enter the password and devices are now paired.

Bluetooth HC 05 Pairing

2) Go to Google Play store and download the “Bluetooth terminal” app from it

Bluetooth Terminal app

3) Open the Bluetooth terminal app and search for the paired device and select it. Now, click on the connect button that appears on the top right of your screen. Wait for the 5 seconds till you get notification connected at the bottom and connect button changes in disconnect.

Select HC 05

OUTPUT

Now you just need to send data from the app which will be transmitted by phones BT through the antenna and received by the HC05 antenna then HC05 transmit this data from its Tx to RX of the arduino, but data should be a character (integers are also characters in ASCII) not string here the instruction Serial.read() works.

Serial.print() will transmit data from Arduino Tx to Rx of BT and then BT transmits it to the smartphone through its antenna and that’s how the two-way communication works.

Bluetooth Output


READ NEXT
APPLIANCE CONTROL USING BLUETOOTH AND ARDUINO


Total Visits: 1153
0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x