Bluetooth® wireless technology is becoming a popular standard in the communication. it is one of the fastest growing fields in the wireless technologies. It is convenient, easy to use and has the bandwidth to meet most of today’s demands for mobile and personal communications. Bluetooth technology handles the wireless part of the communication channel; it transmits and receives data wirelessly between these devices. It delivers the received data and receives the data to be transmitted to and from a host system through a host controller interface (HCI). The most popular host controller interface today is either a UART or a USB .Here, I will only focus on the UART interface, it can be easily show how a Bluetooth module can be integrated on to a host system through a UART connection and provide the designer an optimal solution for Bluetooth enabled systems.
The bluetooth module I will use today is HC-05 which is so familiar and cheap. It is easily available in local indian markets. You can go either offline or online. You may find in about ~600 ₹. May be if you search better, you can get as low as 450 ₹.
HC-05 Bluetooth Module is one of the most popular bluetooth module used in embedded projects. It can be easily interfaced with Arduino Board, Raspberry Pi, Microcontrollers through serial UART interface. HC-05 module is an easy to use Bluetooth SPP (Serial Port Protocol) module, designed for transparent wireless serial connection setup.
Serial port Bluetooth module is fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate) 3Mbps Modulation with complete 2.4GHz radio transceiver and baseband. It uses CSR Bluecore 04-External single chip Bluetooth system with CMOS technology and with AFH(Adaptive Frequency Hopping Feature). It has the footprint as small as 12.7mmx27mm. Hope it will simplify your overall design/development cycle.
- Frequency : 2.4GHz ISM Band
- Bluetooth Protocol : Bluetooth Specification v2.0 + EDR
- Emission Power : ≤4dBm, Class 2
- Operating Voltage : 3.3V
- Input Power Supply : 3.6V ~ 6V
- Security : Authentication & Encryption
- Working Temperature : -20°C ~ +75°C
- Dimensions : 35.7mm x 15.2mm x 5.6mm
- 3.3V TTL Compatible
- Wide Input Voltage Range : 3.3V ~ 6V
- Supported Baud Rates : 9600, 19200, 38400, 57600, 115200, 230400, 460800
- Auto Connect to Last Device on power as default
- Supports Master and Slave Modes
This module works on AT Commands. Lets have a look at important AT commands.
- KEY: if set to HIGH module goes into command mode for configuration
- RXD: the RXD signal line – 5V safe
- TXD: the TXD signal line – 5V safe
- Vcc: connection for 5V supply voltage
- GND: Ground
- State : Not connected
The Module has two modes of operation namely,
- AT Command Mode.
It is a mode of the module where a set of commands (AT Commands) are used to setup and configure the module. In this mode, the module can’t be detected by other Bluetooth Devices. For this mode take Key pin to HIGH. All the Commands are sent to the module serially as a string. This string must be capital letters (case sensitive) and each command should be ended by “rn”. If the command is successfully understood by the module, the module will reply back with a response string usually contains the string “OK”. Otherwise, the module returns back the error string “ERROR()” with a specific code that defines the type of this error.
- Connection Mode.
In this mode the device can directly communicate with other devices. We can search this device on other devices and can connect via entering the passkey. The default passkey is ‘1234’. In this mode we cannot change its configuration serially, but can only communicate with it. Key pin should be NC for this case.
You can use any of your favorite microcontrollers, but the condition is it should be having atleast one serial port. I am taking widely used PIC microcontroller as an example here. The device code is PIC 16F887.
For that purpose i needed to configure my HC-05 first to be able to communicate with microcontrollers. Because the default baudrate of module was 38400 hence not easy to direct communicate with microcontroller. So i changed few of settings of HC-05 and changed its baudrate. I did it via my Laptop and a USB to TTL converter. You may use any it of any type such as FTDI, Prolific PL2303 or Scilab CP2021. Then we need a terminal program at Laptop side. For the i used RealTerm. You can use Putty, Terminal or HyperTerminal even. If you want download links for them here are some of them:
Then connect as per shown below
The connections between HC05 module & the USB converter are simple as below :
HC – 05 MODULE USB-TTL MODULE
VCC ——> 5.0V
GND ——> GND
TXD ——> RXD
RXD ——> TXD
KEY ——> 5 V
So now we will be entered into the AT mode.
Then Open real term and connect the respective COM port with 38400 Baudrate.
Enable CR and LF after each line. Then in transmit window
Send ‘AT’. Then it should reply as OK if everything works fine.
Further you can check its version with command ‘AT+VERSION’. You can get its device address with ‘AT+ADDR?’. But our priority is to check the baudrate first. So enter ‘AT+UART?’ Then it replies as
Param1: baud rate( bits/s) value (Decimal)
Param2:stop bit: 0 —-> 1 bit
1 —-> 2 bits
Param3: parity bit
0 —-> None
1 —-> Odd parity
2 —-> Even parity
We have to set as 9600 baud rate 1 stop bit hence now we will set this configuration.
To set baudrate the syntax is ‘AT+UART=<Param>,<Param2>,<Param3>’
Hence we will send ‘AT+UART=9600,0,0’
So now our module is ready to be connected to microcontroller so remove HIGH logic at Key pin to exit AT mode. Now we are ready to work with microcontroller. Here the schematic is shown with one 16×2 LCD and a serial port connection.
Our task is to type a message on Android device and it should be displayed on LCD of our Hardware. So Lets see the PIC microcontroller program for that below. Later on we will download app for Android to communicate.
//Initialize USART with baud rate 9600
TRISD = 0x00;
USARTWriteString(“Hii.. Bluetooth is readyrn”);
//Get the amount of data waiting in USART queue
uint8_t n= USARTDataAvailable();
//If we have some data
if(ch == ‘n’)
Like we use the Hyperterminal utility to send data over serial in PC, there are similar kind of very useful apps for smartphones also. But they send this data over Bluetooth to other devices. Most of platforms are having this kind of apps. I am focusing on Android here. Phone which i tested was Micromax Canvas HD (Model No: A116) It runs on Android Jelly Bean. But generally speaking most of android phones are capable to do it via these apps.
I used the app called ‘Bluetooth Terminal’ Checkout at PlatStore: https://play.google.com/store/apps/details?id=ptah.apps.bluetoothterminal&hl=en . Check the logo below
Download the app and follow on screen instructions. Now search devices, You will find device named as ‘HC-05’. Connect it with.
Now reset your microcontroller.On your mobile app ,you should see the text as ‘Hii.. Bluetooth is ready’.
Now type any message on your screen and the press send the text will be displayed on the LCD of our hardware board.
See the final view in the app: