ARDUINO BLUETOOTH HC 05

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

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 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 program now make connection shown in circuit diagram below:

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

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 Bluetooth module is on.

Arduino Bluetooth HC 05

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

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 device. In this list you will find HC05, select it and then it requires 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 connect button that appears on top right of your screen. Wait for the 5 seconds till you get notification connected at bottom and connect button changes in disconnect.

Select HC 05

OUTPUT

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

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

Bluetooth Output

Leave a Reply

avatar
  Subscribe  
Notify of

Arduino Tutorials with Basic Electronics: CONTENT

Translate »