i need to interchange three pumps. selection of pump will be based on running time. the minimum driven pump should start on next time. no pump should run continuously more than 15 minutes ( pump should interchange after 15 minutes).
by using one input(runing switch) pin and 3 out put(3 pumps) pins .
when the input pin is high.. one of the out put pin shoud be high. according to the above conditions.
please tell me is it posible to do with arduino? im a beginer to this and if u can provide me some assistance it i will be thankfull for u.
thank u!
const int NumberOfPumps = 3;
unsigned long PumpRunTimes[NumberOfPumps]; // Total run times in seconds
unsigned long ContinuousRunTime = 0;
int ActivePump = -1; // No pumps are active
const int SwitchPin = 2;
const int PumpPins[NumberOfPumps] = {3, 4, 5};
void setup() {
pinMode(SwitchPin, INPUT);
PumpsOff();
for (int i=0; i<NumberOfPumps; i++) {
pinMode(PumpPins[i], OUTPUT);
}
}
void loop() {
static unsigned long lastTime;
unsigned long currentTime = millis();
if (currentTime - lastTime > 1000) {
lastTime = currentTime;
// Every second:
if (digitalRead(SwitchPin) == LOW) {
PumpsOff();
}
else {
// Switch input is HIGH
if (ActivePump == -1) { // No pumps are active
StartAPump();
}
else {
// A pump is already running
PumpRunTimes[ActivePump]++;
ContinuousRunTime++;
if (ContinuousRunTime > 15*60) {
// Pump has been running 15 minutes. Switch to a different one
StartAPump(); // Will not choose ActivePump
}
}
}
}
}
void PumpsOff() {
for (int i=0; i<NumberOfPumps; i++) {
digitalWrite(PumpPins[i], LOW);
}
ActivePump = -1;
ContinuousRunTime = 0;
}
// Start the least-used pump that is not the ActivePump
void StartAPump() {
unsigned long lowestRunTime = 0xFFFFFFFFUL;
for (int i=0; i<NumberOfPumps; i++) {
digitalWrite(PumpPins[i], LOW);
if (i != ActivePump && PumpRunTimes[i] < lowestRunTime) {
lowestRunTime = PumpRunTimes[i];
ActivePump = i;
}
} // end of search for least used pump
ContinuousRunTime = 0; // Start the 15-minuter timer
digitalWrite(PumpPins[ActivePump], HIGH);
}