HC-05 Bluetooth

Introduction

I bought this bluetooth module (HC-05 or BT400_B6) on ebay some weeks ago at very low price.

I decided to test it with an Android telephone.

This module is configured as Slave by default.


Required Components


Product Specifications

  • Chipset CSR BC417143
  • Bluetooth version V2.0+EDR
  • Output power Class II
  • Flash 8Mbit
  • Power Supply 3.3V
  • Size 26.9mm*13mm*2.2mm


Pin Description

/media/uploads/edodm85/1-881-.jpg


Connectivity

HC05 pinMbed pin
1 - TxP10 - Rx
2 - RxP9 - Tx
12 - 3.3VVout - 3.3V
13 - GNDGND
31 - PIO8--
32 - PIO9--
34 - PIO11GND or 3.3V


PIO8 is used to control LED indicating the status. It will blink after power on.

PIO9 is used to control LED indicating paring. It will be steady on when paring is successful.

PIO11 is used to set this two mode: AT command mode (if the pin is connect to 3.3V) or Automatic binding transparent data mode (if the pin is connect to GND). The AT command mode is used to configure some characteristics of the device (for example the Master, Slave or Loopback modes).


Code for Transparent data mode

Import programHC05_Transparent_mode

Transparent data mode for Bluetooth HC05



Example: Bluetooth communication between Pc and Android Phone

First you must turn on the Bluetooth on your Android phone.
Search the bluetooth device and pair with it (the password is 1234).

/media/uploads/edodm85/screenshot_20160716-182149_mod.png /media/uploads/edodm85/screenshot_20160716-182157_mod.png /media/uploads/edodm85/screenshot_20160716-182204_mod.png


Then open "Terminal Multi" and press the button "SEARCH" for select the paired device (HC-05).
In the end press "CONNECT".

/media/uploads/edodm85/screenshot_20160716-192539_mod1.png /media/uploads/edodm85/screenshot_20160716-192545_mod2.png /media/uploads/edodm85/screenshot_20160716-192558_mod1.png


Bluetooth Settings

/media/uploads/edodm85/screenshot_20160719-133456_mod.png


Output example

/media/uploads/edodm85/androidpc.png


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


AT command mode

In AT command mode you can configure and send control command to the HC05 device.

For enter into AT mode you must follow this steps:

  • Power off the mbed
  • Tie PIO11 to 3.3V (you can see it on the schematic below)
  • Power on the mbed
  • Open a serial monitor (Set the baud to 115200; choose "Both CR+LF" in the check box)


Schematic for AT command mode

/media/uploads/edodm85/at_mode_sch.jpg


Basic AT commands

CommandReturnParameterDescription
ATOKNoneTest
AT+VERSION?+VERSION:<Param> OKParam: Version numberGet the soft version
AT+ORGLOKNoneRestore default status
AT+ADDR?+ADDR: <Param> OKParam: Bluetooth addressGet module Bluetooth address
AT+NAME=<Param>OKParam: Bluetooth device nameSet device’s name
AT+NAME?+NAME:<Param> OKParam: Bluetooth device nameInquire device’s name
AT+ROLE=<Param>OKParam:0=Slave role; 1=Master role; 2=Slave-Loop roleSet module role
AT+ ROLE?+ ROLE:<Param>Param:0=Slave role; 1=Master role; 2=Slave-Loop roleInquire module role
AT+UART=<Param>,<Param2>,<Param3>OKParam1: baud rate( bits/s); Param2: stop bit; Param3: parity bitSet serial parameter
AT+ UART?+UART=<Param>,<Param2>,<Param3> OKParam1: baud rate( bits/s); Param2: stop bit; Param3: parity bitInquire serial parameter


Is possible to set this three modes:

  • Slave: Passive connection;
  • Master: Inquire the near SPP Bluetooth slave device, build connection with it positively, and build up the transparent data transmission between master and slave device;
  • Slave-Loop: Passive connection, receive the remote Bluetooth master device data and send it back to the master device.


