Bluetooth 藍牙模組 HC-05 設定

[材料]

Arduino主板 x 1

藍牙模組 HC-05

/*
BlueTooth 藍牙模組
VCC to arduino 5v
GND to arduino GND
RXD to arduino D11
TXD to arduino D10
KEY to arduino 3.3v
*/

#include  <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX
void setup()
{
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  BTSerial.begin(38400);
}
void loop()
{
  if (BTSerial.available())
    Serial.write(BTSerial.read());
  if (Serial.available())
    BTSerial.write(Serial.read());
}

設定:將Arduino連接電腦,並上傳程式碼後,進入AT模式。

[如果藍牙模組上,有一個小按鈕,要先按住按鈕,再把usb線接上電腦,之後再放開按鈕。]

1. 輸入 AT

回應:

OK


2. 查詢版本,輸入 AT+VERSION

回應:

+VERSION:2.0-20100601

OK


3. 查詢名稱,輸入 AT+NAME?

回應:

+NAME:HC-05

OK


4.更改名稱,輸入 AT+NAME=名稱

回應:

OK