Contacts

What is a bluetooth module? Hc 06 bluetooth module connect win 7

Bluetooth whistle for computer: http://ali.pub/2jfj3y

First, let's understand what bluetooth is.

Bluetooth(from the words English blue - blue and tooth - tooth; pronounced /bluːtuːθ/), bluetooth- production specification of wireless personal networks ( Wireless personal area network, WPAN). Bluetooth allows the exchange of information between devices such as personal computers (desktops, pockets, laptops), mobile phones, printers, digital cameras, mice, keyboards, joysticks, headphones, headsets on a reliable, free, ubiquitous short-range radio frequency. Bluetooth allows these devices to communicate when they are within a radius of up to 10 m from each other (the range is highly dependent on obstacles and interference), even in different rooms.

Now knowing that bluetooth is used to build networks and exchange data between devices, we will use it to connect a CNC (CNC) machine and a computer or phone or tablet and laptop to each other.

Since I use the grbl firmware on the arduino platform to control the CNC, we will connect a bluetooth module suitable for arduino to the machine, namely the HC-06 bluetooth module.

Before connecting the Bluetooth module to the arduino, you need to make sure that the bluetooth module and arduino work at the same COM port speed.

If you are using grbl 0.8 firmware, then nothing needs to be changed, but if grbl 0.9 and higher, then the speed of the arduino COM port will become 115200, and the default speed on the module is 9600.

So we need to change the port speed on the bluetooth module itself.

To configure Bluetooth modules, there are special AT commands, with which we can set the necessary parameters of the module.

With AT commands, we can change the speed of the COM port or change the name of the Bluetooth device or find out or change the pin code for pairing.

In order to connect the bluetooth module to a computer to enter AT commands, we need an FTDI programmer, a link to it at the beginning of the article. I think the connection diagram is unnecessary here. You need to connect gnd to gnd, 5v to 5v, rx to tx and tx to rx.

After connecting, we need the HMComAssistant program to enter AT commands and program our module. Download: https://yadi.sk/d/eVzPmnh63Wab5R

Well, here I will give some AT commands to change the settings of the bluetooth module:

AT command Module response A comment
AT OK It is used to check the connection, as a rule, before performing any operations, this command is first used to check the connection.
AT+BAUD1 OK or OK1200 Sets the baud rate to 1200 baud
AT+BAUD2 OK or OK2400 Sets the baud rate to 2400 baud
AT+BAUD3 OK or OK4800 Sets the baud rate to 4800 baud
AT+BAUD4 OK or OK9600 Sets the baud rate to 9600
AT+BAUD5 OK or OK19200 Sets the baud rate to 19200 baud
AT+BAUD6 OK or OK38400 Sets the baud rate to 38400
AT+BAUD7 OK or OK57600 Sets the baud rate to 57600 baud
AT+BAUD8 OK or OK115200 Sets the baud rate to 115200 baud
AT+BAUD9 OK or OK230400 Sets the baud rate to 230400 baud
AT+BAUDA OK or OK460800 Sets the baud rate to 460800
AT+BAUDB OK or OK921600 Sets the baud rate to 921600
AT+BAUDC OK or OK1382400 Sets the baud rate to 1382400
AT+NAME +NAME=test Returns the current module name
AT+NAMEiarduino_BLU +NAME=test OK Sets the new module name to “test“
AT+PIN +PIN=000000 Returns the current password, in this case the password is "000000"
AT+PIN123456 +PIN=123456 OK Set a new password, in this case the password is “123456”
AT+VERSION +VERSION=Firmware V3.0.6,Bluetooth V4.0LE Returns the firmware version, in this case the password is “Firmware V3.0.6,Bluetooth V4.0 LE”
AT+RESET +RESET OK
AT+HELP ——– Returns a list of all available AT commands

