Go Down

Topic: Using pot to turn two seperate LEDs on and for a certain length of time (Read 2098 times) previous topic - next topic

CNC101

Hi,

This is my homework project and would greatly appreciate some help.

I am trying to simulate a water tank that has two pumps which are each represented by an LED. I am using a Potentiometer to simulate the water level(i.e 10% travel represents low level and 90% travel represents High water level.)

Basically when the users twists the potentiometer knob to 90% I want to turn one pump on (LED 1 HIGH.) However when it comes on I want to start a timer to countdown from 30s to 0s at which point the second pump (LED2 HIGH) will turn on unless the user winds down to 10% travel within the 30s.

If after 30s of the second pump starting and the travel is still not at 10%, then an alarm should be given (LED 3 HIGH.)

Heres my code so far. I have only managed to turn pump one on at above 90% travel in the void loop:

Code: [Select]

int PumpOne=3;    // Declare Blue LED in pin 3 to simulate Pump 1
int PumpTwo=4;    // Declare Green LED in pin 4 to simulate Pump 2
int Alarm=2;      //Delcare Red LED in pin 2 to simulate Alarm
int TDCRPot=A0;   // Declare Potentiometer(TDCRPot) an int and assign to pin A0 

int TDCRLevel;     //Declare TDCRLevel a variable to read the High and Low
                   //travel of the potentiometer

void setup() {

Serial.begin(9600);      //Turn on Serial monitor for troubleshooting
                         //purposes and set to 9600 baud

pinMode(PumpOne, OUTPUT);    //Declare Blue LED(PumpOne) an output
pinMode(PumpTwo, OUTPUT);    //Declare Green LED(PumpTwo) an output
pinMode(Alarm, OUTPUT);      //Declare Red LED(Alarm) an output
pinMode(TDCRPot, INPUT);      //Declare Potentiometer(TDCRPot) an input
}

void loop() {

TDCRLevel = analogRead(TDCRPot);      //Read the voltage from the Potentiometer pin

if (TDCRLevel >= 1000) {
digitalWrite(PumpOne, HIGH);
digitalWrite(PumpTwo, LOW);
digitalWrite(Alarm, LOW);
}



I have heard of the use of millis() function for timing but I can't get my head around the statements. Any help will be appreciated

septillion

First tip, watch the layout. The IDE really tries to help you by indenting the code so I have no clue how you managed to mess that up.

Second, use a bit more descriptive variable names.

If you number variables, arrays :)

And use the smallers variable that will do.
Code: [Select]

const byte PumpPins[] = {3, 4};
const byte AlarmPin = 2;
const byte LevelPin = A0;


Think of millis() as a clock. It keeps ticking but if you watch it now and then you can time things with it. When you need to start to time something you remember (save to a variable) the time you start. And then you start watching the clock now and then and ask yourself if the time you want to pass has passed. You do that with
Code: [Select]

if(millis() - savedStartTime >= timeToPass){
  //do your thing
}


Good luck!
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

CNC101

Thanks for replying!

I did try and use an array but found the a couple of the LEDs went very dim so am just using const byte for variables atm until i get the sequence correct.

I have so far only managed to delay the second pump (GreenPin,) but only for 10 seconds which I will stick with as I test this code so I am not waiting around! However it doesnt come on 10 seconds after the waterLevel >= 1000, but 10 seconds after it has been uploaded to the board.

Heres the code(Sorry if the layout is not ideal!);

Code: [Select]

const byte BluePin = 3;          //pump one
const byte GreenPin = 4;         //pump two
const byte AlarmPin = 2;         //alarm   
const byte LevelPin = A0;        //potentiometer pin

int waterLevel;     //Declare waterLevel a variable to read the High and Low
                         //travel of the potentiometer

unsigned long start=0;
unsigned long savedStartTime;
float timeToPass=10000;


and the void Loop;
Code: [Select]

void loop() {

waterLevel = analogRead(LevelPin);      //Read the voltage from the Potentiometer pin

if (waterLevel >= 1000) {
digitalWrite(BluePin, HIGH);           //Set pump pin 3 high

}
if (BluePin == HIGH){
start=millis();
savedStartTime=start;
}

if(millis() - savedStartTime >= timeToPass){

  digitalWrite(GreenPin, HIGH);           //Set pump pin 4 high
}
}



I need help telling arduino to start the timer when the pot is >= 1000.

cheers

septillion

I did try and use an array but found the a couple of the LEDs went very dim so am just using const byte for variables atm until i get the sequence correct.
Array can't be the reason for that. Using an array and calling a single member is no different then a normal variable.

Heres the code(Sorry if the layout is not ideal!);
Like I said, the IDE tries to help you  in making the layout easy and clear. Don't know how you manages to mess it up but if you press CTRL+T the IDE will try to help you again :)

And why post the code in two blobs???? It's more work for you to post, it's more work for me to read and a part is missing! (Thanks for using code tags though ;) )

Code: [Select]

const byte BluePin = 3;          //pump one
const byte GreenPin = 4;         //pump two

That's of course completely backwards... You might have a blue led connected to simulate the first pump but the goal is to control a pump. So call it a pump(pin)! You don't change the code to match the test set-up, you change the test set-up to match what you try to debug with it. So keep in mind what you REALLY try to do and just put a big sticky not near the blue led with "PUMP 1" on it if you need to be reminded.

I need help telling arduino to start the timer when the pot is >= 1000.
No you don't ;) If you need to take the bus in 10 minutes, do you change the clock to start from 0:00 so you can see when 10 minutes have passed? Or do you just remember you need to grab a bus and you remember it's 10:29 now so you calculate you need to leave at 10:39?

I hope you do the last and that's how you do it on a micro controller as well. The moment you want to do something in the future you remember the time now and you check to see if the time has passed but only if you want something to happen!

Code: [Select]

if (BluePin == HIGH){

Do you really want to do that? HINT: BluePin is equal to 3....

Code: [Select]

if(millis() - savedStartTime >= timeToPass){

Do you want to do this always if the time has passed? Or do you want to do this if the time has passed AND the pump1 is on? ;)

PS 90% corresponds with a value of 921 of the ADC ;) Not 1000 which is 98%.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

CNC101

I've revamped my code to make it a little simpler and coherent hopefully,( its been stressful because I don't have much programming experience obviously!). I have found the ctrl+t thanks!


Still having trouble with the layout of the first if statement to save the current time and compare it later. The 3rd if statement seems to work. Just to get my head around the timing I am trying to focus on getting Pump 2 on before focusing on the "Alarm" afterwards. For simplicity I have tried to use variables Plim1 and 2 and assigned values instead of an actual reading.

Code: [Select]


const byte Pump1 = 3;  // Declare Blue LED in pin 3 to simulate Pump 1
const byte Pump2 = 4;  // Declare Green LED in pin 4 to simulate Pump 2
const byte Alarm = 2;    //Delcare Red LED in pin 2 to simulate Alarm
const byte TDCRPot = A0; // Declare Potentiometer(TDCRPot) an int and assign to pin A0

int L;     //Declare L a variable to read the High and Low
//travel of the potentiometer

int Plim1 = 1000;       // pot reading for pump 1 turn on
int Plim2 = 1000;       // pot reading for pump 2 turn on
int Llim = 100;         //pot reading to turn both pumps off

unsigned long T;         // current time
unsigned long T1;   // P1  on time
unsigned long Tlim = 3000;

boolean P1 = false;
boolean P2 = false;
boolean Alarmstate = false;

void setup() {

  Serial.begin(9600);      //Turn on Serial monitor for troubleshooting
  //purposes and set to 9600 baud

  pinMode(Pump1, OUTPUT);    //Declare Blue LED(PumpOne) an output
  pinMode(Pump2, OUTPUT);    //Declare Green LED(PumpTwo) an output
  pinMode(Alarm, OUTPUT);      //Declare Red LED(Alarm) an output
  pinMode(TDCRPot, INPUT);      //Declare Potentiometer(TDCRPot) an input

}

