Skip to content

Instantly share code, notes, and snippets.

@detik19
Created June 3, 2019 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save detik19/cd2b9969ceee5a346f7be08946a150c8 to your computer and use it in GitHub Desktop.
Save detik19/cd2b9969ceee5a346f7be08946a150c8 to your computer and use it in GitHub Desktop.
esp32 bluetooth serial
#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