#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <Ultrasonic.h>
Const char* ssid = “YourWiFiSSID”;
Const char* password = “YourWiFiPassword”;
Const int trigPin = 2; // Trigger pin of Ultrasonic Sensor
Const int echoPin = 3; // Echo pin of Ultrasonic Sensor
Const int relayPin = 7; // Relay module control pin
Ultrasonic ultrasonic(trigPin, echoPin);
WiFiServer server(80);
Void setup() {
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW);
Serial.begin(115200);
WiFi.begin(ssid, password);
While (WiFi.status() != WL_CONNECTED) {
Delay(1000);
Serial.println(“Connecting to WiFi...”);
}
Server.begin();
}
Void loop() {
WiFiClient client = server.available();
If (client) {
String request = client.readStringUntil(‘\r’);
If (request.indexOf(“/on”) != -1) {
digitalWrite(relayPin, HIGH); // Turn the pump on
delay(2000); // Run the pump for 2 seconds
digitalWrite(relayPin, LOW); // Turn the pump off
}
Client.flush();
}
// Check water level
Float distance = ultrasonic.read();
If (distance < 10) {
// Water is low, update the web interface
// You can send an HTML response to the client here
}
}
SIMULATION AND TE