void loop() {
  L = analogRead(TDCRPot);      //Read the voltage from the Potentiometer pin
  T = millis();
  if (!P1 && L > Plim1) {
    digitalWrite(Pump1, !P1);
    T1 = T;
  }

  if (Pump1 != P1 && T1 >= Tlim && L > Plim2) {
    digitalWrite(Pump2, !P2);
    T1 = millis();
  }
  if (Pump1 != P1 && L < Llim ) {
    digitalWrite(Pump1, P1);
    digitalWrite(Pump2, P2);
  }
}



septillion

First of all, short variable names are a big NONO. It's short to write but a hell lot easier to remember what each hold. Might be simple now but if the program expends or when somebody else reads to code (which includes future you! ;) ) it's hard. Just give them names that make it clear what it is and that's already a headache less.

Talking about good variable names, what is "TDCRPot" for name? Just call is something like waterLevelPin.

After you changed that I'll have a look again at the code. It's now just to damn hard to read it quick...
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

CNC101

Perfectly understandable. TDCR is shorthand for Transducer in my workplace. I was trying to use the pot as a waterlevel transducer.

Code: [Select]

const byte Pump1 = 3;  // Declare Blue LED in pin 3 to simulate Pump 1
const byte Pump2 = 4;  // Declare Green LED in pin 4 to simulate Pump 2
const byte Alarm = 2;    //Delcare Red LED in pin 2 to simulate Alarm
const byte levelPot = A0; // Declare Potentiometer(levelPot) an int and assign to pin A0

int waterLevel;     //Declare waterLevel a variable to read the High and Low
//travel of the potentiometer

int Pumplimit1 = 1000;       // pot reading for pump 1 turn on
int Pumplimit2 = 1000;       // pot reading for pump 2 turn on
int Lowlimit = 100;         //pot reading to turn both pumps off

unsigned long currentTime;         // current time
unsigned long pumpOnTime;         // Pump  on time
unsigned long intervalTime = 3000;    //Timing interval

boolean Pump1state = false;
boolean Pump2state = false;
boolean Alarmstate = false;

void setup() {

  Serial.begin(9600);      //Turn on Serial monitor for troubleshooting
  //purposes and set to 9600 baud

  pinMode(Pump1, OUTPUT);    //Declare Blue LED(PumpOne) an output
  pinMode(Pump2, OUTPUT);    //Declare Green LED(PumpTwo) an output
  pinMode(Alarm, OUTPUT);      //Declare Red LED(Alarm) an output
  pinMode(levelPot, INPUT);      //Declare Potentiometer(levelPot) an input

}

void loop() {
  waterLevel = analogRead(levelPot);      //Read the voltage from the Potentiometer pin
  currentTime = millis();
  if (!Pump1state && waterLevel > Pumplimit1) {
    digitalWrite(Pump1, !Pump1state);
    pumpOnTime = currentTime;
  }

  if (Pump1 != Pump1state && pumpOnTime >= intervalTime && waterLevel > Pumplimit2) {
    digitalWrite(Pump2, !Pump1state);
    pumpOnTime = millis();
  }
  if (Pump1 != Pump1state && waterLevel < Lowlimit ) {
    digitalWrite(Pump1, Pump1state);
    digitalWrite(Pump2, Pump2state);
  }
}


septillion

Alright. And looks more like it indeed :)

I made some edits + comments. You could even simplify it more if you thought of the Alarm as another "level of pumps" as well but okay
Code: [Select]

//! arryas really make things easier :D
const byte PumpPins[] = {3, 4};
//const byte Pump1 = 3;  // Declare Blue LED in pin 3 to simulate Pump 1
//const byte Pump2 = 4;  // Declare Green LED in pin 4 to simulate Pump 2
//! It's a pin, let us remind us of that
const byte AlarmPin = 2;    //Delcare Red LED in pin 2 to simulate Alarm
//!let' try to use the same notation aka ConstVarName
const byte LevelPotPin = A0; // Declare Potentiometer(levelPot) an int and assign to pin A0

//! Has no reason to be gobal
//int waterLevel;     //Declare waterLevel a variable to read the High and Low
//travel of the potentiometer

