HC-06 Bluetooth Module JP: 두 판 사이의 차이
(새 문서: 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]] | ||
Bluetooth機能を搭載したモジュールです。 | |||
Bluetooth 2.0を使用しており、iOS(Apple製品)との互換性に問題が生じる場合があります。 | |||
iPhone 13でのテストでは、iPhoneからHC-06へのメッセージはシリアルモニターに表示されましたが、逆方向の通信は正常に動作しませんでした。 | |||
マスター/スレーブ切り替え可能モデルとスレーブ固定モデルが存在します。スレーブ固定モデルはATコマンドで役割を変更できません。 | |||
== ''' | == '''仕様''' == | ||
* 動作電圧: 3.3V ~ 5V | |||
* | |||
* Bluetooth 2.0 | * Bluetooth 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" | ||
|+ | |+ | ||
| 46번째 줄: | 46번째 줄: | ||
[[File:Hc06 회로.png|center|class=coders100]] | [[File:Hc06 회로.png|center|class=coders100]] | ||
== ''' | == '''ライブラリ''' == | ||
* 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() | ||
{ | { | ||
// | // Bluetoothシリアルからデータ受信時、シリアルモニターに表示 | ||
if (BTSerial.available()) | if (BTSerial.available()) | ||
{ | { | ||
| 80번째 줄: | 81번째 줄: | ||
} | } | ||
// | // シリアルモニターからデータ入力時、Bluetoothシリアルに送信 | ||
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]] | ||
=== | === Bluetoothターミナルアプリテスト === | ||
# スマートフォンにBluetoothターミナルアプリをインストール | |||
# | # アプリ内でHC-06モジュールと接続 | ||
# | # アプリの入力はシリアルモニターに、シリアルモニターの入力はアプリに表示 | ||
# | |||
[[File:Hc06 앱테스트.png|center|class=coders100]] | [[File:Hc06 앱테스트.png|center|class=coders100]] | ||
2025년 3월 20일 (목) 15:25 판

Bluetooth機能を搭載したモジュールです。
Bluetooth 2.0を使用しており、iOS(Apple製品)との互換性に問題が生じる場合があります。
iPhone 13でのテストでは、iPhoneからHC-06へのメッセージはシリアルモニターに表示されましたが、逆方向の通信は正常に動作しませんでした。
マスター/スレーブ切り替え可能モデルとスレーブ固定モデルが存在します。スレーブ固定モデルはATコマンドで役割を変更できません。
仕様
- 動作電圧: 3.3V ~ 5V
- Bluetooth 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()
{
// Bluetoothシリアルからデータ受信時、シリアルモニターに表示
if (BTSerial.available())
{
Serial.write(BTSerial.read());
}
// シリアルモニターからデータ入力時、Bluetoothシリアルに送信
if (Serial.available())
{
BTSerial.write(Serial.read());
}
}
動作確認
コードアップロード後、シリアルモニターで「AT」入力 「OK」表示されれば正常動作

Bluetoothターミナルアプリテスト
- スマートフォンにBluetoothターミナルアプリをインストール
- アプリ内でHC-06モジュールと接続
- アプリの入力はシリアルモニターに、シリアルモニターの入力はアプリに表示
