Esp8266 Water Tank Control
Esp8266 Water Tank Control
DOCTYPE html>
<html>
<head>
<title>ESP8266 Water Tank and Sump Control with Mobile App</title>
</head>
<body>
<script>
// ESP8266 Code for Fully Automatic Water Tank and Sump Control with Mobile App Monitoring
and Control
// This code assumes the use of Arduino IDE with ESP8266 support and the
ESPAsyncWebServer library.
#include <ESP8266WiFi.h>
#include <ESPAsyncWebServer.h>
// WiFi Credentials
const char* ssid = "Your_SSID"; // Replace with your WiFi SSID
const char* password = "Your_PASSWORD"; // Replace with your WiFi Password
// Pin Definitions
const int sumpLowPin = D1; // Input: Sump Low Level Sensor
const int sumpHighPin = D2; // Input: Sump High Level Sensor
const int tankLowPin = D3; // Input: Overhead Tank Low Level Sensor
const int tankHighPin = D4; // Input: Overhead Tank High Level Sensor
const int controlSwitchPin = D5; // Input: Auto/Manual Control Switch
const int motorPin = D6; // Output: Motor Control Relay
const int sumpLowLedPin = D7; // Output: LED Indication for Sump Low
const int sumpHighLedPin = D8;// Output: LED Indication for Sump High
const int tankLowLedPin = D9; // Output: LED Indication for Tank Low
const int tankHighLedPin = D10; // Output: LED Indication for Tank High
const int motorRunningLedPin = D11; // Output: LED Indication for Motor Running
// Variables
bool motorState = LOW; // Current state of the motor
bool autoMode = true; // Default to Auto Mode
void setup() {
// Initialize Serial Monitor
Serial.begin(115200);
// Initialize Inputs
pinMode(sumpLowPin, INPUT);
pinMode(sumpHighPin, INPUT);
pinMode(tankLowPin, INPUT);
pinMode(tankHighPin, INPUT);
pinMode(controlSwitchPin, INPUT);
// Initialize Outputs
pinMode(motorPin, OUTPUT);
pinMode(sumpLowLedPin, OUTPUT);
pinMode(sumpHighLedPin, OUTPUT);
pinMode(tankLowLedPin, OUTPUT);
pinMode(tankHighLedPin, OUTPUT);
pinMode(motorRunningLedPin, OUTPUT);
// Initial State
digitalWrite(motorPin, LOW); // Motor Off
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
Serial.println(WiFi.localIP());
// Start server
server.begin();
}
void loop() {
// Read Sensor States
bool sumpLow = digitalRead(sumpLowPin);
bool sumpHigh = digitalRead(sumpHighPin);
bool tankLow = digitalRead(tankLowPin);
bool tankHigh = digitalRead(tankHighPin);
bool controlSwitch = digitalRead(controlSwitchPin);