//! Why can one limit and the other low limit? Using the same convention really makes things eassier
//! And why two upper limit?
//! And they don' change on runtime so a unsigned const is the right type
/*
int Pumplimit1 = 1000;       // pot reading for pump 1 turn on
int Pumplimit2 = 1000;       // pot reading for pump 2 turn on
int Lowlimit = 100;         //pot reading to turn both pumps off
*/
const unsigned int UpperWaterLimit = 1000; //! Upper limit to turn pump on (NOT 90% though)
const unsigned int LowerWaterLimit = 100; //! Lower limit to turn pumps off

//! No need for a global again
//unsigned long currentTime;         // current time
unsigned long pumpOnTime;         // Pump  on time
//! interval of wat ;)
///unsigned long intervalTime = 3000;    //Timing interval
const unsigned int ExtraPumpInterval = 30000;
const unsigned int AlarmInterval = 30000;

//You can just read that. That way you can't forget to change these state variables
/*
boolean Pump1state = false;
boolean Pump2state = false;
boolean Alarmstate = false;
*/

void setup() {

  Serial.begin(9600);      //Turn on Serial monitor for troubleshooting
  //purposes and set to 9600 baud
 
  //! Yes, for just two this is longer but it scales very easy
  for(byte i = 0; i < sizeof(PumpPins); i++){
    pinMode(PumpPins[i], OUTPUT);
  }

  pinMode(AlarmPin, OUTPUT);      //Declare Red LED(Alarm) an output
  //Don't need to for an analog
  //pinMode(LevelPotPin, INPUT);      //Declare Potentiometer(levelPot) an input

}

