Hi there,
I am doing a project with this scenario:
The water level in the sump is to be controlled as follows:
If the level reaches high one pump will start to pump out.
If the level does not reach low within about 30 seconds, the second pump will come into action. If the level does reach low before 30 second
pumping should stop.
If the level does not reach low within about 30 seconds of the second
pump starting, an alarm is given. The alarm is sounded until the level reaches low. If the level does reach low before 30 seconds the pumping should stop.
The pumps will stop when low is detected.
To give even loading of the pumps they are to be used alternately, e.g. if
on one pump cycle P1 starts first and P2 is the ‘back up’ then on the next cycle P2 will start first and P1 is the ‘back up’.
I am using a potentiometer to act as a level sensor and LEDs to represent the pumps. I think i have the code for the operation of the pumps sorted, i just cannot figure out how to alternate which pump is used first. So if pump 1 starts first, then in the next loop pump 2 will start first and vice versa.
/*This code is for the control of water level in a sump. This is done using a potentiometer to measure the water level, two pumps to pump the water out and
an alarm which warns the operator of the system failing to pump water to the low level after a set amount of time.
A potentiometer is used to sense the water level, full will be indicated by an output of 1023, empty by an output of 0, LOW level will be indicated by 10%
of 1023 and HIGH level will be indicated by 90% of 1023.
FULL - 1023
HIGH - 921
LOW - 102
EMPTY - 0
An LED is used here to represent each water pump.
The system will alternate which pump starts first to conserve the life of the pumps.
*/
int Pump1 = 8; //An LED to represent Pump 1 is installed at pin 8.
int Pump2 = 9; //An LED to represent Pump 2 is installed at pin 9.
int Alarm = 7; //The alarm is installed at pin 7.
int potPin = A5; //The water level sensing potentiometer is installed at pin analog pin A5.
int potValue = 0;
void setup() {
pinMode(Pump1, OUTPUT); //Designate Pump 1 at pin 8 as an OUTPUT.
pinMode(Pump2, OUTPUT); //Designate Pump 2 at pin 9 as an OUTPUT.
pinMode(Alarm, OUTPUT); //Designate the alarm at pin 7 as an OUTPUT.
}
void loop() {
int sensorValue = analogRead(A5); //Read the input from the analog Water level sensing potentiometer.
if (analogRead(sensorValue) <= 921); //The system is monitoring the water level. If the level does not reach HIGH, system will not do anything.
digitalWrite(Pump1 , LOW);
if (analogRead(sensorValue) >= 921); //If water level reaches the HIGH level, the first pump will begin to work.
digitalWrite(Pump1, HIGH);
delay(30000); //The system will now wait 30 seconds. If the water level has not fell to the LOW level, pump 2 will start.
if (analogRead(sensorValue) <= 102); //If the water has now reached LOW, Pump 1 will turn off.
digitalWrite(Pump1 , LOW);
if (analogRead(sensorValue) >= 102); //If the water has still not reached LOW, Pump 2 will also turn on.
digitalWrite(Pump2 , HIGH);
delay(30000); //The system will now wait a further 30 seconds.
if (analogRead(sensorValue) <= 102); //If the water level has fallen to LOW then both pumps will turn off, if not then both pumps will remain on.
digitalWrite(Pump1 & Pump2 , LOW); //If the level has not fallen to LOW then a warning alarm will sound to alert the operator.
if (analogRead(sensorValue) >= 102);
digitalWrite(Pump1 & Pump2 , HIGH);
digitalWrite(Alarm, HIGH);
delay(30000); //The system will wait a further 30 seconds.
if (analogRead(sensorValue) <= 102); //If the water level has reached LOW, the pumps and the alarm will turn off.
digitalWrite(Pump1 & Pump2 & Alarm , LOW);
if (analogRead(sensorValue) >= 102); //If the water level has not reached LOW, the pumps will turn off but the alarm will remain on until LOW is reached.
digitalWrite(Pump1 & Pump2 , LOW);
digitalWrite(Alarm, HIGH);
if (analogRead(sensorValue) <= 102); //Once the LOW level has been reached, the alarm will silence.
digitalWrite(Alarm, LOW);
}