0% found this document useful (0 votes)
4 views

Esp8266 Water Tank Control

This document provides code for an ESP8266-based system to control a water tank and sump with mobile app monitoring. It includes setup for WiFi connectivity, sensor inputs, and motor control logic, allowing users to switch between automatic and manual modes. The web interface displays the status of the sump and tank levels and provides buttons to control the motor and change modes.

Uploaded by

muru009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Esp8266 Water Tank Control

This document provides code for an ESP8266-based system to control a water tank and sump with mobile app monitoring. It includes setup for WiFi connectivity, sensor inputs, and motor control logic, allowing users to switch between automatic and manual modes. The web interface displays the status of the sump and tank levels and provides buttons to control the motor and change modes.

Uploaded by

muru009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

<!

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

// Create AsyncWebServer object on port 80


AsyncWebServer server(80);

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());

// Route for root / web page


server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
String html = "<!DOCTYPE html><html><head><title>Water Control</title></head><body>";
html += "<h1>Water Tank and Sump Control</h1>";
html += "<p><strong>Sump:</strong> Low: " + String(digitalRead(sumpLowPin)) + ", High: "
+ String(digitalRead(sumpHighPin)) + "</p>";
html += "<p><strong>Tank:</strong> Low: " + String(digitalRead(tankLowPin)) + ", High: " +
String(digitalRead(tankHighPin)) + "</p>";
html += "<p><strong>Motor:</strong> " + String(motorState ? "ON" : "OFF") + "</p>";
html += "<p><strong>Mode:</strong> " + String(autoMode ? "Auto" : "Manual") + "</p>";
html += "<button onclick=\"fetch('/motor/on')\">Turn Motor ON</button>";
html += "<button onclick=\"fetch('/motor/off')\">Turn Motor OFF</button>";
html += "<button onclick=\"fetch('/mode/auto')\">Set Auto Mode</button>";
html += "<button onclick=\"fetch('/mode/manual')\">Set Manual Mode</button>";
html += "</body></html>";
request->send(200, "text/html", html);
});
// Route to turn motor ON
server.on("/motor/on", HTTP_GET, [](AsyncWebServerRequest *request){
motorState = HIGH;
digitalWrite(motorPin, HIGH);
digitalWrite(motorRunningLedPin, HIGH);
request->send(200, "text/plain", "Motor Turned ON");
});

// Route to turn motor OFF


server.on("/motor/off", HTTP_GET, [](AsyncWebServerRequest *request){
motorState = LOW;
digitalWrite(motorPin, LOW);
digitalWrite(motorRunningLedPin, LOW);
request->send(200, "text/plain", "Motor Turned OFF");
});

// Route to set Auto Mode


server.on("/mode/auto", HTTP_GET, [](AsyncWebServerRequest *request){
autoMode = true;
request->send(200, "text/plain", "Auto Mode Activated");
});

// Route to set Manual Mode


server.on("/mode/manual", HTTP_GET, [](AsyncWebServerRequest *request){
autoMode = false;
request->send(200, "text/plain", "Manual Mode Activated");
});

// 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);

// Update LED Indicators


digitalWrite(sumpLowLedPin, sumpLow ? HIGH : LOW);
digitalWrite(sumpHighLedPin, sumpHigh ? HIGH : LOW);
digitalWrite(tankLowLedPin, tankLow ? HIGH : LOW);
digitalWrite(tankHighLedPin, tankHigh ? HIGH : LOW);

// Motor Control Logic in Auto Mode


if (autoMode && controlSwitch == HIGH) { // Auto Mode
if (!sumpLow && tankLow) { // If sump is not low and tank is low
motorState = HIGH;
digitalWrite(motorPin, HIGH); // Turn on Motor
digitalWrite(motorRunningLedPin, HIGH); // Indicate Motor Running
} else if (tankHigh || sumpLow) { // If tank is full or sump is low
motorState = LOW;
digitalWrite(motorPin, LOW); // Turn off Motor
digitalWrite(motorRunningLedPin, LOW); // Indicate Motor Stopped
}
}

// Small delay to avoid rapid switching


delay(100);
}
</script>
</body>
</html>

You might also like