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


Schematic for Trasparent data mode

/media/uploads/edodm85/ch05_sch2.png


Test Code for Trasparent data mode

#include "mbed.h"

Serial pc(USBTX, USBRX);
Serial blue(p9,p10);          // HC05
DigitalOut myled(LED1);
DigitalOut myled4(LED4);


int main() {

    blue.baud(9600);
    pc.baud(9600);

    // echo back characters, toggle the LED
    while (1) {
        if (blue.readable()) {
            pc.putc(blue.getc());
            myled = !myled;
        }
        if (pc.readable()) {
            blue.putc(pc.getc());
            myled4 = !myled4;
        }
        
    }
}


Output for Trasparent 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: baund 38400; 1stop bit and no parity.

» Import this 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


Please login to post comments.