diff --git a/arduino/arduino_code/arduino_code.ino b/arduino/arduino_code/arduino_code.ino index 81f84a8..dee965a 100644 --- a/arduino/arduino_code/arduino_code.ino +++ b/arduino/arduino_code/arduino_code.ino @@ -35,6 +35,7 @@ void wakeUpScreen(); void setup() { Serial.begin(115200); + Serial1.begin(115200); // Initialize RX/TX for Arduino-ESP communication lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); @@ -158,6 +159,29 @@ void loop() { openGarage(); } } + + // Check for commands from ESP via Serial1 + if (Serial1.available() > 0) { + String espCommand = Serial1.readStringUntil('\n'); + espCommand.trim(); + Serial.print("ESP Command received: "); + Serial.println(espCommand); + if (espCommand == "OPEN_DOOR") { + openDoor(); + } else if (espCommand == "OPEN_GARAGE") { + openGarage(); + } else if (espCommand == "DOORBELL") { + // Process doorbell trigger + Serial.println("Doorbell triggered"); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print(" Kapi Zili! "); + delay(2000); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print(" HVZ House "); + } + } } bool isValidPassword(String password) { @@ -246,4 +270,4 @@ void wakeUpScreen() { lcd.setCursor(0, 1); lcd.print(" Hosgeldiniz! "); isScreenOn = true; -} \ No newline at end of file +} diff --git a/arduino/arduino_code/esp32.ino b/arduino/arduino_code/esp32.ino new file mode 100644 index 0000000..d153b0b --- /dev/null +++ b/arduino/arduino_code/esp32.ino @@ -0,0 +1,79 @@ +#include +#include + +// WiFi credentials +const char* ssid = "YOUR_SSID"; +const char* password = "YOUR_PASSWORD"; + +// Define ESP32 hardware serial for Arduino communication +#define ARDUINO_SERIAL Serial1 // RX/TX pins must be connected to Arduino + +WebServer server(80); + +// Embedded HTML without camera/sound/voice +const char* index_html = R"rawliteral( + + + + + + H3RU Home Control System + + + +

H3RU Home Control System

+ + + + + +)rawliteral"; + +void handleRoot() { + server.send(200, "text/html", index_html); +} + +void handleDoorbell() { + ARDUINO_SERIAL.println("DOORBELL"); + server.send(200, "text/plain", "Doorbell triggered"); +} + +void handleOpenDoor() { + ARDUINO_SERIAL.println("OPEN_DOOR"); + server.send(200, "text/plain", "Door opening"); +} + +void handleOpenGarage() { + ARDUINO_SERIAL.println("OPEN_GARAGE"); + server.send(200, "text/plain", "Garage opening"); +} + +void setup() { + Serial.begin(115200); + // Initialize Arduino serial for ESP32 TX/RX communication + ARDUINO_SERIAL.begin(115200); + + // Connect to WiFi + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println("\nWiFi connected"); + + // Start web server and define routes + server.on("/", handleRoot); + server.on("/doorbell", handleDoorbell); + server.on("/open_door", handleOpenDoor); + server.on("/open_garage", handleOpenGarage); + server.begin(); + Serial.println("HTTP server started"); +} + +void loop() { + server.handleClient(); + // ...existing code if required... +}