// Define constants for sensor pins
const int waterLevelSensorPin = A0; // Analog input pin for water level sensor
const int temperatureSensorPin = A1; // Analog input pin for temperature sensor
const int pumpControlPin = 2; // Digital output pin for controlling MOSFET (water pump)
// Define constants for LED pins
const int greenLEDPin = 3; // Green LED pin
const int yellowLEDPin = 4; // Yellow LED pin
const int redLEDPin = 5; // Red LED pin
// Define thresholds for water level and temperature
const int fullTankThreshold = 5000; // Above 4500 liters is considered full (analog value)
const int refillThresholdLow = 2000; // Below 2000 liters is considered low (analog value)
const int refillThresholdHigh = 4500; // Between 2000 and 4500 liters is considered refill (analog value)
const int pumpStartThreshold = 1500; // Pump starts when water level is above 1500 liters (analog value)
const int temperatureThreshold = 65; // Temperature threshold in Celsius
void setup() {
Serial.begin(9600);
// Set pin modes for LEDs
pinMode(greenLEDPin, OUTPUT);
pinMode(yellowLEDPin, OUTPUT);
pinMode(redLEDPin, OUTPUT);
// Set pin mode for pump control
pinMode(pumpControlPin, OUTPUT);
}
void loop() {
// Read analog values from sensors
int waterLevel = analogRead(waterLevelSensorPin); // Read water level sensor
int temperature = analogRead(temperatureSensorPin); // Read temperature sensor
// Convert analog readings to actual quantities or temperatures
int waterQuantityLiters = map(waterLevel, 0, 1023, 0, 10000); // Map analog value to liters (0-10000)
// Check water level and control LEDs
if (waterQuantityLiters >= refillThresholdHigh) {
digitalWrite(greenLEDPin, HIGH); // Green LED (Full tank)
digitalWrite(yellowLEDPin, LOW); // Yellow LED (Refill) off
digitalWrite(redLEDPin, LOW); // Red LED (Empty) off
} else if (waterQuantityLiters >= refillThresholdLow && waterQuantityLiters < refillThresholdHigh) {
digitalWrite(greenLEDPin, LOW);
digitalWrite(yellowLEDPin, HIGH);
digitalWrite(redLEDPin, LOW);
} else {
digitalWrite(greenLEDPin, LOW);
digitalWrite(yellowLEDPin, LOW);
digitalWrite(redLEDPin, HIGH);
}
// Check water level to control pump
if (waterQuantityLiters > pumpStartThreshold) {
digitalWrite(pumpControlPin, HIGH); // Turn on pump
} else {
digitalWrite(pumpControlPin, LOW); // Turn off pump
}
// Check temperature to control heater element (assuming heater logic is implemented separately)
// Debugging output (optional)
Serial.print("Water Level (liters): ");
Serial.println(waterQuantityLiters);
Serial.print("Temperature (Celsius): ");
Serial.println(map(temperature, 0, 1023, 0, 100)); // Map temperature analog value to Celsius
// Add delay to prevent continuous looping too fast (adjust as needed)
delay(3000); // Delay of 1 second (3000 milliseconds)
}