int currentState1;
int currentState2;
int currentState3;
int currentState4;
int buttomfull = LOW;
void setup() {
Serial.begin(9600);
Serial.println("Begin");
pinMode(13, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
pinMode(27, INPUT_PULLUP);
pinMode(22, OUTPUT); //to run pump
}
void loop() {
currentState1 = digitalRead(13); //deep well empty water
currentState2 = digitalRead(12); //deep well enough water
currentState3 = digitalRead(14); //enough level to add water
currentState4 = digitalRead(27); //max water level on tank
if (currentState1 == HIGH || currentState4 == LOW){
digitalWrite(22, LOW);
if (currentState1 == HIGH)
buttomfull = LOW;
}
else if (currentState4 == HIGH && buttomfull == HIGH) {
if (currentState3 == HIGH )
digitalWrite(22,HIGH);
}
else if (currentState1 == LOW )
if (currentState2 == LOW){
digitalWrite(22, HIGH);
buttomfull = HIGH;
}
else
digitalWrite(22,LOW);
}