HC-06 Bluetooth Module CN: 두 판 사이의 차이

아두위키 : Arduwiki
(새 문서: center|class=coders100 This is a module equipped with Bluetooth functionality. It uses Bluetooth 2.0, which may present issues when used with iOS (Apple products). Testing with an iPhone 13, it was found that while messages from the iPhone to the HC-06 were displayed on the Serial Monitor, the reverse was not true, indicating an issue with operation in that direction. There are models that can switch between Master and Slave roles and models...)
 
잔글편집 요약 없음
1번째 줄: 1번째 줄:
[[File:Hc06대표이미지1.jpg|center|class=coders100]]
[[File:Hc06대표이미지1.jpg|center|class=coders100]]
This is a module equipped with Bluetooth functionality.
配备蓝牙功能的模块。


It uses Bluetooth 2.0, which may present issues when used with iOS (Apple products).
使用蓝牙2.0,可能与iOS(苹果产品)存在兼容性问题。


Testing with an iPhone 13, it was found that while messages from the iPhone to the HC-06 were displayed on the Serial Monitor, the reverse was not true, indicating an issue with operation in that direction.
在iPhone 13测试中,iPhone向HC-06发送的消息可显示在串行监视器,但反向通信无法正常工作。


There are models that can switch between Master and Slave roles and models that are fixed as Slave. Note that the Slave fixed models cannot change between master and slave roles using AT commands.
存在主/从切换型号和从机固定型号。从机固定型号无法通过AT命令切换角色。




== '''Specifications''' ==
== '''规格''' ==
* 工作电压: 3.3V ~ 5V
* 蓝牙2.0
* 默认设置:
* 名称: HC-06
* 波特率: 9600
* 配对码: 1234 或 0000


* Operating Voltage: 3.3V ~ 5V
* Bluetooth 2.0
* Default Settings:
* NAME: HC-06
* BAUD RATE: 9600
* PINCODE: 1234 or 0000
== '''Required Hardware''' ==


== '''所需硬件''' ==
* HC-06
* HC-06
* Arduino UNO
* Arduino UNO
* UNO Cable
* UNO电缆
* F-M Cable (4 pieces)
* F-M电缆(4根)
 


== '''Connection''' ==
== '''连接''' ==
TXD and RXD are connected to any desired Digital pins on the UNO board.
TXD/RXD可连接至UNO板的任意数字引脚。
{| class="wikitable"
{| class="wikitable"
|+
|+
46번째 줄: 46번째 줄:
[[File:Hc06 회로.png|center|class=coders100]]
[[File:Hc06 회로.png|center|class=coders100]]


== '''Library''' ==
== '''''' ==


* SoftwareSerial (default library)
* SoftwareSerial (default library)


== '''AT command''' ==
== '''AT命令''' ==
* 可通过AT命令检查连接状态
* 可通过串行监视器发送AT命令
* HC-06连接其他设备时AT命令无效


* Connection status can be checked using AT commands.
[[File:AT commands.png|center|class=coders100]]
* AT commands can be sent via the Serial Monitor.
* AT commands will not work if the HC-06 module is connected to another device.


[[File:AT commands.png|center|class=coders100]]


== '''Example Code''' ==
== '''示例代码''' ==
<syntaxhighlight lang="c++" line="1">
<syntaxhighlight lang="c++" line="1">
#include <SoftwareSerial.h>
#include <SoftwareSerial.h>
// Using pins 6 and 7
// 使用引脚6和7
SoftwareSerial BTSerial(6, 7);
SoftwareSerial BTSerial(6, 7);


67번째 줄: 67번째 줄:
{
{
     Serial.begin(9600);
     Serial.begin(9600);
     // Start communication with the Bluetooth module at 9600 baud rate (default)
     // 以9600波特率(默认)启动通信
     BTSerial.begin(9600);
     BTSerial.begin(9600);
     Serial.println("Serial start");
     Serial.println("Serial start");
74번째 줄: 74번째 줄:
void loop()
void loop()
{
{
     // If there is data from the Bluetooth serial, write it to the Serial Monitor.
     // 蓝牙串口数据转发至串行监视器
     if (BTSerial.available())
     if (BTSerial.available())
     {
     {
80번째 줄: 80번째 줄:
     }
     }


     // If there is data from the Serial Monitor, write it to the Bluetooth serial.
     // 串行监视器输入转发至蓝牙串口 
     if (Serial.available())
     if (Serial.available())
     {
     {
89번째 줄: 89번째 줄:
</syntaxhighlight>
</syntaxhighlight>


=== Operation Check ===
After uploading the code, enter AT in the Serial Monitor to test the operation.


If OK is displayed, it indicates that the module is functioning correctly.
=== 操作确认 ===
上传代码后,在串行监视器输入「AT」
显示「OK」即为正常
[[File:AT result.png|center|class=coders100]]
[[File:AT result.png|center|class=coders100]]




=== Bluetooth Terminal Application Test ===
=== 蓝牙终端应用测试 ===


# Install a Bluetooth terminal application on your smartphone. The type of application does not matter.
# 智能手机安装蓝牙终端应用
# Connect to the HC-06 Bluetooth module within the application.
# 在应用中连接HC-06模块
# Messages entered in the app will be displayed on the Serial Monitor, and conversely, messages entered in the Serial Monitor will be displayed in the app.
# 应用输入显示在串行监视器,串行监视器输入显示在应用


[[File:Hc06 앱테스트.png|center|class=coders100]]
[[File:Hc06 앱테스트.png|center|class=coders100]]

2025년 3월 20일 (목) 15:29 판

配备蓝牙功能的模块。

使用蓝牙2.0,可能与iOS(苹果产品)存在兼容性问题。

在iPhone 13测试中,iPhone向HC-06发送的消息可显示在串行监视器,但反向通信无法正常工作。

存在主/从切换型号和从机固定型号。从机固定型号无法通过AT命令切换角色。


规格

  • 工作电压: 3.3V ~ 5V
  • 蓝牙2.0
  • 默认设置:
  • 名称: HC-06
  • 波特率: 9600
  • 配对码: 1234 或 0000


所需硬件

  • HC-06
  • Arduino UNO
  • UNO电缆
  • F-M电缆(4根)


连接

TXD/RXD可连接至UNO板的任意数字引脚。

HC-06 Arduino UNO
RXD D7
TXD D6
GND GND
VCC 5V

  • SoftwareSerial (default library)

AT命令

  • 可通过AT命令检查连接状态
  • 可通过串行监视器发送AT命令
  • HC-06连接其他设备时AT命令无效


示例代码

#include <SoftwareSerial.h>
// 使用引脚6和7
SoftwareSerial BTSerial(6, 7);

void setup()
{
    Serial.begin(9600);
    // 以9600波特率(默认)启动通信
    BTSerial.begin(9600);
    Serial.println("Serial start");
}

void loop()
{
    // 蓝牙串口数据转发至串行监视器
    if (BTSerial.available())
    {
        Serial.write(BTSerial.read());
    }

    // 串行监视器输入转发至蓝牙串口  
    if (Serial.available())
    {
        BTSerial.write(Serial.read());
    }
}


操作确认

上传代码后,在串行监视器输入「AT」 显示「OK」即为正常


蓝牙终端应用测试

  1. 智能手机安装蓝牙终端应用
  2. 在应用中连接HC-06模块
  3. 应用输入显示在串行监视器,串行监视器输入显示在应用