Code for AT command mode

Important: The default setting of the serial port of HC05 is: baud 38400; 1stop bit and no parity.

Import programHC05_AT_mode

This program send an AT command to the HC05 module and shows the response into a terminal.


Output for AT command mode

/media/uploads/edodm85/at_mode.jpg


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


C# Test Program

You can download the program here: HC05 Test Software v1.2
Is required Microsoft .NET Framework 4.0 or above.

Screen:

/media/uploads/edodm85/screen_bt1.jpg


Select the correct COM Port and the BaudRate and press the "Connect" Button.

/media/uploads/edodm85/screen_bt2.jpg


/media/uploads/edodm85/screen_bt3.jpg



UPDATE:

U3: Added new Android Application (Terminal Multi)
U2: Updated HC05 Test Software and added new screens
U1: Updated the HC05 Test Software


16 comments on HC-05 Bluetooth:

21 Sep 2013
21 Jan 2014

Do you have the source available for the C# app? I would love to see how you're communicating with the device. Unfortunately, I can't run an exe directly (security risk).

Thanks a lot!

10 May 2014

Hi I have tried to communicate the bluetooth serial port from HC-05 for one of my project same as like the program you uploaded in this page (C# Test Program). I can search the available bluetooth devices in my range and also can pair with it. But i cannot connect through my C# program. In short words i have a HC-05 device that is sending the character "A" continuously via its serial port, i need to read that character and display it in a text field.

Here is my code blocks <br> private void btnSearch_Click(object sender, EventArgs e) { BluetoothRadio.PrimaryRadio.Mode = RadioMode.Discoverable; BluetoothRadio myRadio = BluetoothRadio.PrimaryRadio; lblSearch.Text = "" + myRadio.LocalAddress.ToString(); BtClient = new BluetoothClient(); Cursor.Current = Cursors.WaitCursor; BluetoothDeviceInfo[] bluetoothDeviceInfo = { }; bluetoothDeviceInfo = BtClient.DiscoverDevices(10); cmbDevicesFound.DataSource = bluetoothDeviceInfo; cmbDevicesFound.DisplayMember = "DeviceName"; cmbDevicesFound.ValueMember = "DeviceAddress"; cmbDevicesFound.Focus(); Cursor.Current = Cursors.Default; foreach (BluetoothDeviceInfo b in bluetoothDeviceInfo) { listBox1.Items.Add(b.DeviceAddress.ToString()); } }

private void btnPair_Click(object sender, EventArgs e) { if (cmbDevicesFound.SelectedValue != null) { try { BluetoothSecurity.PairRequest((InTheHand.Net.BluetoothAddress)cmbDevicesFound.SelectedValue, "1234"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }

private void btnConnect_Click(object sender, EventArgs e) { if (cmbDevicesFound.SelectedValue != null) { try { MessageBox.Show(cmbDevicesFound.SelectedValue.ToString()); InTheHand.Net.BluetoothEndPoint Ep = new Net.BluetoothEndPoint((InTheHand.Net.BluetoothAddress)cmbDevicesFound.SelectedValue, BluetoothService.SerialPort); bool t = false; BluetoothClient cli = new BluetoothClient(); cli.Connect(Ep); t = cli.Connected; MessageBox.Show(t.ToString()); MessageBox.Show("Connected"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }

Can you please help in this?

10 May 2014

Hi, if I understood you want to use a USB dongle or a internal Bluetooth of a PC for receive the data from the HC-05 device.
I never used the library 32feet.NET so I don't think that I can help you.
what kind of exception you have?

Manikandan Yemarajan wrote:

Hi I have tried to communicate the bluetooth serial port from HC-05 for one of my project same as like the program you uploaded in this page (C# Test Program). I can search the available bluetooth devices in my range and also can pair with it. But i cannot connect through my C# program. In short words i have a HC-05 device that is sending the character "A" continuously via its serial port, i need to read that character and display it in a text field.

12 Nov 2014

hey what is the exact AT Command for a master device to search its near by SLAVE device?? is it AT+INQ??

22 Nov 2014

Yes is AT+INQ

this command responds: +INQ:<Bluetooth address>,<device type>,<signal intensity>

darshana patil wrote:

hey what is the exact AT Command for a master device to search its near by SLAVE device?? is it AT+INQ??

01 Dec 2014

The HC05 Test Software would be great tool but it doesn't send out the required CR+LF characters at the end. You can easily check this with any terminal program. This program can only be used with the HC06 that doesn't require the CR+LF characters at the end.

06 Dec 2014

Hi Ernie, Yes my software doesn't send the CR+LF characters but the Bluetooth HC05 works without the CR+LF characters.

In next few days I will publish the new HC05 Test Software v1.2 with the possibility to add to the end of message the following characters None/LF/CR/CR+LF.

Edoardo

Ernie Horning wrote:

The HC05 Test Software would be great tool but it doesn't send out the required CR+LF characters at the end. You can easily check this with any terminal program. This program can only be used with the HC06 that doesn't require the CR+LF characters at the end.

07 Dec 2014

Andrew Pavlík wrote:

please i need some help i'll use this Bluetooth but i cant understand something can you help me pleas "very important" thank's

10 Dec 2014

I'm looking forward to the new version.

From the HC-05 User Instructions: "Command structure: all command should end up with “\r\n” (Hex: 0X0D X0A) as the terminator."

I tried without, using a terminal program and the modules that I have, definitely need the CR+LF characters appended.

Edoardo De Marchi wrote:

Hi Ernie, Yes my software doesn't send the CR+LF characters but the Bluetooth HC05 works without the CR+LF characters.

In next few days I will publish the new HC05 Test Software v1.2 with the possibility to add to the end of message the following characters None/LF/CR/CR+LF.

Edoardo

Ernie Horning wrote:

The HC05 Test Software would be great tool but it doesn't send out the required CR+LF characters at the end. You can easily check this with any terminal program. This program can only be used with the HC06 that doesn't require the CR+LF characters at the end.

13 Dec 2014

I understood, you are using my HC05 Test Software but not my mbed firmware that appends the "\r\n" character.

I uploaded the new version, give me a feedback. Thanks
Edoardo

Ernie Horning wrote:

I'm looking forward to the new version.

From the HC-05 User Instructions: "Command structure: all command should end up with “\r\n” (Hex: 0X0D X0A) as the terminator."

I tried without, using a terminal program and the modules that I have, definitely need the CR+LF characters appended.

16 Aug 2015

Hi All,

I have the Wireless Buzzband BT-88 which I'd like to trigger using the HC-05 combined with the Arduino. The Buzzband BT-88 device name is 'WATCHDOG' and its default pairing code is '0000'. Does anyone have any ideas where to start? Any help is much appreciated

Thanks.

15 Jul 2016

please tell me how can i use HC-05 with embed 1768 to receive the data from IMU LSM9DS1

18 Oct 2016

Hi there...! Im trying to do a project where I use a Geiger Counter to measure radiation on an autonomous electric vehicle. So by the time it drives around and meets objects that contain radiation as soon as it detects them I want it to wireless send the data on my android phone. Would that be possible using that?Please let me know. May I ask for an email as well? Thank you.

21 Oct 2016

Hi Alexandros,

First you need to receive the Geiger Counter datas with mbed.
Then you can send the datas to a phone over bluetooth.

Probably a problem is the maximun working distance of this bluetooth.

Alexandros Malatras wrote:

Hi there...! Im trying to do a project where I use a Geiger Counter to measure radiation on an autonomous electric vehicle. So by the time it drives around and meets objects that contain radiation as soon as it detects them I want it to wireless send the data on my android phone. Would that be possible using that?Please let me know. May I ask for an email as well? Thank you.

01 Feb 2019

Hello . I'm using HC05 and i need to send data(any text value) from my Android app to device . but i don't know how to pass data from App to this device . Any method or command you can suggest ?

Please log in to post comments.