Purpose:
“ESP32 uses BT SPP Profile to connect with mobile phones or PCs and transmit strings through BT functions to perform specific functional actions for functional strings.”
#include <BluetoothSerial.h>
BluetoothSerial BT; //宣告藍芽物件,名稱為BT
void setup() {
Serial.begin(115200);
BT.begin("BT_Test"); // BTName為藍芽廣播名稱
}
void loop() {
BT.println("Hello World!"); //傳輸到藍芽裝置
//檢查藍芽內是否有資料
while (BT.available()) {
//讀取藍芽資料
String BTdata=BT.readString();
//顯示在序列視窗
Serial.println(BTdata);
BTprocessCommand(BTdata); // do something with the command
}
}
void BTprocessCommand(String data)
{
if (data == "LED_OFF")
{
Serial.println(F("LED_OFF"));
vTaskSuspend(hled);
}
if (data == "LED_ON")
{
Serial.println(F("LED_ON"));
vTaskResume(hled);
}
}
以上程序為ESP32端的code
手機端最簡單方式可以用現成的APP
Arduino Bluetooth Control
延伸閱讀
- ESP32 Bluetooth Remote Control Car -DIY(2023/08)
- Arduino與硬碟無刷直流馬達(BLDC)正反轉測試(2021/09)
- Arduino 控制三顆馬達(2019/03)
- Arduino與光碟機的結合(2016/07)
- Arduino之測試治具控制系統(2018/07)



沒有留言:
張貼留言