Skip to content

Instantly share code, notes, and snippets.

@youjunjer
Last active April 25, 2019 16:48
Show Gist options
  • Save youjunjer/991eaa7e12a66f4cc30b2e3c0bf6b63b to your computer and use it in GitHub Desktop.
Save youjunjer/991eaa7e12a66f4cc30b2e3c0bf6b63b to your computer and use it in GitHub Desktop.
ArduinoBluetoothControl
#include <BluetoothSerial.h>
BluetoothSerial SerialBT;//宣告藍芽物件=SerialBT
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);//序列視窗
SerialBT.begin("BLETEST");//<<藍芽廣播名稱,請自己記得
pinMode(4,OUTPUT);//風扇relay
pinMode(16,OUTPUT);//電燈relay
}
void loop() {
if(SerialBT.available()){
Serial.println("");
}
while(SerialBT.available())
{
char btdata=SerialBT.read();
Serial.print(btdata);//查看藍芽輸入的值
if (btdata=='1'){digitalWrite(4,HIGH);}//關風扇
if (btdata=='2'){digitalWrite(4,LOW);}//開風扇
if (btdata=='3'){digitalWrite(16,HIGH);}//關電燈
if (btdata=='4'){digitalWrite(16,LOW);}//開電燈
}
delay(100);
}
© 2019 GitHub, Inc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment