#include "BluetoothSerial.h" #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it #endif String res = ""; BluetoothSerial SerialBT; void setup() { Serial.begin(115200); pinMode(12, OUTPUT); pinMode(13, OUTPUT); pinMode(14, OUTPUT); SerialBT.begin("ESP32test"); //Bluetooth device name Serial.println("The device started, now you can pair it with bluetooth!"); } void loop() { while (!SerialBT.available()); // Wait Until anything is coming from bluetooth client while (SerialBT.available()) // Read until the bluetooth client is sending. { char add = SerialBT.read(); res = res + add; delay(1); } // Assigning Actions on particular conditions if (res == "T") { Serial.println("Connection Established!!!"); } if (res == "r") { Serial.println("Turning ON Red led"); digitalWrite(13, HIGH); } if (res == "g") { Serial.println("Turning ON Green led"); digitalWrite(12, HIGH); } if (res == "b") { Serial.println("Turning ON blue led"); digitalWrite(14, HIGH); } if (res == "a") { Serial.println("Animation"); digitalWrite(12, HIGH); delay(1000); digitalWrite(12, LOW); digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); digitalWrite(14, HIGH); delay(1000); digitalWrite(14, LOW); delay(1000); } if (res == "o") { Serial.println("Turning OFF all led"); digitalWrite(12, LOW); digitalWrite(13, LOW); digitalWrite(14, LOW); } res = ""; // clearing the string. }