Wednesday, 6 August 2014

HC - 05 Bluetooth Module Basic interface (Tutorial 1)

HC-05 Bluetooth Module:

             
   HC – 05 is a Bluetooth SPP profile module that can be used as either Master or Slave device.
Master - the module can be configured to search for the nearer Bluetooth devices and can pair with required device (mobiles and computers).
Slave (Default mode) – Other Bluetooth devices can search for this module and pair with the module by simply typing the default password (1234).
There are two modes in HC-05 communication,
1.        Communication mode
2.       AT mode
          In this tutorial, we will just see the communication mode, where data is transmitted between HC-05 and Android mobile phone. An Android App named Blueterm is used to receive this serial data and display it. GR-Sakura board (Arduino Uno Compatible) is used to control HC-05 Bluetooth module.
         The HC-05 Bluetooth module that I use is shown below. I bought it for Rs.1000 from nskelectronics.com. While you buy a HC-05, note that it comes with the interface board as shown below.
 
          If you buy it without the interface board as shown below, then it’s a big ‘headache’.  I bought one, tried to solder it, but it was an utter failure.
 

 

Pin Details:



State – LED output status (Honestly, I don’t exactly know what this does. It is not of much use, hence no worries.)

Key – pin to drive the module into AT mode
 
RX – UART Receiver pin
 
TX – UART Transmit pin
5V – 5 volt supply voltage
 
GND – ground pin
 
Note: In the module I use, RX and TX pins of the module should be connected to the RX and TX pins of the processor respectively.
 

Circuit Diagram:

 
 
 

BlueTerm:

      First pair with HC-05 by searching for bluetooth devices using Android Mobile phone. Then open Blueterm App.
 Blueterm app screen

Tips: In the Preferences tab, select the ‘Local echo’ option or else the characters that you type won’t be visible in the screen.




Once you open Blueterm, click ‘Connect Device’ and select ‘HC-05’.
 

Tera term:

 
            Similar to the app at mobile side, you can have a serial monitor at PC side. One of such serial monitors is Tera Term.




 
 

Code:


#include <rxduino.h>
#include<iodefine_gcc63n.h>

int main()
{
  Serial.begin(9600);

  Serial1.begin(115200, SCI_SCI6B); // the baud rate should be same as that of the module baud rate *
  delay(8000);

  Serial.println("Start sending data.....");
  Serial1.println("Start sending data.....");

  delay(5000);
  while(1)
  {
              if (Serial.available())
              {
                          Serial1.write(Serial.read());
              }
               if (Serial1.available())
              {
                          Serial.write(Serial1.read());
              }
  }
}
Now, whatever you type in Tera term will appear in Blueterm and vice versa.
 
 
 
* The baud rate can be found out using the AT command (AT+UART?). The AT mode will be discussed later.


2 comments:

  1. i can´t compile the program, i need the library

    ReplyDelete
  2. You can download the library from arduino website.

    ReplyDelete