You are on page 1of 23

AN INTRODUCTION TO BLUETOOTH

MODULES (HC-05 & HC-06)

An Introduction to Bluetooth Modules 1 | P a g e


Contents
Introduction to Bluetooth Technology ................................................................................................... 2
Advantages and Disadvantages .............................................................................................................. 3
Advantages.......................................................................................................................................... 3
Disadvantages ..................................................................................................................................... 3
Introduction to HC-05 and HC-06 Modules ............................................................................................ 3
HC 05 ................................................................................................................................................... 3
HC 06 ............................................................................................................................................... 4
Hooking up with Arduino ........................................................................................................................ 5
HC-05 with Arduino............................................................................................................................. 5
HC-06 with Arduino............................................................................................................................. 7
Configuring HC-05 with AT commands ................................................................................................... 7
HOW TO PAIR TWO BLUETOOTH MODULES (HC-05) ............................................................................. 9
WIRELESS PROGRAMMING USING HC-05 BLUETOOTH MODULE.................................................. 12
Step 1: Install the latest beta version of Arduino ............................................................................. 13
Step 2: Bread-board the Bluetooth module setup circuit................................................................ 13
Step 3: Upload the setup sketch ....................................................................................................... 14
Step 5: Setup the Bluetooth module in Windows ............................................................................ 18
Step 6: Set-up the Bluetooth module in Windows (cont'd) ............................................................. 19
Step 7: Solder a jumper onto the Bluetooth module ....................................................................... 21
Step 9: Program the Arduino with Bluetooth ................................................................................... 23
References ............................................................................................................................................ 23

Introduction to Bluetooth Technology


Bluetooth is a wireless communication technology used for exchange of data over
short distances. It is found in many devices ranging from mobile phones and
computers. Bluetooth technology is a combination of both hardware and
software. It is intended to create a personal area networks (PAN) over a short
range. It operates in the unlicensed industrial, scientific and medical (ISM) band
at 2.4 to 2.485 GHz. It uses a radio technology called frequency hopping spread
spectrum. Bluetooth technologys adaptive frequency hopping (AFH) was
designed to reduce interference between wireless technologies sharing the 2.4
GHz spectrum. This adaptive hopping among 79 frequencies at 1 MHz intervals
gives a high degree interference immunity. Thus the Bluetooth divides the data
that need to be transmitted into packets and each packet are transmitted on one of
79 designated Bluetooth channels. The bandwidth of each channel is 1 MHz .It is

An Introduction to Bluetooth Modules 2 | P a g e


a packet-based protocol with a master-slave structure. Each master can
communicate with up to 7 slaves in a piconet. The range of Bluetooth depends
upon the class of radio using.
Class 3 radios have range up to 1 meter or 3 feet.
Class 2 radios have range of 10 meters or 33 feet.
Class 1 radios have range of 100 meters or 300 feet.
The most commonly used radio is Class 2.

Advantages and Disadvantages


Advantages
The biggest advantage of using this technology is that there are no cables or wires
required for the transfer of data over short ranges. Bluetooth technology
consumes less power when compared with other wireless communication
technologies. For example Bluetooth technology using Class 2 radio uses power
of 2.5 mW. As it is using frequency hopping spread spectrum radio technology
there is less prone to interference of data if the other device also operates in the
same frequency range. Bluetooth doesnt require clear line of sight between the
synced devices.
Disadvantages
Since it uses the greater range of Radio Frequency (RF), it is much more open to
interception and attack. It can be used for short range communications only.
Although there are fewer disadvantages, Bluetooth still remains best for short
wireless technology.

Introduction to HC-05 and HC-06 Modules


HC 05
HC-05 is a class 2 Bluetooth module with Serial Port Profile (SPP). It can be
configure either as master or salve. It is a replacement for wired serial connection.

An Introduction to Bluetooth Modules 3 | P a g e


The datasheet of the Bluetooth module is below
http://www.robotshop.com/media/files/pdf/rb-ite-12-bluetooth_hc05.pdf
HC-05 Specification:
Bluetooth Protocol : Bluetooth Specification v2.0 + EDR
Frequency : 2.4 GHz ISM band
Profiles : Bluetooth Serial Port
Working Temperature : -20 to + 75 centigrade
Power of emitting : 3 dBm
The pins on the module are:
Vcc Power supply for the module.
GND Ground of the module.
TX Transmitter of Bluetooth module.
RX Receiver of the module.
Key Used for the module to enter into AT command mode.
HC 06
HC-06 is a drop-in replacement for wired serial connection. This can be used as
serial port replacement to establish connection between PC and MCU
(Microcontroller). This is a Slave Mode only Bluetooth device. This module can
be configured for baud rates 1200 to 115200 bps.

The datasheet of HC-06 module is in the below link:


http://www.electronicoscaldas.com/datasheet/HC-06_Wavesen.pdf
HC-06 Module Features:
An Introduction to Bluetooth Modules 4 | P a g e
Encrypted connection
Frequency : 2.4 2.524 GHz
Bluetooth core v2.0
Serial Port Profile (SPP) support

Hooking up with Arduino


HC-05 with Arduino

The connections are:


HC-05 Arduino
Vcc -----------> 5V
GND -----------> GND
TX -----------> RX
RX -----------> TX
HC-05 is connected to Arduino as shown in above figure. The Bluetooth module
will be blinking with a delay of 1 second when it is powered. If HC-05 is to be
paired from PC, search for the available Bluetooth devices from PC and there
should be a device named HC-05. Pair with it and the default passcode is
1234(You can change it later from AT commands). If HC-05 is paired it blinks it
with a delay of 2 seconds. If a Bluetooth module is connected to laptop it opens
a COM port, hence in PC using Device Manager search for which COM port the
Bluetooth module is connected.

An Introduction to Bluetooth Modules 5 | P a g e


Lets control the LED on Arduino using a basic code to send command over
Bluetooth. The code is below.

char ch;

void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop() {
if(Serial.available())
{
ch=Serial.read();
if(ch=='h')
{
digitalWrite(13,HIGH);
}
if(ch=='l')
{
digitalWrite(13,LOW);
}
}
}

In the above code if h (without quotes) is entered in the Serial port the LED
(which is interconnected to 13th pin of Arduino) will glow. If l (without quotes)
is entered the LED will turn off. Now upload the code to Arduino and pair with
HC-05 and open the COM port to which HC-05 is connected. Now enter the
commands h or l to control the Arduino. Thus, successfully you controlled the
Arduino using HC-05. You can make the changes to code as per your
requirement.
Note: Here the HC-05 TX and RX are connected to RX (0) and TX (0) of
Arduino Uno. If you use other Arduino there are more than one serial ports. So
while writing the code write correct serial port number to which RX and TX of
HC-05 are connected.
For example if you use Arduino MEGA there are 4 serial ports. Consider if TX
and RX of HC-05 are connected to RX (1) and TX (1) of MEGA then replace
Serial with Serial1 in code and upload it.

An Introduction to Bluetooth Modules 6 | P a g e


HC-06 with Arduino

The connections are:


HC-06 Arduino
Vcc -----------> 5V
GND -----------> GND
TX -----------> RX
RX -----------> TX
HC-06 is same as HC-05 but the only difference is HC-06 is slave mode only
while HC-05 can be configured as either master or slave. Hence the program used
for HC-05 can be used for this module also and can control the Arduino.

Configuring HC-05 with AT commands


HC-05 can be configured i.e. its name and password can be changed and many
more using AT commands. It can also be configured as either master or slave.
To set the HC-05 into AT command mode the KEY pin of the module is made
high i.e. it is connected to either 5V or 3.3V pin of Arduino and TX of Arduino
is connected to TX of HC-05 and RX of HC-05 to RX of Arduino.
The connections with Arduino are shown in the below figure:

An Introduction to Bluetooth Modules 7 | P a g e


Power up the Arduino after connecting HC-05 to it. It is known that HC-05
entered into AT command mode by observing the blinking of LED on Bluetooth
module. It blinks with a delay of 2 seconds. To enter the AT commands open up
the COM port of the Arduino to which the Bluetooth module is connected and set
the baud rate to 38400. After opening COM port if you enter command AT
(without quotes) it should return OK thus it can be said that HC-05 entered into
AT command mode.
Lets see some of AT commands to change the name and password of HC-05
module.
To change the name enter command AT + NAME = <Param> (without
quotes).
Where <Param> is Bluetooth device name.
To change the password enter command AT + PSWD =<Param>
(without quotes).
Where <Param> is Bluetooth device passkey (default is 1234).
To check the role (master or slave) of the Bluetooth device enter command
AT+ROLE?(without quotes). If it returns 0 it is in Slave mode, if it
returns 1 it is in Master mode.
You can also set the role of HC-05 using command AT + ROLE = <Param>
Where Param=0 for Slave mode and 1 for Master mode.

An Introduction to Bluetooth Modules 8 | P a g e


The above are basic AT commands you can use. It will return OK after each
command is executed. The below is the list of AT commands you can use for
configuring your Bluetooth module.
http://www.linotux.ch/arduino/HC-
0305_serial_module_AT_commamd_set_201104_revised.pdf
These AT commands are used to set the baud rate, name, passkey, remote
Bluetooth device address etc.

HOW TO PAIR TWO BLUETOOTH MODULES (HC-05)

It is quite simple to pair a Bluetooth module from your Android phone. But
bit tricky to pair it with another HC-05 module. In this post Ill describe
the method of pairing 2 Bluetooth modules. One of the module is assigned
ROLE as MASTER & the other left as SLAVE.
By default all HC-05 modules are SLAVES. Using AT commands the
module can be configured as we like.
To configure the SLAVE we make use of an Arduino UNO board. Not
much of configuration needed for slave. We can leave it to defaults. But to
know the ADDRESS of the slave youve to follow this procedure.

Before connecting the HC05 module, upload an empty sketch to Arduino.


This bypasses the Boot loader of UNO & the Arduino is used as USB-
UART converter.

An Introduction to Bluetooth Modules 9 | P a g e


After uploading this empty sketch, remove USB power from Arduino & do
the following connections with HC05 Slave:

ARDUINO HC05

Rx (pin0) > Rx

TX (pin1) > TX

+5v > VCC

GND > GND

+3.3V > KEY

Remember it is one to one connection here & not cross connection

Now provide the USB cable power to Arduino. The HC-05 module enters
the Command mode with Baud Rate 38400.
Open the Serial Monitor of Arduino.
Ensure to select BOTH NL & CR & Baud Rate as 38400 at the bottom
of the serial monitor. This is very important as the Bluetooth module HC-
05 expects both Carriage Return and Line Feed after every AT command.

An Introduction to Bluetooth Modules 10 | P a g e


If you type in AT & click on SEND button you should get an OK
confirmation from the HC-05 module.
If you get ERROR (0) try again to enter the Command mode. If there is
no response then check whether correct COM port has been assigned in
Arduino IDE & confirm Baud Rate is 38400, Both NL & CR selected.
Type in AT+NAME? To get the name of the module. You can change
the name as you like with

AT+NAME=HC05_SLAVE

The password by default is 1234 .Confirm that with AT+PSWD?


The ROLE of the module can be known by typing AT+ROLE?
You can change it by AT+ROLE=0 (0 for SLAVE & 1 for Master). Leave
it as 0 as we want this module to be SLAVE.
You should know the Address of this module to make it pair with another.
Type in

AT+ADDR? & note the Address. Here it is 14:2:110007.

While using this address in AT commands you should replace the colon
with a comma, like

14, 2,110007
An Introduction to Bluetooth Modules 11 | P a g e
Now remove the KEY connection from the HC05 module & disconnect
the power.
Again provide the power to see STATUS LED on the module blinking fast
indicating that it is looking for a PAIR.
Now we have the slave Bluetooth module ready. Now we have to setup the
master Bluetooth module.

NOTE: SAME CONNECTION IS USED FOR CONFIGURING THE MASTER


MODULE AS THAT OF SLAVE MODULE.

If you type in AT & click on SEND button you should get an OK


confirmation from the HC-05 module.
If you get ERROR (0) try again to enter the Command mode. If there is
no response then check whether correct COM port has been assigned in
Arduino IDE & confirm Baud Rate is 38400, Both NL & CR selected.
Type in AT+NAME? To get the name of the module. You can change
the name as you like with

AT+NAME=HC05_MASTER

The password by default is 1234 .Confirm that with AT+PSWD?


The ROLE of the module can be known by typing AT+ROLE?
Change it master mode by typing following AT command:

AT+ROLE=1 (0 for SLAVE & 1 for Master)

Now, type the following AT Command to pair with the slave module.

AT+LINK=14, 2,110007

NOTE: BEFORE TYPING THIS AT COMMAND, MAKE SURE THAT OTHER


MODULE MUST BE POWERED SO THAT THEY CAN BE PAIRED.

If it returns OK it means the module is set to pair with the slave module
when both module are switched on at same time.

Hence, the two modules are paired.

WIRELESS PROGRAMMING USING HC-05 BLUETOOTH


MODULE

We generally program the Arduino board USB cable. But using HC-05 Bluetooth
module we can program the Arduino board without USB cable that is by

An Introduction to Bluetooth Modules 12 | P a g e


wirelessly. We need to modify the hardware little bit for the wireless
programming and steps required for wireless module are shown below.

Step 1: Install the latest beta version of Arduino


The current beta version of the Arduino IDE has fixed some of the issues that made
Bluetooth programming difficult in the past. The most current version available
today is Arduino 1.5.6-r2.

You can download the installer from: http://arduino.cc/en/Main/Software


Step 2: Bread-board the Bluetooth module setup circuit

The Bluetooth module used in this project is the HC-05. It is inexpensive


and one of the most common modules you'll see in a lot of other
projects. The HC-05 is sold bare or mounted to a breakout board. You
want one on a 6-pin breakout board.
Using a breadboard, temporarily wire the HC-05 Bluetooth module per
the schematic.
With 3.3v on the Key pin, the module will enter 38400 baud command
mode and will accept AT commands. The Key pin must be connected to
An Introduction to Bluetooth Modules 13 | P a g e
3.3v when the module is powered on. If it is connected afterwards, the
module will enter command mode at the default baud rate (as set by the
'AT+UART=' command or 9600 baud from the factory).

Step 3: Upload the setup sketch

An Introduction to Bluetooth Modules 14 | P a g e


The above sketch is attached below, upload it to your Arduino.

/* Serial Loop */

#include <SoftwareSerial.h>

#define rxPin 8
#define txPin 9

SoftwareSerial mySerial(rxPin, txPin);


// RX, TX
char myChar ;

void setup() {
Serial.begin(9600);
Serial.println("AT");

mySerial.begin(38400);
mySerial.println("AT");
}

void loop() {
while (mySerial.available()) {
myChar = mySerial.read();
Serial.print(myChar);
}

while (Serial.available()) {
myChar = Serial.read();
Serial.print(myChar); //echo
mySerial.print(myChar);
}
}

An Introduction to Bluetooth Modules 15 | P a g e


Step 4: Run the setup sketch and enter serial commands

Open the serial console and make sure the baud rate is set to 9600 and
line endings is set to be "Both NL & CR"
Enter the following AT commands into the serial console.
AT

AT+ORGL

AT+ROLE=0

AT+POLAR=1,0

AT+UART=115200,0,0

AT+INIT

In order, these commands tell the module to reset to factory settings,


switch to slave role (transparent serial bridge), set pin 32 low on
An Introduction to Bluetooth Modules 16 | P a g e
Bluetooth connection, change baud rate to match the Arduino Uno
programming rate, and to initialize.
Disconnect 3.3v from the Key pin and cycle the power to the module. It
will now be running at 115200 baud and be in pairing mode.

An Introduction to Bluetooth Modules 17 | P a g e


Step 5: Setup the Bluetooth module in Windows

An Introduction to Bluetooth Modules 18 | P a g e


From the Control Panel select add a Device.
Add the Bluetooth module.
Select enter pairing code option.

Step 6: Set-up the Bluetooth module in Windows (cont'd)

An Introduction to Bluetooth Modules 19 | P a g e


Enter "1234" for the pairing code.
At the Add a device success window, click Close.
Device ready to use. The OS will create two serial COM ports associated
with the device. Always use the one with the lower number.

An Introduction to Bluetooth Modules 20 | P a g e


Step 7: Solder a jumper onto the Bluetooth module

Disassemble the bread boarded circuit. Solder a jumper wire directly to


the HC-05's Pin 32.
Don't forget to use flux.
You may want to use hot glue or tape to protect the joint.

Step 8: Build the programmer circuit.

An Introduction to Bluetooth Modules 21 | P a g e


Build the programmer circuit onto the prototyping shield.
Solder on a female header for the Bluetooth module if you want to be
able to easily remove it later.

An Introduction to Bluetooth Modules 22 | P a g e


Step 9: Program the Arduino with Bluetooth

Power on the Arduino from a battery or AC adapter.


In the Arduino IDE, choose the serial port of the Bluetooth module (the
lower valued one of the two) and then upload a sketch like normal.

Hence the Arduino board is programmed wirelessly using HC-05 Bluetooth


module.

References

https://alselectro.wordpress.com/2014/10/18/bluetooth-module-hc-
05how-to-pair-2-modulesat-command-walkthrough/
https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pair-
two-modules/
http://www.bluetooth.com/Pages/How-It-Works.aspx
http://makezine.com/projects/diy-arduino-bluetooth-programming-shield/
An Introduction to Bluetooth Modules 23 | P a g e

You might also like