This tutorial will demonstrate how to configure and use the Serial Bluetooth Module with an Arduino Uno. There are three types of Serial Bluetooth Modules, which are available in the market. They are:
1. Master-Slave (HC-03, HC-05) -user can change the firmware.
2.Master Only (HC-04-S, HC-06-S) -user cannot change the firmware, factory default firmware.
3. Slave Only (HC-04-M, HC-06-M) -user cannot change the firmware, factory default firmware.
To have a connection between two micro controllers, a master device is needed (e.g. the HC-05 can be configured as master or slave). For simple device to computer and device to Notebook communication Master-Slave Module is not necessary. It can be made possible by using simple Master or Slave Modules(HC-06,HC-04). The entire tutorial is based on the use of the HC-06 Bluetooth Module.
HC-06 Bluetooth Module:
HC 06 is a slave Bluetooth to serial adapter. It measures a dimensions of only 28mm x 15 mm x 2.35mm.It is easy to handle and can be used as wireless UART Communication from PC to any microcontroller. HC-06 is a slave only device. By default, HC-06 has
- Baud Rate – 9600
- Pairing Code – 1234
- Name/ ID – linvor
The settings can be changed by using AT Commands.
Testing the Bluetooth Module:
Step1: Uploading the Code
Upload the below sketch to the Arduino Uno,
void setup ()
Serial.begin(9600);//set the baud rate
Serial.println(“start”);//send data to the android phone
Serial.println(“Hiii, Android”);// send data to the android phone
The HC-06 Module communicates with the Arduino Uno via serial connection. Four pins are used:
- VCC -> VCC is used to power the module. It is connected to the Arduino 5v pin.
- GND -> GND is the ground pin. It is connected to the Arduino Ground pin.
- TX -> TXD is used to send data from the module to the Arduino. It is connected to the serial receive pin (RX) of the Arduino, which is pin 0 in case of the Uno. Incase different Arduino board is used, then its schematics has to be checked inorder to make sure that the right pins are used.
- RX -> RXD is used to receive data from the Arduino. It is connected to the Arduino serial transmit pin (TX), which is pin 1 of Arduino Uno.
- KEY -> This pin is used for changing the settings (AT Command Mode).At present, KEY pin is left open.
VCC -> VCC (5V)
TX ->RX (D0)
RX ->TX (D1)
Note: Make sure that the sketch is loaded from step 1 on the Arduino, before connecting the Bluetooth model to the phone.It is not possible to use the Arduino IDE serial monitor or upload sketches when the Bluetooth module is connected, as it uses the same RX/TX lines. Software Serial library is used to connect the Bluetooth module to any digital Arduino pin and keep the RX/TX line open.
Step 4: Pairing the Bluetooth and setting the Blueterm Software
- After the power up of the Bluetooth device, turn on the Bluetooth in the android phone.
- Search for the new devices. A Bluetooth device name is found. Click on the Bluetooth device name, a pairing window appears,which looks similar to the fig shown below. Type a password, say “1234”.
- Install the Blueterm free Android app on the phone.
- Open the Blueterm app and click on menu.Connect to the Bluetooth device.A message “Hi, Android” is displayed on the Blueterm Window continuously.
Changing the default Settings through AT Commands:
Step 1: Connection
- Make “KEY” Pin of the Bluetooth Module HIGH by connecting KEY Pin to the VCC and the complete connection. It is shown below.
VCC -> VCC (5V)
GND -> GND
TX -> RX (D0)
RX -> TX (D1)
KEY -> VCC
Open the Serial Monitor and set the Baud Rate to 9600.
Step 2: AT Commands
- Communication Test:
Test the Bluetooth Module by typing “AT” on Serial Monitor without an inverted coma(“”).After typing, press “Enter” on the keyboard. Incase Serial Monitor response is “OK”, then it is confirmed that Bluetooth Module is accepting the AT Commands, else double check the connections.
<- Sent: AT
-> Receive: OK
- AT Command for Setting the Baud Rate:
- Sets the Bluetooth UART Baud Rate. Baud Rate is set by an hexadecimal index from ‘1’ to ‘C’
- Indexes are 1:1200, 2:2400, 3:4800, 4:9600, 5:19200, 6:38400, 7:57600, 8:115200, 9:230400, A:460800, B:921600, C:1382400
- Send: AT+BAUD<index>
- Response: OK<baud rate
- AT Command for Setting the Device Name:
- Sets the Bluetooth Device Name
- Send: AT+Name<device name>
- Response: OKsetname
- AT Command for Setting the Bluetooth PIN Code:
- Sets the security code needed to connect to the device.
- Send:AT+ PIN<4 digit code>
- Response: OK<4 digit code>
- AT Command for checking the Firmware Version:
- Get the Firmware Revision Number
- Send: AT+VERSION
- Response: Linvor V1.8