HC‐05 bluetooth module is an easy to use Bluetooth SPP (Serial Port Protocol) module, designed for transparent wireless serial connection setup & can easily interface with Arduino. The HC-05 Bluetooth Module can be used in a Master or Slave configuration, making it a great solution for wireless communication, especially for Arduino. This serial port Bluetooth module is fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate) 3 Mbps Modulation with complete 2.4 GHz radio transceiver and base-band. It uses CSR Bluecore 04‐External single chip Bluetooth system with CMOS technology and with AFH (Adaptive Frequency Hopping Feature).
The Bluetooth module HC-05 is a MASTER/SLAVE module. By default the factory setting is SLAVE. The Role of the module (Master or Slave) can be configured only by AT commands. The slave modules cannot initiate a connection to another Bluetooth device, but can accept connections. Master module can initiate a connection to other devices. The user can use it simply for a serial port replacement to establish connection between MCU and GPS, PC to your embedded project, etc. Refer Datasheet/User Manual & AT command’s list.
- Typical ‐80 dBm sensitivity
- Up to +4Bm RF transmit power
- 3.3 to 5 V I/O and RoHS Compliant
- PIO (Programmable Input/Output) control
- UART interface with programmable baud rate
- Inbuilt/Integrated antenna
- Auto‐connect to the last device on power as default
- Permit pairing device to connect as default
- Auto‐pairing pin code: ”1234” as default (which can be changed)
- CSR Bluetooth Chip Solution
- Bluetooth Spec v2.0 EDR Compliant with V2.0.E.2 of specification for both 2Mbps and 3Mbps modulation modes
- Full Speed Bluetooth Operation with Full Piconet Support and Scatternet Support
- Support for 8Mbit External Flash On-board
- Support for 802.11 Coexistence
State: It is status indicator pin. When the HC05 is not connected to or not paired with any other Bluetooth device, signal at this pin goes Low. During this state the on-board LED flashes continuously which indicates that the module is not paired with any device. When HC05 is paired or connected with any Bluetooth device, the pin status goes High. During this state, on-board LED blinks with a constant delay say for example 2 seconds delay which indicates that the module is paired.
RXD: Receive pin of UART interface for communication
TXD: Transmit pin of UART interface for communication
GND: Ground pin
Vcc: Supply voltage of 3.3V or 5VDC
Key (or EN): When this pin is high, the module is disabled & will not be connected with any module. When this pin is open or connected to ground or kept open, the module is enabled & it can be connected/communicate.
Apart from pins, you will find a small push button on HC05. When you press the button for 1 second, HC05 will enable AT command mode. During AT command mode you can change different parameters of HC05, but while changing parameters the HC05 shouldn’t be connected/paired with any device.
Normally, people connects HC05 TXD & RXD to Arduino RX(D0) & TX(D1), but in that case if you want to upload any code using USB port then you have to remove connection from D0 & D1 otherwise you will get code upload error. To avoid this issue there is one best solution as library called ‘SoftwareSerial’. Using SoftwareSerial library we can configure any two DIO as Tx & Rx. In above connection diagram, HC05 Tx & Rx are connected to Arduino pins D10 & D11 which to be assigned as Rx & Tx respectively.
#include SoftwareSerial BTserial(10, 11);
Serial.println("Beat Your Bit");
BTserial.println("Beat Your Bit");
Explanation of code:
#include : As you can see SoftwareSerial library is included, it is available in Arduino IDE
SoftwareSerial BTserial(10, 11); : anyname(RX, TX); i’ve give name BTserial, D10 pin as RX & D11 as Tx
char data; : variable where incoming data will be stored, for better execution data will be first stored in a variable then will be processed.
Serial.begin(9600); begin serial communication with Arduino IDE
Serial.println(“Beat Your Bit”); print custom message on serial monitor to confirm serial communication has been initiated
BTserial.begin(9600); begin serial communication using dedicated pins (D10 & D11)
BTserial.println(“Beat Your Bit”); transmit custom message on HC05 paired device to confirm serial communication with HC05 has been initiated
if (BTserial.available()) [if any data available from HC05 then]
data=BTserial.read(); [store received data in ‘data’ variable]
Serial.print(data); [print received data on serial monitor of Arduino IDE]
if (Serial.available()) [if any data available from serial monitor then]
data=Serial.read(); [store received data in ‘data’ variable]
BTserial.print(data); [transmit received data on HC05]
As explained, this code exchanges data between HC05 and Arduino IDE serial monitor. We can see data received on serial monitor but to read the data received on HC05, we have to use an android app or any terminal application which can be connected with HC05 using Bluetooth. Here we are going to use android app to test Arduino-HC05 connection & data exchange. I used Arduino Bluetooth Control app which have many add on features & easy to use. It has serial terminal, arrow keys, buttons, slider, accelerometer & voice control features.
Connect circuit as shown in connection diagram, upload code and connect/pair HC05 with your smartphone. If you are using/pairing HC05 for first time then default pairing PIN may be 1234, you can change it later using AT commands. Open Arduino Bluetooth Control App & select paired HC05. Open terminal windows in app & serial monitor in Arduino IDE with mentioned baud-rate. Write any text in Arduino IDE serial monitor & press enter, you will receive same text in terminal window of Arduino Bluetooth Control app. Vice versa, write in app and send it to Arduino IDE serial monitor.
Change HC05 settings
You can change HC05 default settings like Bluetooth display name, pairing PIN, baud rate etc. As mentioned in Pin-out details, you have to put HC05 in AT command mode by pressing the push button while power up the module but make sure it is not connected with any other Bluetooth device.
How to put HC05 in AT command mode:
1. Disconnect HC05 form power, Remove the +5V connection to HC05.
2. Press and hold the push button switch on HC05
3. Re-connect HC05 Vcc to +5V (while still pressing the button switch), HC05 on-board LED should turn ON.
4. Release the push button switch and the LED should be blinking at interval of two seconds. It indicates that your are now in AT command mode. Now open serial monitor & give AT commands from there.
Some useful AT commands:
AT : Simple feedback request. If communication is working fine then it will return “OK”
AT+VERSION : This returns the firmware version.
AT+STATE : This returns the current state of the module.
AT+ROLE : Valid values are 0~Slave, 1~Master, 2~Slave-Loop.
(To change to Master Mode, enter AT+ROLE=1, returns “OK”)
AT+UART : It returns the baud rate used by the HC05 in communication mode. Default it will be 9600 mostly.
(To change the baud rate to 19200 : AT+UART=19200,0,0. Returns “OK”)
AT+NAME : The command AT+NAME? only works in AT command mode. If HC05 is not responding on AT+NAME? then put HC05 in AT command mode as procedure mentioned in tutorial.
Return when AT+NAME? is given:
(To change name : AT+NAME=BeatYourBit, Returns “OK”)
You can find all AT commands list from here.
I hope you liked this tutorial, now you can add Bluetooth interface in your project & expand the features. Further you can display values on display, data exchange with another wireless modules like RF & WiFi. Give your feedback about this tutorial in Contact, Your feedback will be appreciated.