After changing the speed of the com port and setting the pin code for pairing. (default pin code for pairing is “1234”, let's connect the module to arduino.

And since I use CNC shield v 3.0. Then I will bring the connection diagram to it.

I will not create my own scheme, but I will take it from one article. May the creator forgive me.

The scheme is certainly not very smooth, but in my opinion it is quite understandable.

So what are resistors used for in a circuit? The arduino has 5 volt logic, which means that the arduino sends 5 volts to all its outputs. But the module says LEVEL 3.3v, which means that Bluetooth requires 3.3V, but not 5v. Therefore, resistors are connected to lower the voltage and prevent the bluetooth module from failing.

But I decided to use it directly without resistors, let's see how long the module lasts, we'll arrange some kind of crash test.

To control the CNC (CNC) machine from a phone or tablet, I used the “Grbl controller” program, it is free and quite multifunctional. In the video below, I briefly showed how the machine is controlled from this program.

But if you connect from a computer, then there is a nuance, when pairing the connection with the module, two new COM ports will appear in the devices. I have COM6 and COM7. So one of them is used to send data, and the other to receive. Therefore, it is unnecessary to be scared and just try to connect to one; if nothing happens, then connect to another.

But if something is not clear, but clearly I showed it in the video:

For wireless exchange of information between different devices over short distances, you can use Bluetooth technology. For these purposes, the Chinese industry produces various Bluetooth modules, among which the HC-05 and HC-06 models are widely popular. At one time, I bought an HC-06 on Aliexpress, on which I will conduct further experiments, as well as connect it to my Chinese counterpart Arduino.

The Bluetooth module itself. In this form, it can be used in various devices, where it is soldered directly to the board. The module has 34 outputs, including: outputs for connecting to a computer via UART, audio transmission using the PCM method (pulse code modulation), analog input and output, contacts for connecting to a USB connector, SPI interface, and general purpose ports. In fact, not all of these outputs are available for use, access to audio transmission outputs (5-8), analog input and output (9, 10), as well as to the group of contacts for connecting to USB (15, 20) is blocked.

HC-06 is based on BC417 chip (BlueCore4-External device), Bluetooth V2.0 specification. On board there is also a 26 MHz quartz and 8 MB flash memory. Power is supplied from 3.3V.

For your designs, it is most convenient to use a module with a breadboard, on which the necessary contacts for connections are displayed, and there is also a voltage regulator that allows you to power from 5 volts.
When buying such modules, you may encounter their various markings. In fact, this is the same device, differing in firmware, which determines the module mode (master / slave).

The difference between HC-05 and HC-06 is that HC-05 can be used as a slave (master) or master (slave). These modes are set using AT commands. A button on the module board switches it to the AT command input mode. The master mode allows the module to detect such a device itself and organize communication with it. The HC-06 module can only work in one fixed slave mode.

There are also models HC-03 and HC-04, but they are produced for industrial purposes.

Designation of pins on the HC-06 board.

STATE- checking the status of the module. On this contact, the signal is duplicated, which displays the LED built into the board. If it blinks very quickly, then the module is in an active state. In the communication mode, the current is 30-40 mA. When the module establishes a connection with another device, the LED just lights up. In data transfer mode, the current is 8 mA.
RX- receiving data.
TX- data transfer.
GND- connected to ground.
+5V- power supply +5 Volts
EN- enable/disable the module. If a logical 1 (5 volts) is applied to this contact, the module will turn off, if a logical 0 is applied or not connected to this contact, the module will work.

By default, the HC-06 has a name to be discovered by other devices " HC-06”, with the pin code “ 1234 ».

To change these data, you need to connect the module to a computer and enter AT commands using the terminal program. This can be done with a USB to COM adapter with TTL levels. For these purposes, an adapter for PL2303HX, CH340G, or another similar one is suitable. At this point, the driver for the USB adapter should already be installed on the computer.

Contacts are connected as follows:

HC-06 USB to COM adapter
+5V +5V
GND GND
RX TX
TX RX

When this assembly is connected to a computer, the red LED on the Bluetooth module board will begin to blink rapidly. To enter AT commands, you can use any terminal program, I use the Arduino IDE for this purpose.

In the settings, select the number of the virtual COM port on which the USB adapter is connected, in my case it is COM44. Open the window " Serial Monitor».

Enter in capital letters the command " AT", if the device connected successfully, the response should return " OK". The default baud rate is 9600 baud.

To check the firmware version, enter the command " AT+VERSION", in my case the response returned " OKlinvorV1.8».

Team " AT+NAMEyyy", Where uuu- an arbitrary set of characters in Latin, we can change the name by which our bluetooth device module will be found (by default HC-06). In my example, I entered " AT+NAMEfox”, the response is returned OKsetname.

Team " AT+PINxxxx", Where xxxx- an arbitrary set of numbers, you can change the pin code (by default 1234). The response is " OKsetPIN».

Team " AT+BAUDx", Where x– value from 1 to 9, you can change the baud rate (by default 9600).

1 - 1200
2 - 2400
3 - 4800
4 - 9600
5 - 19200
6 - 38400
7 - 57600
8 - 115200
9 - 230400

Let's say if we run the command " AT+BAUD8”, where 8 is the speed of 115200 baud, the response will return “ OK115200».

Connecting HC-06 to Arduino.

Example 1 Let's upload a sketch to the Arduino, with the help of which we will turn on and off the LED wired on the 13th pin of the Arduino via the Bluetooth module.

intdata;
int LED = 13;
void setup()
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH);
}
void loop()
{
if(Serial.available())
{
data = Serial.read();
if (data == "1")
{
digitalWrite(LED, HIGH);
}
if (data == "0")
{
digitalWrite(LED, LOW);
}
}
}

