
Everyone is likely familiar with Bluetooth, having used it in various situations. But what about the Bluetooth modules in microcontrollers? This installment of useful information will take you into the world of Bluetooth modules.
1
Introduction to Bluetooth Modules
A Bluetooth module is a commonly used wireless communication module, widely applied in various smart devices. A wireless Bluetooth module refers to a chip that integrates basic circuit sets for Bluetooth functionality, used for short-distance 2.4G wireless communication.
For end users, a Bluetooth module is a semi-finished product that can be further developed and encapsulated into a final product capable of Bluetooth communication. Among them, the low-energy Bluetooth module (BLE) refers to modules that support Bluetooth protocol 4.0 or higher, also known as BLE modules.

JDY-31

HC-05
More Bluetooth modules can be searched by yourself.
2
Versions
Bluetooth versions include V1.0, V2.0, V3.0, and V4.0, with V4.0 being the latest. Bluetooth is backward compatible; for example, a phone with V2.0 cannot search and recognize a Bluetooth 3.0 module, but the reverse is possible.
Due to special settings for Bluetooth devices on Apple devices, Bluetooth serial modules prior to V4.0 cannot be used directly with Apple. If friends using Apple encounter issues with pairing their phone to a Bluetooth module, they can try searching for LightBlue in the app store. As for the usage of LightBlue, the author is not very clear, but those in need can explore it (or alternatively buy an Android device~).
3
Operating Modes
Bluetooth modules have two operating modes: command response mode and automatic connection mode.
When the module is in automatic connection mode, it will automatically connect based on pre-set data transfer methods; when the module is in command response mode, it can execute AT commands, allowing users to send various AT instructions to set control parameters or issue control commands.
AT commands can only take effect when the module is not connected; once the Bluetooth module connects to a device, it enters data transparent transmission mode (AT commands are instructions used for connection and communication between terminal devices and PC applications, with AT meaning Attention. AT commands begin with AT and end with a character, and the response data for each command is included. Each command has a corresponding return indicating whether it was successful).
Different Bluetooth modules have different Bluetooth AT command sets, generally provided in the Chinese data manual supplied by the seller.
4
Configuration
Connect the Bluetooth module to the RXD, TXD, GND, and VCC of the USB to TTL converter. Press and hold the small button on the Bluetooth module, then power it on (holding while powering is configuration mode; powering directly is normal use mode). Use Bluetooth testing software to enter absolute AT mode, retrieve module information, and obtain information about the Bluetooth module.
Typically, configure the baud rate, master/slave mode, pairing password, and set module parameters such as device name and connection password. It is essential to ensure the baud rate matches; otherwise, garbled data may occur, preventing successful information transfer.
The Bluetooth module can be used as a full-duplex serial port without needing to understand complex Bluetooth protocols.
5
Hardware Connections
Similar to connecting conversion modules, the RX of the Bluetooth module connects to the TX of the microcontroller, the TX of the Bluetooth module connects to the RX of the microcontroller, and the VCC and GND pins are connected as well; other pins usually do not need to be addressed.
6
Program
The following program is for connecting Bluetooth with a mobile phone, sending 1 from the Bluetooth serial assistant to execute the digital tube display function, and sending 0 to turn off the digital tube.
Main function👇

Receiving data in the interrupt👇

The serial interrupt of the 51 microcontroller receives data one byte at a time. For example, if the phone sends data “123” to the microcontroller, the interrupt function in the microcontroller will enter three times to receive the data “123” in three parts, receiving one character at a time.
7
Mobile End Operations
Connect the mobile phone to Bluetooth and send data through the mobile Bluetooth serial assistant (search for Bluetooth serial assistant directly in the mobile app store).
The Bluetooth module has an indicator light; before a successful Bluetooth connection, the red light on the Bluetooth module keeps flashing. After a successful connection, the red light stops flashing, and every time a command is sent, the serial debugging assistant on the computer can receive messages sent from the mobile end.

Most Bluetooth serial apps can modify the button names on the mobile page, which can be changed as needed.
After debugging the communication between the Bluetooth module and the mobile phone, you can send some characters through the mobile Bluetooth serial debugging assistant to let the microcontroller execute specific commands. You could try making a Bluetooth remote-controlled car or controlling household appliances on/off, etc.
This is a simple usage of a Bluetooth module.
There are various advanced operations that everyone can try for themselves~
Scan the QR code below to follow the WeChat public account of Huashi Wuxie.

Text | Huang Shuangshuang
Layout | Huang Minxue
Editor | Xu Weiliang, Luo Shuqiqi
Initial Review | Ma Beiyu
Review | Cai Hanjing
Final Review | Tang Xiaoyu