Created
June 3, 2019 17:19
-
-
Save detik19/cd2b9969ceee5a346f7be08946a150c8 to your computer and use it in GitHub Desktop.
esp32 bluetooth serial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "BluetoothSerial.h" | |
BluetoothSerial ESP_BT; //Object for Bluetooth | |
int incoming; | |
int LED_BUILTIN = 2; | |
void setup() { | |
Serial.begin(9600); //Start Serial monitor in 9600 | |
ESP_BT.begin("ESP32_LED_Control"); //Name of your Bluetooth Signal | |
Serial.println("Bluetooth Device is Ready to Pair"); | |
pinMode (LED_BUILTIN, OUTPUT);//Specify that LED pin is output | |
} | |
void loop() { | |
if (ESP_BT.available()) //Check if we receive anything from Bluetooth | |
{ | |
incoming = ESP_BT.read(); //Read what we recevive | |
Serial.print("Received:"); Serial.println(incoming); | |
if (incoming == 49) | |
{ | |
digitalWrite(LED_BUILTIN, HIGH); | |
ESP_BT.println("LED turned ON"); | |
} | |
if (incoming == 48) | |
{ | |
digitalWrite(LED_BUILTIN, LOW); | |
ESP_BT.println("LED turned OFF"); | |
} | |
} | |
delay(20); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment