1 軟體 : Arduino ( v1.8.12 ) 會隨版本更新
2 元件及材料 :
ESP 32 板子
麵包板x1
杜邦線x4
電線x2
ledx1
220Ω 電阻x1
10k Ω 電阻x1
光敏電阻x1
Arduino
教學 : https://zanrobot.com/uncategorized/3699
下載 : tps://www.arduino.cc/zh/main/software?setlang =cn
接線圖

5V —-> +
GND —-> –
SVP —–> 光敏的端+10k
P13 —-> LED+端(腳長)
ESP 32 前置
教學 : https://zanrobot.com/uncategorized/3699
程式編碼
#include <BluetoothSerial.h>
BluetoothSerial SerialBT;//宣告藍芽物件=SerialBT
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);//序列視窗
SerialBT.begin(“ESP32”);//<<藍芽名稱,請自己記得
pinMode(A0, INPUT);
pinMode(13,OUTPUT);//電燈relay
}
int pr_min = 400;
void loop() {
char analogRea=SerialBT.read();
int pr = analogRead(A0);{
Serial.println(pr);
SerialBT.println(pr);
delay(1000);
}
while(SerialBT.available())
{
char btdata=SerialBT.read();
Serial.print(btdata);//查看藍芽輸入的值
if (btdata==’3′){digitalWrite(13,HIGH);}//開電燈
if (btdata==’4′){digitalWrite(13,LOW);}//關電燈
}
delay(100);
}
手機app
先到play商店下載arduino bluetooth controller

開啟並開啟藍芽選到裝置

點擊裝置會出現此列表

按下

當程式執行成功時將出現光敏阻值
且輸入 3 Led 亮 4 Led關