If you do not have this LED on the board, connect it to pin 13 according to the diagram, resistor values ​​can be taken from 220 Ohm to 1kOhm.

Power off the Arduino and connect the HC-06. Contact TX connect the module to the contact RX Arduino (pin 0 on the UNO board), and the pin RX, to contact TX(pin 1). Contacts +5V And GND, are connected to the corresponding Arduino pins.

Assembled structure. After powering up the Arduino, the LED on the HC-06 should blink quickly.

Arduino control via HC-06, using a computer.

I will show an example on Windows XP. Any USB Bluetooth adapter must be connected to the computer and drivers installed on it.

In my case, I used this adapter.

When it is connected to a PC, a corresponding icon appears in the tray (near the clock).

Right-click on this icon and select " Add Bluetooth device».

Put the switch " Device installed and ready to be discovered» and press « Further».

Our Bluetooth module will be displayed in the list of discovered devices, with the new name that I changed earlier. Select it and click " Further».

In the next window, enter the pin code to connect to the module by selecting the item " Use the access key from the documentation:». The default is "1234" but I changed it to "9999". Press " Further».

The Bluetooth module has successfully contacted the computer, which can be found in the corresponding window. It should be noted that when a connection is established between two Bluetooth devices, two new virtual COM ports will be created on the computer (will be displayed in the device manager), one for outgoing data, the other for incoming data. We need a port for outgoing data, in my case it is COM45.

Reopen some terminal program, I'll use the Arduino IDE. In the settings, select the outgoing port (I have COM45), open " Serial Monitor", enter the commands " 1 " And " 0 ". When command "1" the LED lights up, when "0" goes out.

Control Arduino via HC-06 with Smartphone.

Probably all modern smartphones already have built-in Bluetooth. It remains only to install the terminal program. In my case I used Lumia 640DS, with installed Windows mobile 10. I use "" as the terminal program. On Android smartphones, everything is the same, you can use “ Bluetooth Terminal».

For owners of Apple smartphones, it will not be possible to work with Bluetooth modules HC-05 and HC-06 (Bluetooth V2.0), they will have to use adapters with BLE technology (Bluetooth low energy), Bluetooth 4.0 specification. A prominent representative is the HM-10 module.

Pairing HC-06 with smartphone bluetooth.

1. In " Parameters"smartphone, select the item" Devices».
2. Next " Bluetooth and other devices».
3. Turn on the bluetooth of the smartphone with the slider and click on " plus squared» to search for and add a new Bluetooth device, in our case HC-06.

4. In the section " Add device» choose «».
5. The smartphone will search for Bluetooth devices in the area and display their names. In my example, the HC-06 module was found, which I renamed to " Fox».

6. Enter the pin code of the device to which we are connecting, press the button " connect».

Install and run the terminal program "". The HC-06 module connected to the smartphone is displayed in the list, select it.

A field for entering commands and a button for submitting will appear. Enter alternately " 1 " And " 0 "and watch the LED on pin 13, which will turn on or off.

