Below I would like to present you a short description of the very popular HC-05master-slave Bluetooth module with the ZS-040 base board. It is a module for wireless Bluetooth communication, equipped with a UART interface and support for AT commands.
This module can be used, for example, for wireless two-way communication between a computer and an AVR microprocessor that supports the UART interface. Below I will describe the HC-05 module soldered to the ZS-040 adapter, where we have a six-pin connector, LED visualization (whether the module has been paired) and a monostable button. We have available pins: EN, VCC, GND, TxD, RxD, STATE. EN is used to turn off the module - applying the mass to this pin will turn off the module, leaving this pin free allows the module to work. VCC is power, GND is ground. Tx, Rx UART interface communication lines. The STATE pin changes its state after establishing communication, it is connected to the PIO9 pin, i.e. pin 32 of the HC-05 module. The dimensions of the module with the connector are 43x17x7mm. We have a voltage stabilizer on the adapter, so the value of the module supply voltage is max 6.5V, range up to 10m, transmission speed 9600bps, default operation mode - slave, current consumption measured by me is 45mA. Despite the use of a stabilizer in the adapter, the voltage level for UART communication is still 3.3V. The pairing password is: 1234. On the adapter we have one LED connected to the PIO8 pin (pin 31), which after applying power to the module starts blinking, and after pairing the module with another device, it changes the visualization method into two short flashes and a break, and then the sequence repeats. The prices of the module with shipment start from about PLN 16.50 on Polish auction portals, while the purchase directly from China requires less than $ 2.8 with the shipment.
The first of the tests I performed was pairing the module with the computer, sending a message to the module wirelessly and receiving it on the same terminal - the communication lines from the UART - Rx interface with Tx were shorted on the module, power supply for the module 3.3V. When connected in this way, the LED will flash rapidly. A computer with Windows 10 and the "PuTTY" program was used here. Adding a Bluetooth device is shown below:
As you can see - the device was successfully added.
From now on, the LED starts blinking twice, followed by a pause and repeat the cycle. In the device manager in Windows, we have two new COM ports - in this case COM 4 and COM5. The first port must be selected - COM4. When selecting the COM5 port, no connection with the Bluetooth module will be established.
Run the "PuTTY" program and in the "SESION" category, change the connection type to "SERIAL", enter "COM4" in "SERIAL LINE" and enter 9600 in the "SPEED" window. In the "SAVED SESSIONS" place, enter the name of your choice and press " SAVE ".
The next time we connect, we will be able to load our saved settings by selecting them and pressing "LOAD".
Now we go to the CONNECTION / SERIAL category and here we set our COM port.
Now click the "OPEN" button. From now on, everything we enter in the terminal window will be sent wirelessly to the HC-05 module and will be sent back from it (thanks to the shorting of the Rx line with the Tx) wirelessly to the computer and it will appear in our terminal window. In the terminal window, I typed the text "test hc-05" and that the text was displayed on the computer monitor.
There is no need to press the ENTER key, each time you press a button on the keyboard, the selected character will appear in the terminal window. Disconnecting the jumper connecting Rx with Tx will result in no reaction in the terminal window - we will not see what we press or get a response from the module, even though the module receives what we send to it all the time, after opening the jumper, the module sends nothing, because nothing is sent to the transmitting line.
The second part of the test is sending data wirelessly from one computer to another using the tested module. The distance between the computer and the module is approx. 6 m. In this test, I used the aforementioned computer, the tested HC-05 module and a second computer with Windows XP, to which a USB-UART converter built on the FT232 chip was connected. However, it should be remembered that our tested HC-05 module operates at the voltage level of 3.3V, therefore the jumper should be set to 3.3V on the USB-UART converter. On the second computer, "HyperTerminal" was used as the terminal. Here the converter is detected on the COM25 port, and below we have its settings for the "HyperTermianal" program.
From now on, we can communicate wirelessly between these computers thanks to our HC-05 module. In the "HyperTerminal" program, I turned on local echo in the settings so that what we typed on the keyboard can be seen in the terminal window. The effect of this should be that in the windows of both terminals we should see the same (as long as we transmit from the "HyperTerminal" - in "PuTTY" I did not find an option to enable echo, so we do not see what we enter in the "PuTTY" window . I entered the text in the "HyperTerminal" window:
On the other computer, I received this message in "PuTTY" as shown in the image below.
Since communication works one way, communication should work and the other way. To check, in the "PuTTY" window, I enter the text and in the "Hyperterminal" window, exactly the same as written in "PuTTY" on the other computer appears.
As the above proves - Bluetooth wireless communication using the tested HC-05 module works properly. Thanks to AT commands support, we can e.g. change the module name, baud rate or e.g. pairing password. We can get to the command handling in two ways by sending the signal to the PIO11 pin high - 3.3V. In our adapter, we have a button at our disposal which, when pressed, gives high status to pin PIO11, i.e. pin 34 of the HC-05 module. The first way is to press the button while the module has been and is still powered. Then the baud rate should be 9600bps, unless we changed it before. The second way is to press the button and then apply the power. With this method, the transmission speed is 38400bps and does not depend in any way on what was previously set. In both methods, remember that when using AT commands on pin 34, the state of the high state all the time, i.e. you have to keep the button on the adapter pressed all the time. Releasing the button may result in a lack of correct responses to entering commands. Only uppercase letters should be used when using AT commands. Below is shown changing the name of the module by entering the command AT + NAME = GRALA1
After correctly entering the AT command, the module should respond with the text "OK".
Remember about common ground for the USB-UART converter and the HC-05 module, otherwise you may have problems with communication. When doing this description, I did not test the range of the module - the distance between the computer and the module was constant and was 6 meters. Below is a link to the description of the HC-05 module with another adapter https://www.elektroda.pl/rtvforum/viewtopic.php?p=17017103#17017103
the biggest advantage it has is that it can be configured to automatically pair with the second hc-05/6 creating a virtually invisible wireless bridge for uart (except for the imperceptible delay). I successfully used such a solution at a distance close to 10m and 470k baud.