void loop() {
  //! const can prevents accidentally changing it
  const unsigned int WaterLevel = analogRead(levelPot);      //Read the voltage from the Potentiometer pin
  const unsigned long CurrentTime = millis();
 
  if (!digitalRead(PumpPins[0] && WaterLevel > UpperWaterLimit) {
    //! This will not change PumpState... What I was talking about forgetting to change the state....
    //digitalWrite(Pump1, !Pump1state);
    digitalWrite(PumpPins[0], HIGH);
    pumpOnTime = CurrentTime;
  }

  else if (digitalRead(PumpPins[0]) && !digitalRead(PumpPins[1]) && currentTime - pumpOnTime >= ExtraPumpInterval) {
    digitalWrite(PumpPins[1], HIGH);
   
    //! Then there was no need to storeCurrentTime...
    //pumpOnTime = millis();
    pumpOnTime = CurrentTime;
  }
 
  else if(digitalRead(PumpPins[1]) && CurrentTime - pumpOnTime >= AlarmInterval){
    digitalWrite(AlarmPin, HIGH);
  }
 
  else if (WaterLevel < LowerWaterLimit ) {
    for(byte i = 0; i < sizeof(PumpPins); i++){
      digitalWrite(PumpPins[i], LOW);
    }
  }
}


Have a look through it. My comments are all prefixed with //!
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

CNC101

One thing is that currentTime in the first else if statement needs to be declared again for some reason. Heres the error message:

*************************************************************
65: error: 'currentTime' was not declared in this scope

   else if (digitalRead(PumpPins[0]) && !digitalRead(PumpPins[1]) && currentTime - pumpOnTime >= ExtraPumpInterval) {

                                                                     
exit status 1
'currentTime' was not declared in this scope
*************************************************************


I changed the pot "analogRead" to A0 so that WaterLevel variable can read from it.


CrossRoads

Add this before setup()
unsigned long CurrentTime;
and then just use CurrentTIme in loop() without redeclaring it.

Same for any other time related variables. They are variable, not const (const get turned into a fixed number in flash).
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

CNC101

Thanks for the input! :)

The probem was when verifying the code I failed to realise that the C in CurrentTime was lower case so it didn't recognise it.

I've gone through all the code and comments intensely however I am getting nothing from my board. I made minor changes to the CurrentTime as suggested. Am I missing boolean operators for the PumpPins?

I kept ExtraPumpInterval = 30000; and AlarmInterval = 30000; as const because that time doesn't change.



Heres the latest:

Code: [Select]

const byte PumpPins[] = {3, 4};
const byte AlarmPin = 2;    //Delcare Red LED in pin 2 to simulate Alarm
const byte LevelPotPin = A0; // Declare Potentiometer(levelPot) an int and assign to pin A0

const unsigned int UpperWaterLimit = 1000; //! Upper limit to turn pump on (NOT 90% though)
const unsigned int LowerWaterLimit = 100; //! Lower limit to turn pumps off

unsigned long CurrentTime;
unsigned long pumpOnTime;         // Pump  on time
const unsigned int ExtraPumpInterval = 30000;
const unsigned int AlarmInterval = 30000;

//You can just read that. That way you can't forget to change these state variables
/*
  boolean Pump1state = false;
  boolean Pump2state = false;
  boolean Alarmstate = false;
*/

void setup() {

  Serial.begin(9600);      //Turn on Serial monitor for troubleshooting
  //purposes and set to 9600 baud

  //! Yes, for just two this is longer but it scales very easy
  for (byte i = 0; i < sizeof(PumpPins); i++) {
    pinMode(PumpPins[i], OUTPUT);
  }

  pinMode(AlarmPin, OUTPUT);      //Declare Red LED(Alarm) an output


}

void loop() {
  //! const can prevents accidentally changing it
  const unsigned int WaterLevel = analogRead(A0);      //Read the voltage from the Potentiometer pin
  unsigned long CurrentTime = millis();

  if (!digitalRead(PumpPins[0] && WaterLevel > UpperWaterLimit)) {
    digitalWrite(PumpPins[0], HIGH);
    pumpOnTime = CurrentTime;
  }

  else if (digitalRead(PumpPins[0]) && !digitalRead(PumpPins[1]) && CurrentTime - pumpOnTime >= ExtraPumpInterval) {
    digitalWrite(PumpPins[1], HIGH);

    pumpOnTime = CurrentTime;
  }

  else if (digitalRead(PumpPins[1]) && CurrentTime - pumpOnTime >= AlarmInterval) {
    digitalWrite(AlarmPin, HIGH);
  }

  else if (WaterLevel < LowerWaterLimit ) {
    for (byte i = 0; i < sizeof(PumpPins); i++) {
      digitalWrite(PumpPins[i], LOW);
    }
  }
}

septillion

Indeed, I changed CurrentTime to start with a capital but I forgot to change that in one place. I indeed forget to try to compile it. Because I now see I missed a bracket on line 62 as well and the analogRead() on line 59 should of course be of LevelPotPin. But I would say those where pretty obvious bugs...

Corrected you get
Code: [Select]


//! arryas really make things easier :D
const byte PumpPins[] = {3, 4};
//const byte Pump1 = 3;  // Declare Blue LED in pin 3 to simulate Pump 1
//const byte Pump2 = 4;  // Declare Green LED in pin 4 to simulate Pump 2
//! It's a pin, let us remind us of that
const byte AlarmPin = 2;    //Delcare Red LED in pin 2 to simulate Alarm
//!let' try to use the same notation aka ConstVarName
const byte LevelPotPin = A0; // Declare Potentiometer(levelPot) an int and assign to pin A0

//! Has no reason to be gobal
//int waterLevel;     //Declare waterLevel a variable to read the High and Low
//travel of the potentiometer

//! Why can one limit and the other low limit? Using the same convention really makes things eassier
//! And why two upper limit?
//! And they don' change on runtime so a unsigned const is the right type
/*
int Pumplimit1 = 1000;       // pot reading for pump 1 turn on
int Pumplimit2 = 1000;       // pot reading for pump 2 turn on
int Lowlimit = 100;         //pot reading to turn both pumps off
*/
const unsigned int UpperWaterLimit = 1000; //! Upper limit to turn pump on (NOT 90% though)
const unsigned int LowerWaterLimit = 100; //! Lower limit to turn pumps off

//! No need for a global again
//unsigned long currentTime;         // current time
unsigned long pumpOnTime;         // Pump  on time
//! interval of wat ;)
///unsigned long intervalTime = 3000;    //Timing interval
const unsigned int ExtraPumpInterval = 30000;
const unsigned int AlarmInterval = 30000;

//You can just read that. That way you can't forget to change these state variables
/*
boolean Pump1state = false;
boolean Pump2state = false;
boolean Alarmstate = false;
*/

void setup() {

  Serial.begin(9600);      //Turn on Serial monitor for troubleshooting
  //purposes and set to 9600 baud
 
  //! Yes, for just two this is longer but it scales very easy
  for(byte i = 0; i < sizeof(PumpPins); i++){
    pinMode(PumpPins[i], OUTPUT);
  }

  pinMode(AlarmPin, OUTPUT);      //Declare Red LED(Alarm) an output
  //Don't need to for an analog
  //pinMode(LevelPotPin, INPUT);      //Declare Potentiometer(levelPot) an input

}

void loop() {
  //! const can prevents accidentally changing it
  const unsigned int WaterLevel = analogRead(LevelPotPin);      //Read the voltage from the Potentiometer pin
  const unsigned long CurrentTime = millis();
 
  if (!digitalRead(PumpPins[0]) && WaterLevel > UpperWaterLimit) {
    //! This will not change PumpState... What I was talking about forgetting to change the state....
    //digitalWrite(Pump1, !Pump1state);
    digitalWrite(PumpPins[0], HIGH);
    pumpOnTime = CurrentTime;
  }

  else if (digitalRead(PumpPins[0]) && !digitalRead(PumpPins[1]) && CurrentTime - pumpOnTime >= ExtraPumpInterval) {
    digitalWrite(PumpPins[1], HIGH);
  
    //! Then there was no need to storeCurrentTime...
    //pumpOnTime = millis();
    pumpOnTime = CurrentTime;
  }
 
  else if(digitalRead(PumpPins[1]) && CurrentTime - pumpOnTime >= AlarmInterval){
    digitalWrite(AlarmPin, HIGH);
  }
 
  else if (WaterLevel < LowerWaterLimit ) {
    for(byte i = 0; i < sizeof(PumpPins); i++){
      digitalWrite(PumpPins[i], LOW);
    }
  }
}


@CrossRoads, I would say that's the most terrible advice I have ever seen you give... If somethings not defined, just define a global...

And yes, the are const and no, it does not get turned into flash because they are not global. Each loop() they are created with a fixed value so you can't accidentally change them in the loop() but at the end they just get destroyed so next loop() they can be defined again with new values.

This is useful for situations like for example
Code: [Select]

if(WaterLevel = UpperWaterLimit){
  //do this
}

Instead of giving you a bug because you accidentally set WaterLevel to a value instead of checking it, it will give you a nice error on compiling. Const correctness, really useful ;) In this case I don't try to check for equality but it's nice to get into the habit of doing it right. I have to admit I also don't always do it right but it's a great tool to help you if you're const correct.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

