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

  • Bluetooth HC-05
  • BlueTerm (this is a free app for android and you can found it in the Google Play market)


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).


Test Code for Transparent data mode

Import programHC05_Transparent_mode

Transparent data mode for Bluetooth HC05



Output for Transparent data mode

First you must enable Bluetooth on your telephone. Search the bluetooth device and pair with it (the password is 1234). Then open BlueTerm and select the device.

/media/uploads/edodm85/screen_blue2.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.1
Is required Microsoft .NET Framework 3.5 or above.

Screen:

/media/uploads/edodm85/hc05screen1.1.jpg



UPDATE:

U1: Updated the HC05 Test Software


Report

4 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.

Please login to post comments.