How to use the HC-05 Bluetooth Module with Arduino

How to use the HC-05 Bluetooth Module with Arduino

HC-05 Bluetooth Module Arduino

INTRODUCTION

Bluetooth is a wireless technology standard used for exchanging data between fixed and mobile devices over short distances using short-wavelength radio waves.

HC-05 is a Bluetooth module and it is used for sending and receiving data through Serial Communication.  It can be connected with a microcontroller (In our case an Arduino) to control multiple sensors.

APPLICATIONS

Applications for Bluetooth technology include short distance communication, mobile phones, digital Camera, autonomous Vehicles, home automation.

WIRING DIAGRAM

GND – GND

VCC – 3.3 V

RX – TX

TX – RX

HC05 Bluetooth Arduino connection

 

CODE

 

char junk;
String inputString="";
void setup()                    // run once, when the sketch starts
{
 Serial.begin(9600);            // set the baud rate to 9600, same should be of your Serial Monitor
 pinMode(13, OUTPUT);
}
void loop()
{
  if(Serial.available()){
  while(Serial.available())
    {
      char inChar = (char)Serial.read(); //read the input
      inputString += inChar;        //make a string of the characters coming on serial
    }
    Serial.println(inputString);
    while (Serial.available() > 0)  
    { junk = Serial.read() ; }      // clear the serial buffer
    if(inputString == "a"){         //in case of 'a' turn the LED on
      digitalWrite(13, HIGH);  
     Serial.print("LED IS ON");
    }else if(inputString == "b"){   //incase of 'b' turn the LED off
      digitalWrite(13, LOW);
     Serial.print("LED IS OFF");
    } 
inputString = "";    } }

END RESULT

Open the serial monitor. When “ a “ is sent, the Built-in Led will Turn ON, and when “ b “  is sent from the serial monitor, Built-in LED will Turn OFF.

Want to be smarter?

Let’s turn ON/OFF the LED using your Phone.

One can easily use a smartphone (Android) to turn Led on & off with HC-05 and Arduino. The pin configuration and the code will remain the same.

1. Download Bluetooth Terminal Mobile Application (Bluetooth Terminal HC-05, available on Google play store) The following is the front image of mobile app.

2. Give power to Arduino and HC-05

3. Open the mobile application and turn your mobile Bluetooth ON

4. You will see a list of available Bluetooth connections

5. Select HC-05

6. It will ask you to enter the code. By Default, codes are 0000 or 1234; anyone of them can be used for a successful connection

7. When your Bluetooth is connected, the HC-05 device which is connected with the Arduino starts blinking with a delay of around 1 second (it is the confirmation that the Bluetooth is successfully connected with your mobile phone application)

8. Now you need to send “a “for turning Led on and “b “for turning Led Off

ADDITIONAL RESOURCES

https://howtomechatronics.com/tutorials/arduino/arduino-and-hc-05-bluetooth-module-tutorial/