CNC101

Thanks for replying. :)

My board is still not lighting up. Is this a True/False situation?

i.e
Code: [Select]

//You can just read that. That way you can't forget to change these state variables
/*
  boolean Pump1state = false;
  boolean Pump2state = false;
  boolean Alarmstate = false;
*/


What you were talking about there?


septillion

What I meant there is that if you make a variable to hold the state it's up to you to keep it in sync with the real output. So it's easier to just read the real output.

But I can't spot the problem here... This block should at least turn on the first pump if you turn the pot up to max
Code: [Select]

  if (!digitalRead(PumpPins[0]) && WaterLevel > UpperWaterLimit) {
    //! This will not change PumpState... What I was talking about forgetting to change the state....
    //digitalWrite(Pump1, !Pump1state);
    digitalWrite(PumpPins[0], HIGH);
    pumpOnTime = CurrentTime;
  }
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

CNC101

Not to worry I've fixed it! There was a missing bracket in the first if statement. :)

Just two last questions:

I'm fiddling with the last else if statement to get the alarm pin to go LOW as well as the other two when WaterLevel < LowerWaterLevel. I've tried putting

 
Code: [Select]
digitalWrite(AlarmPin, LOW)

and similar but when the alarm pin is high after 30s of pump2 and I move the pot to < LowerWaterLevel they all stay on regardless. How would I get around this?

Last question and this seems tricky. How would I set it up to give even loading of the pumps? i.e  if on one cycle Pump1 starts first and Pump2 is the 'back up' then on the next cycle Pump2 will start first and Pump1 is the 'back up'.

Seems like a switcheroo function is needed but I have no idea what one is called or implemented. Other than that it works like a dream!
 

Go Up