Bluetooth Module interfacing with Arduino

Bluetooth was first invented by Jaap Haartsen in the 1990s. It was named after a king, Harald Bluetooth, king of Denmark and Norway. Bluetooth is a wireless technology used for exchanging data between fixed and mobile devices over a short distance. Bluetooth LE and Bluetooth SPP are both Bluetooth profiles. These are also called as pairing modules because of the difference in their pairing process. Bluetooth Module interfacing with Arduino Uno :
SPP is used for sending and receiving bursts of data between two devices.
BLE is used to minimize energy consumption and speed to work with extremely low power.

HC – 05 module:

HC – 05 is very cheap, easy and designed for wireless serial connection setup with Bluetooth SSP(Serial Port Protocol).
The frequency band of the HC – 05 module is 2.45 GHz. Its connection maybe points to point or multipoint with the range of 10M.
The transfer rate of data is 1Mbps.
Comparing HC – 05 with HC – 06
HC – 06 can only be set as a slave but HC – 05 can be set as both slave and master which enables making communication between two separate Arduino boards.
HC-05 Bluetooth Module Pinout

                                                                                                     HC – 05 module

Pin Description:

  1. Enable/Key: It is used to bring modules in data mode and command mode.
  2. VCC: Connect a power supply of 5V or 3.3V.
  3. GND: Ground Pin.
  4. TX: Transmits serial data to the microcontroller.
  5. RX: Receives serial data.
  6. STATE: It states whether a module is connected or not.

Application:

  • Used to communicate between two different microcontrollers.
  • Used to communicate with mobile phones and other accessories.
  • Communicate with wireless Robots.
  • To control home appliances like fans, bulbs, etc.

Connecting Arduino with HC – 05 module

Interfacing HC-05 Bluetooth Module With Arduino Uno

                                                                                FIG.2: Interfacing of Arduino with HC – 05 module

  • Connect VCC to 5v of Arduino.
  • Connect GND to GND of Arduino.
  • Connect RX to TX of Arduino.
  • Connect TX to RX of Arduino.

Source code for interfacing bluetooth with arduino

#define ledPin 13
int state = 0;
voidsetup(){
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(38400); // Default communication rate of the Bluetooth module
}
voidloop(){
if(Serial.available()>0){ // Checks whether data is comming from the serial port
state = Serial.read(); // Reads the data from the serial port
}
if(state == ‘0’){
digitalWrite(ledPin, LOW); // Turn LED OFF
Serial.println(“LED: OFF”); // Send back, to the phone, the String “LED: ON”
state = 0;
}
elseif(state == ‘1’){
digitalWrite(ledPin, HIGH);
Serial.println(“LED: ON”);;
state = 0;
}
}

Explanation of program   

  • Initially define the LED pin and a variable in which we store the data.
  • In the setup, we define the LED pin as OUTPUT and set it as LOW.
  • Begin the serial communication at a 38400 baud rate.
  • In the loop the serial.the available() function is used to check whether data is coming from the serial port.If we send the data to the module, the data will be stored in a state variable using serial.read() function.
  • If the state variable is equal to ‘0’, it will turn the LED OFF and use serial println() it will send back to the phone, the string “LED OFF” and reset the state variable to 0.
  • If the state variable is equal to ‘0’, it will turn the LED ON and use serial println() it will send back to the phone the string “LED ON” and set the state variable to 0.
  • Now the code is ready to be uploaded.

Conclusion:

In the above discussion we came to know about the HC – 05 module, its pin description, and interfacing HC – 05 with Arduino. HC – 05  module is used in a wide range of Autonomous Robotic Projects where the wireless data transmission is required. 

Read related topics:

Introduction to arduino board
Interfacing of arduino with joystick module
arduino official website tutorials

Spread knowledge

Leave a Comment

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