Hello Guys Please Help Me!
I want to make connection between ESP32 Microcontroller with Bluetooth Module HC-06 and relay as Output. Then how does it work, if BT HC-06 is connected to ESP32 then the relay will be ON or signal HIGH and vice versa if BT HC-06 is disconnected from ESP32 then the relay will be OFF or signal LOW.
I have a problem with my bluetooth connection. the problem is, if the BT HC-06 is disconnected with ESP32, the disconnection time is very long, it takes about 60 seconds each reading disconnected. So how to increase the reading time speed when the BT HC-06 is disconnected?
So this is my code
#include "BluetoothSerial.h"
#define RELAY_PIN 2
BluetoothSerial SerialBT;
String MACadd = "00:19:10:1109:6B:F3";
uint8_t address[6] = {0x98, 0xD3, 0x32, 0x11, 0x31, 0x37};
//uint8_t address[6] = {0x11, 0x1D, 0xA5, 0x02, 0xC3, 0x22};
String name = "HC-06";
char *pin = "1234"; //<- standard pin would be provided by default
bool connected;
void setup() {
Serial.begin(115200);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW);
SerialBT.begin("ESP32test", true);
SerialBT.setPin(pin);
Serial.println("The device started in master mode, make sure remote BT device is on!");
connected = SerialBT.connect(name);
}
void loop() {
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
Serial.write(SerialBT.read());
}
connected = SerialBT.connect(name);
if(connected) {
Serial.println("Bluetooth Connected");
digitalWrite(RELAY_PIN, HIGH);
}
if(!SerialBT.connected()) {
Serial.println("Bluetooth Disconnected");
digitalWrite(RELAY_PIN, LOW);
}
SerialBT.connect();
}
this serial monitor
*note:
Terhubung is Connected
Terputus is Disconnected