ESP32 Bluetooth Home Automation :
ESP32 Bluetooth Home Automation code:
#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 = "";
int re1=13;
BluetoothSerial SerialBT;
void setup() {
Serial.begin(115200);
pinMode(re1, OUTPUT);
SerialBT.begin("ESP32 MEWT "); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
digitalWrite(re1,HIGH);
}
void loop()
{
while (!SerialBT.available()); // Wait Until anything is coming from bluetooth client
while (SerialBT.available()) // Read until the bluetooth client is sending.
{
char v= SerialBT.read();
res = res + v;
delay(1);
}
// Assigning Actions on particular conditions
if (res == "T")
{
Serial.println("Connection Established!!!");
}
if (res == "A")
{
Serial.println("Turning ON 1st led");
digitalWrite(re1, HIGH);
}
if (res == "a")
{
Serial.println("Turning OFF 1st led");
digitalWrite(re1, LOW);
}
res = ""; // clearing the string.
}
0 Comments