The First Pressure Based Switching Controlled Pump Plc
The First Pressure Based Switching Controlled Pump Plc
#include <LiquidCrystal.h>
const int inputPin = 6; // Original input pin for controlling the pumps
const int pump1Pin = 8; // Pump 1 (to be inverted)
const int pump2Pin = 9; // Pump 2 (to be inverted)
const int pump3Pin = 10; // Pump 3 (to be inverted)
const int controlLedPin = 7; // Control LED pin (shows pump activity)
const int pushToReadPin = 13; // Push-to-read switch pin
const int modeSwitchPin = A2; // Mode switch pin (to toggle to threshold setting
screen)
const int lowPressureLedPin = A5;// LED to indicate low pressure (stays HIGH when
pressure is low)
const int vfdLedPin = A1; // VFD LED pin (activates when pumps are running)
void setup() {
// Setup original hardware
pinMode(inputPin, INPUT);
pinMode(pump1Pin, OUTPUT);
pinMode(pump2Pin, OUTPUT);
pinMode(pump3Pin, OUTPUT);
pinMode(controlLedPin, OUTPUT); // Control LED pin
pinMode(pushToReadPin, INPUT_PULLUP); // Push-to-read button
pinMode(modeSwitchPin, INPUT_PULLUP); // Mode switch for threshold screen
pinMode(lowPressureLedPin, OUTPUT); // Low pressure LED (A5)
pinMode(vfdLedPin, OUTPUT); // VFD LED (A0)
// Start with all pumps and LEDs off (inverted logic for pumps)
digitalWrite(pump1Pin, LOW); // Pump 1 OFF (inverted logic)
digitalWrite(pump2Pin, LOW); // Pump 2 OFF (inverted logic)
digitalWrite(pump3Pin, LOW); // Pump 3 OFF (inverted logic)
digitalWrite(controlLedPin, LOW); // Control LED OFF (not inverted)
digitalWrite(lowPressureLedPin, LOW); // Low pressure LED OFF initially
digitalWrite(vfdLedPin, LOW); // VFD LED OFF initially
void loop() {
unsigned long currentTime = millis();
// Turn Control LED ON if the timer has passed and input is HIGH
if (controlLedActive && currentTime >= controlLedTimer && inputState == HIGH) {
digitalWrite(controlLedPin, HIGH); // Turn on Control LED
}
}
lastModeSwitchState = modeSwitchState;
if (pump2On) {
digitalWrite(pumpOrder[1], LOW); // Turn OFF the second pump in the order
pump2On = false;
Serial.println("Second Pump OFF");
delay(closeDelay);
}
if (pump3On) {
digitalWrite(pumpOrder[2], LOW); // Turn OFF the third pump in the order
pump3On = false;
Serial.println("Third Pump OFF");
delay(closeDelay);
}
cycleCount = (cycleCount + 1) % 3; // Increment cycleCount for the next cycle
startTime = currentTime;
}
}
// Function to update the LCD display based on mode and screen toggling
void updateLCD() {
lcd.clear(); // Clear the screen
if (isInThresholdMode) {
// Screen to set pressure thresholds
lcd.setCursor(0, 0);
lcd.print("Set Pressure Limits");
lcd.setCursor(0, 1);
lcd.print("High Threshold: ");
lcd.print(highThreshold, 2); // Display high threshold with 2 decimal points
lcd.setCursor(0, 2);
lcd.print("Low Threshold: ");
lcd.print(lowThreshold, 2); // Display low threshold with 2 decimal points
lcd.setCursor(0, 3);
lcd.print("Press Mode to Exit");
} else if (displayPressureScreen) {
// Display the pressure and pump statuses when the push-to-read switch is
pressed
lcd.setCursor(0, 0);
lcd.print("PRESSURE: ");
lcd.print((analogRead(A0) * (5.0 / 1023.0)) * 6.0, 2); // Convert to BAR
lcd.setCursor(0, 1);
lcd.print("PUMP1=");
lcd.print(digitalRead(pump1Pin) == HIGH ? "ON " : "OFF");
lcd.setCursor(10, 1);
lcd.print("PUMP2=");
lcd.print(digitalRead(pump2Pin) == HIGH ? "ON " : "OFF");
lcd.setCursor(0, 2);
lcd.print("PUMP3=");
lcd.print(digitalRead(pump3Pin) == HIGH ? "ON " : "OFF");
lcd.setCursor(10, 3);
lcd.write(byte(1)); // Display the custom icon
lcd.setCursor(11, 3);
lcd.print("RIK & SUBHRO");
} else {
// Default screen (COSMOS screen)
lcd.setCursor(0, 0);
lcd.print("*******COSMOS*******");
lcd.setCursor(0, 1);
lcd.print("PUMP PLC T5 ROSEDALE");
lcd.setCursor(0, 2);
lcd.print("PUMP1=");
lcd.print(digitalRead(pump1Pin) == HIGH ? "ON " : "OFF");
lcd.setCursor(10, 2);
lcd.print("PUMP2=");
lcd.print(digitalRead(pump2Pin) == HIGH ? "ON " : "OFF");
lcd.setCursor(0, 3);
lcd.print("PUMP3=");
lcd.print(digitalRead(pump3Pin) == HIGH ? "ON " : "OFF");
lcd.setCursor(10, 3);
lcd.write(byte(0)); // Display the custom clock icon
lcd.setCursor(11, 3);