#include "BluetoothSerial.h"
/*
red led = LIV Light -- Used digitalWrite to provide power
blue led = WC light -- Used digitalWrite to provide power
yellow led = FAN -- Used 220V and Relay to control
green led = Kitchen light -- Used 220V and Relay to control
On relay, we used NC - Normal Closed port so LOW signal to stop power, HIGH is provide power
*/
int liv_light = 14;
int wc_light = 27;
int fan = 26;
int kitchen_light = 25;
String inputString = "";
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
void setup() {
Serial.begin(115200);
SerialBT.begin("HomeKit_Nhom4"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
pinMode(liv_light, OUTPUT);
digitalWrite(liv_light, LOW);
pinMode(wc_light, OUTPUT);
digitalWrite(wc_light, LOW);
pinMode(fan, OUTPUT);
digitalWrite(fan, LOW);
pinMode(kitchen_light, OUTPUT );
digitalWrite(kitchen_light, LOW);
}
void loop() {
if (SerialBT.available()) {
inputString = SerialBT.readStringUntil('\n'); // Read the input string until newline
inputString.trim(); // Remove any leading or trailing whitespace
// Process command
if (inputString == "livon") {
digitalWrite(liv_light, HIGH);
} else if (inputString == "wcon") {
digitalWrite(wc_light, HIGH);
} else if (inputString == "fanon") {
digitalWrite(fan, HIGH);
} else if (inputString == "kitchenon") {
digitalWrite(kitchen_light, HIGH);
} else if (inputString == "livoff") {
digitalWrite(liv_light, LOW);
} else if (inputString == "wcoff") {
digitalWrite(wc_light, LOW);
} else if (inputString == "fanoff") {
digitalWrite(fan, LOW);
} else if (inputString == "kitchenoff") {
digitalWrite(kitchen_light, LOW);
} else {
Serial.print("Unknown command: ");
Serial.println(inputString);
}
// Clear the input string for the next command
inputString = "";
}
// Additional code for your loop, if needed
}