Arduino and Bluetooth modules HC-05/06

Bluetooth is one of the most common short-range wireless communication protocols for personal electronic devices. It uses various input and control devices, audio devices.
arduino-and-hc-05-hc-06-3

Bluetooth is one of the most common short-range wireless communication protocols for personal electronic devices. It uses various input and control devices, audio devices.

Against the rest of the Bluetooth protocols, it stands out above all for its noise immunity and simplicity. From no less widespread Wi-Fi Bluetooth differs primarily in low power consumption, which makes it available for stand-alone devices. Thanks to this, BT has become ubiquitous.

Most often, BT-modules HC-05 and HC-06 are used for homemade products. They are easy to find on sale. The HC-05 differs from the HC-06 in that both modes of operation are available: slave (master) and master (slave). But the HC-06 works only as a slave, that is, it is not able to find other devices and independently communicate with them (but this can be corrected).

Both modules are based on the same chip and support BT version 2.0. Their maximum speed is 3 megabits per second.

SMALL REVIEW OF MODULES HC-05 AND HC-06
Most often, HC-05 and HC-06 are two soldered boards. Upper – factory board with BC417 chip. The bottom one is a special board for improvised devices, containing the most needed GPIO legs with a 2.54 mm pitch, a voltage stabilizer, and a reset button. In the photo below is the board with BC417:

These are the modules HC-05 and HC-06 together with the substrate:

HC-05 is not much more expensive than HC-06. But at the same time, it can work in both modes right out of the box. HC-06 will have to tinker to make it work as a master.

There are a few other versions of the modules. Instead of EN output, KEY is displayed on them.

PINOUT

  • EN – power management;
  • VCC – power supply from 3.6 to 6 V;
  • GND – land;
  • RX, TX – UART interface;
  • STATE – work indication;
  • KEY – activation control mode using AT-commands.

Modules are configured using AT commands. But pin KEY is not on all modules. And what to do with it?

Pin KEY is, of course, present on a small board with a large number of contacts, but not divorced from a large one. The reasons for this strange decision of the Chinese are unknown.

This contact is here:

CONNECTING HC-05 AND HC-06 TO ARDUINO
Connection to the Arduino is made by the following contacts:

  • GND – GND;
  • VCC – + 5V;
  • TX – 10;
  • RX – 11;

KEY during normal operation of the module is not used. To switch to AT mode, it must be connected to + 3.3V.
TX and RX are connected to pins 10 and 11 because the hardware UART will be used to communicate with the computer.

AGREEMENT OF LOGICAL LEVELS

Bluetooth-modules work with logic levels of 3.3 V, and the use of five-volt logic can disable them. But most often the board has everything you need to coordinate the levels.

There are situations in which Arduino TX – Bluetooth RX voltage matching is necessary. The use of the divider is a guarantee of reliable operation.

On the right is the simplest divider diagram:

#include
#include

int gLedPin = 13;
int gRxPin = 10;
int gTxPin = 11;

SoftwareSerial BTSerial(gRxPin, gTxPin);

void setup() {
# 38400 – для метода №1, 9600 – для метода №2
BTSerial.begin(38400);
Serial.begin(9600);
delay(500);
}

void loop() {
if (BTSerial.available()) {
Serial.write(BTSerial.read());
}
if (Serial.available()) {
BTSerial.write(Serial.read());
}
}

Terminal Setup:

They can serve as a standard tool for Arduino development environments — a port monitor. I worked with the terminal TeraTerm. We configure the following parameters:

  • Serial port speed: 9600;
  • Line feed: CR + LF.

TeraTerm after configuration looks like this (port number may vary):

All the following steps are divided into the slave setup of the HC-06 module and the master module of the HC-05 module.

HC-06: when power is on, the power indicator will start blinking:

We send a verification command through the terminal to the module:

AT
In response, you will come:

Ok
This team can find out the version of the module:

AT + VERSION?
Answer:

OKLinvor1.5
If something is wrong, check back:

  • Connection speed Choose 9600.
  • The new line should be indicated by the combination “CR + LF”.

HC-06 has only three adjustable parameters:

Change Password:

AT + PIN
Speed change:

AT + BAUD
Change the name of the module displayed when it is searched by other devices:

AT + NAME
Setting example: to change the speed to 9600, we write:

AT + BAUD9600
Change the settings to the desired. The module is waiting for a connection with a slave device, for example, a smartphone.

When setting up the HC-05, you first need to activate the setting mode. This requires a KEY pin.

The first way:

  • Turning off the power supply;
  • We connect pin KEY with power supply 3.3 V;
  • We supply power to the module.

The speed of the serial port will be 38400 baud / s.

The second way:

  • Supply power to the module.
  • Connect the pin KEY to the power source 3.3 V.

Set the speed selected in the settings in advance. The default is 9600.

The power light will blink.

Now we send the same commands with which the last module was checked. The difference will be only in the version: the answer will be “+ VERSION: 2.0-20100601”.

Using HC-05 as a slave:
Reset:

AT + ORGL
Clearing memory from connected devices:

AT + RMAAD
Change Password:

AT + PSWD = 4321
Activate slave mode

AT + ROLE = 0
This command allows you to find out the device address:

AT + ADDR?
After the done manipulations, disable the KEY pin and reset the module.

Using HC-05 as a lead:
Reset:

AT + ORGL
Clearing memory from connected devices:

AT + RMAAD
Activate master mode:

AT + ROLE = 1
Reboot:

AT + RESET
To connect the two modules, do the following:

Put the password on the slave module:

AT + PSWD = 1234
Specify the slave module’s address and timeout to the master module:

AT + PAIR = ,
Example:

AT + PAIR = 12,6,143117, 5
Contact the slave module:

AT + BIND =
Example:

AT + BIND = 12,6,143117
We put a ban on connecting with other modules:

AT + CMODE = 0
That’s all. Now the master module will start connecting to the slave when power is applied.

Share on facebook
Facebook
Share on google
Google+
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on pinterest
Pinterest