#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// LCD setup
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Pin definitions
const int potPin = A0; // Potentiometer simulates TDS sensor
//const int ledA = 5; // Pump A LED
//const int ledB = 4; // Pump B LED
const int relayA = 5; // Relay A (active LOW)
const int relayB = 4; // Relay B (active LOW)
const int tdsThreshold = 100; // ppm threshold
void setup() {
lcd.init();
lcd.backlight();
//pinMode(ledA, OUTPUT);
//pinMode(ledB, OUTPUT);
pinMode(relayA, OUTPUT);
pinMode(relayB, OUTPUT);
// Start OFF (LEDs and Relays OFF)
//digitalWrite(ledA, LOW);
//digitalWrite(ledB, LOW);
digitalWrite(relayA, !HIGH); // OFF (active LOW)
digitalWrite(relayB, !HIGH); // OFF (active LOW)
}
void loop() {
int sensorValue = analogRead(potPin);
int tdsValue = map(sensorValue, 0, 1023, 0, 1000);
lcd.setCursor(0, 0);
lcd.print("TDS: ");
lcd.print(tdsValue);
lcd.print(" ppm ");
if (tdsValue >= tdsThreshold) {
// Both pumps ON
//digitalWrite(ledA, HIGH);
//digitalWrite(ledB, HIGH);
digitalWrite(relayA, !LOW); // ON (active LOW)
digitalWrite(relayB, !LOW); // ON (active LOW)
lcd.setCursor(0, 1);
lcd.print("Pumps ON ");
} else {
// Pump A stops immediately
//digitalWrite(ledA, LOW);
digitalWrite(relayA, !HIGH); // OFF
// Countdown for Pump B
for (int i = 6; i > 0; i--) {
lcd.setCursor(0, 1);
lcd.print("PumpB off in ");
lcd.print(i);
lcd.print("s ");
delay(1000);
}
// After countdown, Pump B stops
//digitalWrite(ledB, LOW);
digitalWrite(relayB, !HIGH); // OFF
lcd.setCursor(0, 1);
lcd.print("Pumps OFF ");
}
delay(500);
}
Pump A
Pump B