Subscribe To Our List

We help electronics hobbyists to create projects related to Micro-controllers. Join our newsletter to get access to new projects first.
Email address
Secure and Spam free...

In this tutorial, you are going to know in detail about the basics of the Arduino Bluetooth module interfacing. The Bluetooth module works with the Arduino through the serial communication. The Arduino will receive the data from the HC-05 Bluetooth module through the serial communication and will turn on or off the LED’s according to the data received. The APP we are going to use for this project is the blueterm.

There are many Bluetooth modules available but the one we are using is the HC-05 Bluetooth module which is most commonly used and make sure to buy the module which comes on breakout board because in this way, it is a lot easier to make connections.

HC-05 Bluetooth Module

The HC-05 module is a Bluetooth SPP (Serial port protocol) module which means that it communicates with the Arduino through serial communication. This module is designed for wireless serial communication and it is fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate) 3Mbps Modulation with complete 2.4GHz radio transceiver and baseband. The maximum range for wireless communication for this module is 10 meters.

The HC-05 Bluetooth module is different from the other modules like HC-06 in a way that the HC-06 module can only be set as a slave while the HC-05 module can be set as a master as well as a slave which can enable the communication between the two microcontrollers like two Arduino boards.

Download the HC-05 DataSheet from here.

Specifications

The specifications of the HC-05 Bluetooth are as follows.

  • Low power operation, 3 to 5V
  • Comes with integrated antenna
  • UART interface with programmable baud rate
  • Supported baud rates are 9600,19200,38400,57600,115200,230400 and 460800.
  • Auto-connect to the last device on power as default.
  • Frequency: 2.45 GHz

Required Components for Arduino Bluetooth Module Tutorial

The components required for Arduino Bluetooth Module Tutorial are as follows

  • HC-05 Bluetooth module (HC-06 will work too)
  • Arduino UNO (Other models will work too)
  • 3 X LED’s
  • 3 X 220 ohm resistors
  • 1k and 2k resistor
  • Connecting wires

Circuit Diagram and Explanation

HC-05 Bluetooth module have six pins but we are not going to use the key and state pins because we do not require these in the project. The state command tells that either it is connected or not and the key command forces setup mode if it is brought HIGH before power is applied.

The four pins that we are going to use are the VCC, GND, TXD and the RXD pins. The VCC requires up to 5V to power up while the RXD pin communicates with the Arduino on 3.3V. So, if you will connect it RXD directly to the Arduino then it may work but it will get damage soon. So it is better to make a voltage divider to convert the 5V into 3.3V using the resistors and then connect the RX pin through this to the Arduino.

Connect the VCC and the ground pin of the HC-05 to the 5V and the ground of the Arduino. Then connect the TX to the pin 0 of the Arduino which is the RX pin by default. Then make a voltage divider by connecting the 1k and 2k resistors in series and connect the RX of the HC-05 to the pin 1 of Arduino through the resistors as shown in the figure.

In last, connect three LED’s to the pins 8, 9 and 10 of the Arduino.

arduino bluetooth module interfacing

Arduino Bluetooth Module Interfacing

Code

Before uploading the code, remove the TX and RX wires from the Arduino and connect these again when the code will be uploaded.

int first_LED = 8; 
int second_LED = 9;
int third_LED = 10;
int state;
int flag=0; //makes sure that the serial only prints once the state
 
void setup() {
 // sets the pins as outputs:
 pinMode(third_LED, OUTPUT);
 pinMode(second_LED, OUTPUT);
 pinMode(first_LED, OUTPUT);
 Serial.begin(9600);
} 
void loop() {
 //if some date is sent, reads it and saves in state
 if(Serial.available() > 0){ 
 state = Serial.read(); 
 flag=0;
 } 
 
 if (state == '1') {
 digitalWrite(first_LED, HIGH); 
 if(flag == 0){
 Serial.println("First LED ON");
 flag=1;
 }
 }
 
 else if (state == '2') {
 digitalWrite(second_LED, HIGH);
 if(flag == 0){
 Serial.println("Second LED ON");
 flag=1;
 }
 }
 
 else if (state == '3') {
 digitalWrite(third_LED, HIGH); 
 if(flag == 0){
 Serial.println("Third LED ON");
 flag=1;
 }
 }
 else if (state == '0') {
 digitalWrite(third_LED, LOW);
 digitalWrite(second_LED, LOW);
 digitalWrite(first_LED, LOW); 
 if(flag == 0){
 Serial.println("LED: off");
 flag=1;
 }
 }
}

Code Explanation

First of all, we have defined the pins where we have connected the LED’s and declared a variable named state. The data coming from the app will be stored in this variable. The flag variable will make sure that the data is sent only once.

int first_LED = 8;
int second_LED = 9;
int third_LED = 10;
int state;
int flag=0;

The ‘serial.available’ command will check that if we have sent some data from the Bluetooth, then the ‘serial.read’ command will read this and will store it into the state variable. Then we set the flag at zero so that we receive data one by one.

if(Serial.available() > 0){    
      state = Serial.read();  
      flag=0;
    }

After that, we will compare the received data with the data we have set in our code. If it will match, then the commands written in it will be executed.

if (state == '1') {
        digitalWrite(first_LED, HIGH);
          if(flag == 0){
          Serial.println("First LED ON");
          flag=1;
        }
    }
    else if (state == '2') {
.
.
.

 Installing the Blueterm APP and Working

Install the Blueterm android APP from here. The reason for choosing this APP is that it has greater functionalities than the other Bluetooth APP’s and it is most commonly used APP for Bluetooth communication.

After installing the APP, open it and from the options connect it to the Bluetooth module. After connection, it will show you blue empty screen. Now, when you will type ‘1’ there, then the first LED will light up and when you will type ‘2’, then the second LED will light up and similarly by typing ‘3’, the third led will light up. By typing ‘0’ the LED’s will go down.

Video

If you have any questions, feel free to ask us in the comment section.

JOIN OUR NEWSLETTER
We help electronics hobbyists to create projects related to Micro-controllers. Join our newsletter to get access to new projects first.
We hate spam. Your email address will not be sold or shared with anyone else.

Leave a Reply

Your email address will not be published.

Subscribe To Our List

We help electronics hobbyists to create projects related to Micro-controllers. Join our newsletter to get access to new projects first.
Email address
Secure and Spam free...
Skip to toolbar