Arduino Bluetooth HC-05 Interfacing Tutorial

Arduino bluetooth hc05 module interfacing and controlling it from a smartphone(android) is a great idea. After learning this interfacing we can control any devices from the android using some android application. A bluetooth module operates at Scientific and Medical (ISM) 2.4GHz short-range radio frequency band. Bluetooth uses a radio technology called frequency-hopping spread spectrum. This kind of bluetooth has a range around 30 meters.
There are a different bluetooth module in the market for hobby and embedded system development. We are using HC 05 bluetooth module in this tutorial.

In this tutorial, we interface bluetooth module to the arduino and one LED at digital pin 13. An android device will be paired to HC-05, and by some android app we switch ON and OFF the led. If this is done then we can create different arduino bluetooth projects based on this tutorial.

Description

The hc-05 bluetooth module has six pins Vcc, GND, RX, TX, Key and State. By default, it comes as a slave device means it will only receive the signal can’t initiate a connection.

But if you want to send something from this module then we need to change it to the master mode by applying some AT commands. If we are connecting HC 05 with the android phone we simply use it in Slave Mode. The default transfer rate will be 9600 baud rate. The HC-05 module has a factory set pin “1234” which is used for pairing to the phone.

HC 05 Bluetooth Pinout

Features

  • Protocol: Bluetooth Specification v2.0+EDR
  • Frequency: 2.4GHz ISM band
  • Modulation: GFSK
  • Emission power: ≤4dBm, Class 2
  • Speed: Asynchronous: 2.1Mbps(Max) / 160 kbps, Synchronous: 1Mbps/1Mbps
  • Sensitivity: ≤-84dBm at 0.1% BER
  • Power supply: +3.3VDC 50mA
  • Security: Authentication and encryption
  • Working temperature: -20 ~ +75 Centigrade

Hardware Required

  • Arduino Uno
  • Bluetooth Module HC 05
  • LED
  • Resistor 220 ohm
  • Breadboard

Arduino Bluetooth Connection

Arduino and bluetooth hc05 serial connection is made. For this project, we should know arduino serial communication.

As we want to control the led at digital pin 13. Arduino already has a led at pin 13 so it is optional to connect the led. But we are connecting here for understanding.

Arduino Android Bluetooth App

There is a different arduino android bluetooth app for controlling the arduino from the android. We have used Bluetooth Controller App developed by FineApps because we are using from a long time and it’s very easy to understand. We can configure this app for different applications by simply editing the layout button text.


You can see easily that all the button is empty and we can edit according to the project.


So press button “SET KEYS”
A new window will open:
Key Name: Led ON and Led OFF => This is button Text
Key Value: => A and B respectively, this key value sends via bluetooth of android to HC-05 module Now press OK.



Now connect the bluetooth module as shown above and then supply it. Pair the HC-05 device with the mobile. It is just like we pair the other mobiles. The passkey is “1234”. Once paired we can find it from the bluetooth controller app by pressing the button “SCAN”.



And its Done! Now we write some code to arduino that will ON and OFF the LED by accepting ‘A’ for “ON” and ‘B’ for “OFF”.

Arduino Bluetooth HC-05 Code

By this bluetooth programming, we can create different arduino bluetooth projects.
Here function Serial.available() is used to monitor the incoming character ‘A’ and ‘B’. This function will be true if it gets anything from the serial port. Once it gets some value it checks whether it is coming from the Led ON or Led OFF button and take decision accordingly.

/*In this program, a user controls the Led by ON and OFF the button.
Each switch has a key value so the arduino can identify based on the key.
Button   Key Value
Led ON      'A'
Led OFF     'B'
*/
int ledPin = 13;                 // LED connected to digital pin 13
char read_bt;

void setup() {
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
  Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}

void loop() { 
  if (Serial.available() > 0) {
  // read the incoming byte:
  read_bt = Serial.read();
  if(read_bt=='A')
   digitalWrite(ledPin, HIGH);   // sets the LED on

   if(read_bt=='B')
   digitalWrite(ledPin, LOW);    // sets the LED off
  }
}

Leave a Reply

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