HC-06 Bluetooth Module CN: 두 판 사이의 차이
(새 문서: 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...) |
잔글편집 요약 없음 |
||
| (같은 사용자의 중간 판 3개는 보이지 않습니다) | |||
| 1번째 줄: | 1번째 줄: | ||
[[File:Hc06대표이미지1.jpg|center|class=coders100]] | {{#seo:|title=Arduino维基:Arduino HC-06蓝牙模块指南|title_mode=append|keywords=Arduino, 信息科学, 创客学习, 性能评估, HC-06蓝牙模块, Arduino项目, 毕业设计项目, Arduino示例代码|description=介绍如何使用Arduino控制HC-06蓝牙模块(基本信息、电路、示例代码)。可用于信息科学和创客课程。}}[[File:Hc06대표이미지1.jpg|center|class=coders100]] | ||
配备蓝牙功能的模块。 | |||
使用蓝牙2.0,可能与iOS(苹果产品)存在兼容性问题。 | |||
在iPhone 13测试中,iPhone向HC-06发送的消息可显示在串行监视器,但反向通信无法正常工作。 | |||
存在主/从切换型号和从机固定型号。从机固定型号无法通过AT命令切换角色。 | |||
== ''' | == '''规格''' == | ||
* 工作电压: 3.3V ~ 5V | |||
* 蓝牙2.0 | |||
* 默认设置: | |||
* 名称: HC-06 | |||
* 波特率: 9600 | |||
* 配对码: 1234 或 0000 | |||
== '''所需硬件''' == | |||
* HC-06 | * HC-06 | ||
* Arduino UNO | * Arduino UNO | ||
* | * UNO电缆 | ||
* F- | * F-M电缆(4根) | ||
== ''' | |||
TXD | == '''连接''' == | ||
TXD/RXD可连接至UNO板的任意数字引脚。 | |||
{| class="wikitable" | {| class="wikitable" | ||
|+ | |+ | ||
| 45번째 줄: | 45번째 줄: | ||
|} | |} | ||
[[File:Hc06 회로.png|center|class=coders100]] | [[File:Hc06 회로.png|center|class=coders100]] | ||
== '''Library''' == | == '''Library''' == | ||
* SoftwareSerial (default library) | * SoftwareSerial (default library) | ||
* | == '''AT命令''' == | ||
* | * 可通过AT命令检查连接状态 | ||
* | * 可通过串行监视器发送AT命令 | ||
* HC-06连接其他设备时AT命令无效 | |||
[[File:AT commands.png|center|class=coders100]] | [[File:AT commands.png|center|class=coders100]] | ||
== ''' | |||
== '''示例代码''' == | |||
<syntaxhighlight lang="c++" line="1"> | <syntaxhighlight lang="c++" line="1"> | ||
#include <SoftwareSerial.h> | #include <SoftwareSerial.h> | ||
// | // 使用引脚6和7 | ||
SoftwareSerial BTSerial(6, 7); | SoftwareSerial BTSerial(6, 7); | ||
| 67번째 줄: | 68번째 줄: | ||
{ | { | ||
Serial.begin(9600); | Serial.begin(9600); | ||
// | // 以9600波特率(默认)启动通信 | ||
BTSerial.begin(9600); | BTSerial.begin(9600); | ||
Serial.println("Serial start"); | Serial.println("Serial start"); | ||
| 74번째 줄: | 75번째 줄: | ||
void loop() | void loop() | ||
{ | { | ||
// | // 蓝牙串口数据转发至串行监视器 | ||
if (BTSerial.available()) | if (BTSerial.available()) | ||
{ | { | ||
| 80번째 줄: | 81번째 줄: | ||
} | } | ||
// | // 串行监视器输入转发至蓝牙串口 | ||
if (Serial.available()) | if (Serial.available()) | ||
{ | { | ||
| 89번째 줄: | 90번째 줄: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== 操作确认 === | |||
上传代码后,在串行监视器输入「AT」 | |||
显示「OK」即为正常 | |||
[[File:AT result.png|center|class=coders100]] | [[File:AT result.png|center|class=coders100]] | ||
=== | === 蓝牙终端应用测试 === | ||
# | # 智能手机安装蓝牙终端应用 | ||
# | # 在应用中连接HC-06模块 | ||
# | # 应用输入显示在串行监视器,串行监视器输入显示在应用 | ||
[[File:Hc06 앱테스트.png|center|class=coders100]] | [[File:Hc06 앱테스트.png|center|class=coders100]] | ||
2025년 3월 20일 (목) 19:53 기준 최신판

配备蓝牙功能的模块。
使用蓝牙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 |

Library
- 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」即为正常

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