Example 2. Let's connect three LEDs to the Arduino and try to control them through the HC-06 Bluetooth module.

I connected the LEDs to pins 9, 11 and 13, if you use other pins, you need to specify them in the sketch.

intdata;
int LED1 = 9;
int LED2 = 11;
int LED3 = 13;
void setup()
{
Serial.begin(9600);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
}
void loop()
{
if(Serial.available())
{
data = Serial.read();
if (data == "1")
{
digitalWrite(LED1, HIGH);
}
if (data == "2")
{
digitalWrite(LED1, LOW);
}
if (data == "3")
{
digitalWrite(LED2, HIGH);
}
if (data == "4")
{
digitalWrite(LED2, LOW);
}
if (data == "5")
{
digitalWrite(LED3, HIGH);
}
if (data == "6")
{
digitalWrite(LED3, LOW);
}
}
}

When uploading the sketch, the HC-06 module must be disconnected from the Arduino, because both the computer and the bluetooth work via UART. Arduino cannot work with several devices on one UART.

We launch the terminal program and try the sketch in action. The meaning of LED control is as follows, there are three LEDs, each of which can be either on or off. It turns out 6 teams. Teams are numbers from 1 to 6 ( 1, 3, 5 - light 1, 2 and 3 LEDs. 2, 4, 6 - to repay). Numbers can be entered one at a time or in combinations. For example: 145 - light the first, extinguish the 2nd, light the 3rd.

Example 3. Let's connect the relay module from the article "" to the Arduino and try to control a powerful load via Bluetooth. In fact, we get a "smart outlet". Various loads (light bulbs, pumps, fans) can be connected to the relay modules and controlled from a distance.

Sketch for this example will appear in the near future.

Do you need to remotely control your Arduino board, communicate with other bluetooth devices? Bluetooth modules HC-05, HC06 will help to cope with this task.

In the first part of the article, we will talk about how to establish a wireless connection between the Arduino and the computer, and in the second part, how to establish a connection between the Arduino and the Android phone. .

This article will be an integral part in the further assembly of a remotely controlled car.

Components to repeat (buy from China):

Modules HC-05/06 are bare bluetooth with additional strapping.

Namely: they are installed on a substrate on which a stabilizer from 5 to 3.3 Volts is located, an LED indicating the state of the module (connection is formed or not), and capacitors on the power lines. The board also has a mosfet transistor (Q1), which, if necessary, can break the bluetooth power circuit, thereby turning it off, but this will not be used in our review.

From the front side, the module looks like this

Connecting to Arduino

Bluetooth HC-05/06 Arduino
VCC +5V
GND GND
TX RX
RX TX

When power is applied to the module, the built-in LED starts flashing.

1) With a computer (OS WIN7)

2) With a phone (ANDROID operating system)

In both cases, we will need to execute 2 actions: perform pairing of the module and device, control through any terminal.

Part 1. Connecting to a Computer (WIN7)

If your computer does not have built-in bluetooth, then you can use. It is not difficult to find it in communication salons or on radio markets.

After installing the drivers for the bluetooth, you can get to work.

. Action 1

Go to the control panel, click on the bluetooth icon and select "Show Bluetooth devices"

After a while, the computer will search and you will see your module (Your module may have a different name).

We select the second option - "Enter the pairing code of the device"

For HC-06 this code is 1234

It all ends with such a picture.

And after him another

First stage of setup completed

In case you forget which COM port your bluetooth is defined on, you can always see it by doing the following:

Actions

P.S. Or look in device manager

. Action 2

Any terminal can be used to transfer data. I used the simple and free "Termite".

As an example, we will change the state of the LED "LED 13" built into the Arduino board. It will turn on when the character "W" is received, and turn off when "S". The sketch below needs to be uploaded to the Arduino board. When pouring into the board, you must disconnect the power from the bluetooth module, reconnect after pouring.

code example:

