#include "BluetoothSerial.h"
#define rele 18
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth nao esta habilitado! Execute a configuracao do bluetooth
#endif
BluetoothSerial SerialBT;
void acionar(char d)
{
if (d=='A')
{
digitalWrite(rele, HIGH);
}
else
{
if (d=='a')
{
digitalWrite(rele, LOW);
}
}
}
void setup()
{
Serial.begin(115200);
//SerialBT.begin("ESP32_01"); //Nome do Bluetooth
Serial.println("Conectado com sucesso");
pinMode(rele, OUTPUT);
}
void loop()
{
if (Serial.available()) //Verificar se chegou dado pela Serial
{
char dado = Serial.read();
SerialBT.write(Serial.read()); //Enviar dados para o celular através da Serial
acionar(dado);
}
if (SerialBT.available()) //Verificar se chegou dado pelo bluetooth
{
char dado = SerialBT.read();
Serial.write(dado); //Exibir na Serial
acionar(dado);
}
delay(50);
}