int value; int LED = 13; void setup () { Serial.begin(9600); pinMode(LED, OUTPUT); ) void loop() ( if ( Serial.available()) ( val = Serial.read(); // At the symbol "W" turn on the LED if (val == "W" ) ( digitalWrite (LED, HIGH ); ) // At the symbol "S" turn off the LED if (val == "S" ) ( digitalWrite (LED, LOW ); ) ) ) Open the program " Termite"

In the settings, select our port, speed (9600).

Also, the module can be checked without Arduino by simply shorting the TX and RX pins. Termite send characters are marked in blue, received in green. Those. if we sent with shorted outputs and we received the same thing, it means that the module is working properly. The photo below demonstrates this.

Part 2: Pair with Phone (Android)

The Samsung Galaxy Ace 2 phone on the Android operating system will be taken as a test subject.

. Action 1

Connecting with phone

. Action 2

As a terminal, we will again choose a simple and free, but already "Bluetooth Terminal"

P.S. If you cannot connect, turn off the bluetooth power and connect again.

Very often in your projects there is a need for remote control or data transfer from your phone gadgets.

One of the most popular and widespread methods of data exchange via Bluetooth .

Today we will analyze simple examples of how you can connect Bluetooth. module to Arduino and set up remote control from your phone.

We will need:

  • Set of wires FATHER-MAMA
  • HC-06 Bluetooth

Connect Bluetooth the module to the Arduino microcontroller is most conveniently using the PAPA-MAMA wiring.

Arduino Bluetooth
Pin 1 (TX) RXD
Pin 0 (RX) TXD
GND GND
5V VCC

Be careful, you need to connect TX -> RXD ,RX -> TXD .

Now you need to write a test program code:

When uploading the sketch, it is necessary that the Bluetooth module is disconnected from the arduino microcontroller. Otherwise, the sketch will not be recorded, because the connection with Bluetooth module occurs on the same RX and TX port as USB.

intval; int LED = 13; void setup() ( Serial.begin(9600); pinMode(LED, OUTPUT); digitalWrite(LED, HIGH); ) void loop() ( if (Serial.available()) ( val = Serial.read(); / / At the character "1" turn on the LED if (val == "1") ( digitalWrite(LED, HIGH); ) // At the character "0" turn off the LED if (val == "0") ( digitalWrite(LED, LOW ); ) ) )

After the sketch is recorded and Bluetooth the module is connected to the Arduino, you can proceed to the next step.

Bluetooth connection to phone

It is advisable to use not USB as a power source for arduino, but an external 9 V power supply.

  1. Turn on Bluetooth on your phone and look for new devices
  2. We find in the list of disorders " HC-06" and connect to it.
  3. The phone will ask for a pin code. you need to enter " 1234 " or " 0000 "
  4. Hooray. The device is connected.

Now you need to download the bluetooth terminal on your phone. We will look at the example of the Android platform.



You can install different bluetooth terminals, as a rule they differ only in different designs, the functionality does not change from this. You can also find a terminal for ios products.

After we have installed the terminal, we launch it, select our bluetooth module HC-06 and connect to it.

It's time to try the project in action. We write the number "0" in the terminal and send. The L LED next to pin 13 on the arduino board should turn off. Now we will send the number "1" through the terminal and the LED L should light up.

Work demo:


Homework:

  • Change the sketch so that the LED turns on and off with the same command for example "G".
  • Add a sketch and teach it how to convert text data coming through bluetooth into digital data and implement a dimer, turn on the LED using PWM, to a given brightness from 0 to 254 coming through bluetooth.

Arduino has a large number of various modules that can significantly expand the functionality of the microcontroller. Chips for data transmission are allocated in a separate class, both over a long distance, for example, for wireless Internet communication, and over a short one, like a bluetooth module. Such a device is designed to establish bidirectional radio communications using the protocol of the same name.

Arduino bluetooth will be handy for remotely controlling your device based on a microcontroller, but let's look at what it is and what are the characteristics of the hc 05 and hc 06 bluetooth modules.

Bluetooth protocol is necessary for fast data transfer over short distances. But much more often it is used in projects in order to control the microcontroller from close distances. Accordingly, it will be convenient for building the same smart homes if the hardware component is supplemented with an application on a smartphone.

Thus, the primary and main purpose of Arduino bluetooth is communication with your PC and / or Android using the appropriate protocol. This allows not only to control a variety of sensors on the microcontroller, but also, if necessary, update the firmware.

It will not work to completely reflash the device with it. In addition, Android Arduino bluetooth can provide communication between multiple MCUs and devices. Naturally, for this, an independent module must be installed on each of them. HC-05 allows you to lay multiple bridges of the USAR-bluetooth-USART type. In this case, the device itself will be perceived as a response to USART. And the hardware part of your project will already organize the connection.


The bluetooth module for Arduino has several advantages over standard add-ons for other MKs:

  1. An engineer does not need to learn the technology of the bluetooth protocol in order to write software or start using ready-made libraries.
  2. Ease of use in general. You will not need to solder a separate board for power distribution, just connect the device to an already finished MK through the pins.
  3. Extensive selection of libraries. Since Arduino has a low entry threshold, a large number of libraries for various purposes can be found for all its modules. But it is worth noting that a significant part of them are useless, because they do not work or work extremely poorly. After all, their community writes, which has not studied the basics of algorithmization and, for the most part, in principle, is poorly versed in programming. Because of this, in many situations, simply modifying someone else's software is not the best solution, and it is much easier to write your own.

The scope of the RC car Arduino bluetooth is huge and limited only by your imagination. For example, you can buy an ordinary Chinese headset, solder a couple of Arduino modules to it, since they can function without a MK, and load one of the ready-made libraries. After such manipulations, the headphones can be used in wireless mode and the problem with tangled or bending wires will disappear. This is one of the banal problems of implementing this protocol in a project, in fact there are thousands of them.

The bluetooth audio module is intended for domestic and commercial use, which is facilitated by its characteristics. It is also worth considering that if you are going to continue to communicate using the protocol of the same name with a PC, then on most modern devices you will need to purchase bluetooth via USB. But you can also solder it from the MK by creating your own bluetooth module for the computer. Naturally, this does not apply to laptops, where transmitters of the same name are installed without exception, and it is no longer necessary to modify them in any way.

Pinout HC-05 and HC-06

The board pins are responsible for:

Characteristics

Let's take a closer look at what characteristics such a bluetooth module has for a PC and various projects. The developers themselves claim that they have withstood the commercial standard in hc 05. Accordingly, a special program on a smartphone or computer will be enough to control the device, which will allow you to send and receive data from the sensor. However, there is a limitation in the field of application, because a stable signal, without the use of amplifiers, can be caught only 9 meters from the chip. Keep in mind that these are raw numbers, which do not take into account the obstacles in the path of the waves.

The hc chips themselves are fully compatible with any adapter that supports SPP. On the device board itself, there is a small antenna soldered to the top layer in the form of a snake-like track. The specifications of the device are as follows:

  1. Active radio frequencies are in the range of 2.4-2.48 GHz.
  2. The channel is adapted for adaptive switching.
  3. The conditional communication range is 10 meters, but this figure does not take into account obstacles and interference.
  4. The maximum speed for information exchange is 115300 baud.
  5. You can store the chip in the temperature range from -40 to +85 degrees, but use it from -20 to +70.
  6. To work, you will need a voltage of 3.3 V, which we will consider below.

Connection

The printed circuit board has several solder contacts at the ends of the device. But you should not directly connect the wires to the contacts of the device, because the board uses a special technology that allows you to squeeze the dimensions of the device into your system as compactly as possible.

It is necessary to install the module tightly enough, for which a standard MK or special boards that use plug connectors are suitable. But you can also purchase a separate board for hc series devices, or make them yourself if you have the skills to design and create electronic boards.

In such a device, there must be a connector / special holes for wiring, as well as LEDs that will help determine whether current is flowing and whether the device is working. Among other things, you need stabilizers, a special switch for resetting the firmware and interface converters, according to your desire.

When connecting for the first time, it is important to check the performance, a smartphone or PC is suitable for this. Just apply current to the module and scan it with the appropriate devices.

Setting

To set up the chip, you will need to establish pairing via USART-bluetooth, where pin 34 will be connected to a common wire. After that, you can issue standard AT commands or reflash the microchip, as you wish.

Out of the box, the password for connecting the interface is 1234, but the data exchange rate is limited to 38400 baud. There are not many ready-made libraries on HC 05, but the direction of its application is quite narrow, which allows you to adapt any existing software to your needs.



Liked the article? Share it