i have modified a sketch to sense the water levels in my sump tank,automatic top-off holding tank,and my water change holding tank for my saltwater aquarium system i am putting together here is the complete code
byte sumplowWaterPin = 32;
byte atolowWaterPin = 33;
byte wclowWaterPin = 34;
byte sumphighWaterPin = 35;
byte atohighWaterPin = 36;
byte wchighWaterPin = 37;
byte sumppumpPin = 28;
byte atopumpPin = 29;
byte wcpumpPin = 30;
unsigned long maxsumpRunTime = 8000;
unsigned long maxsatoRunTime = 8000;
unsigned long maxwcRunTime = 8000;
unsigned long minsumpOffTime = 4000;
unsigned long minatoOffTime = 4000;
unsigned long minwcOffTime = 4000;
unsigned long sumpswitchDebounceTime = 10;
unsigned long atoswitchDebounceTime = 10;
unsigned long wcswitchDebounceTime = 10;
unsigned long lastsumpPumpTime = 0;
unsigned long lastatoPumpTime = 0;
unsigned long lastwcPumpTime = 0;
unsigned long lastsumplowWaterDetectTime = 0;
unsigned long lastatolowWaterDetectTime = 0;
unsigned long lastwclowWaterDetectTime = 0;
boolean lastlowsumpWaterState = HIGH;
boolean lastlowatoWaterState = HIGH;
boolean lastlowwcWaterState = HIGH;
boolean sumppumpRunning = true;
boolean atopumpRunning = true;
boolean wcpumpRunning = true;
void setup() {
Serial.begin (9600);
pinMode (sumplowWaterPin, INPUT_PULLUP);
pinMode (atolowWaterPin, INPUT_PULLUP);
pinMode (wclowWaterPin, INPUT_PULLUP);
pinMode (sumphighWaterPin, INPUT_PULLUP);
pinMode (atohighWaterPin, INPUT_PULLUP);
pinMode (wchighWaterPin, INPUT_PULLUP);
pinMode (sumppumpPin, OUTPUT);
pinMode (atopumpPin, OUTPUT);
pinMode (wcpumpPin, OUTPUT);
}
void loop () {
unsigned long currentMillis = millis();
boolean lowsumpWaterState = digitalRead(sumplowWaterPin);
boolean highsumpWaterState = digitalRead(sumphighWaterPin);
if(lowsumpWaterState != lastlowsumpWaterState){
lastsumplowWaterDetectTime = currentMillis;
}
if (sumppumpRunning) { // if the pump is on then let's see if we should turn it off yet
if ((highsumpWaterState == HIGH) || (currentMillis - lastsumpPumpTime >= maxsumpRunTime)){
digitalWrite(sumppumpPin, HIGH);
sumppumpRunning = false;
lastsumpPumpTime = currentMillis;
}
}
else { // pump is not running, see if we need to turn it on
if((lowsumpWaterState == HIGH) && (currentMillis - lastsumplowWaterDetectTime >= sumpswitchDebounceTime) && (currentMillis - lastsumpPumpTime > minsumpOffTime)){ // switch is low and has been for at least 3 seconds
digitalWrite(sumppumpPin, LOW);
sumppumpRunning = true;
lastsumpPumpTime = currentMillis;
}
}
lastlowsumpWaterState = lowsumpWaterState;
}
boolean lowatoWaterState = digitalRead(atolowWaterPin);
boolean highatoWaterState = digitalRead(atohighWaterPin);
if(lowatoWaterState != lastlowatoWaterState){
lastatolowWaterDetectTime = currentMillis;
}
if (atopumpRunning) { // if the pump is on then let's see if we should turn it off yet
if ((highatoWaterState == HIGH) || (currentMillis - lastatoPumpTime >= maxatoRunTime)){
digitalWrite(atopumpPin, HIGH);
atopumpRunning = false;
lastatoPumpTime = currentMillis;
}
}
else { // pump is not running, see if we need to turn it on
if((lowatoWaterState == HIGH) && (currentMillis - lastatolowWaterDetectTime >= atoswitchDebounceTime) && (currentMillis - lastatoPumpTime > minatoOffTime)){ // switch is low and has been for at least 3 seconds
digitalWrite(atopumpPin, LOW);
atopumpRunning = true;
lastatoPumpTime = currentMillis;
}
}
lastlowatoWaterState = lowatoWaterState;
}
boolean lowwcWaterState = digitalRead(wclowWaterPin);
boolean highwcWaterState = digitalRead(wchighWaterPin);
if(lowwcWaterState != lastlowwcWaterState){
lastwclowWaterDetectTime = currentMillis;
}
if (wcpumpRunning) { // if the pump is on then let's see if we should turn it off yet
if ((highwcWaterState == HIGH) || (currentMillis - lastwcPumpTime >= maxwcRunTime)){
digitalWrite(wcpumpPin, HIGH);
wcpumpRunning = false;
lastwcPumpTime = currentMillis;
}
}
else { // pump is not running, see if we need to turn it on
if((lowwcWaterState == HIGH) && (currentMillis - lastwclowWaterDetectTime >= wcswitchDebounceTime) && (currentMillis - lastwcPumpTime > minwcOffTime)){ // switch is low and has been for at least 3 seconds
digitalWrite(wcpumpPin, LOW);
wcpumpRunning = true;
lastwcPumpTime = currentMillis;
}
}
lastlowwcWaterState = lowwcWaterState;
}
it compiles until i added
boolean lowatoWaterState = digitalRead(atolowWaterPin);
boolean highatoWaterState = digitalRead(atohighWaterPin);
if(lowatoWaterState != lastlowatoWaterState){
lastatolowWaterDetectTime = currentMillis;
}
if (atopumpRunning) { // if the pump is on then let's see if we should turn it off yet
if ((highatoWaterState == HIGH) || (currentMillis - lastatoPumpTime >= maxatoRunTime)){
digitalWrite(atopumpPin, HIGH);
atopumpRunning = false;
lastatoPumpTime = currentMillis;
}
}
else { // pump is not running, see if we need to turn it on
if((lowatoWaterState == HIGH) && (currentMillis - lastatolowWaterDetectTime >= atoswitchDebounceTime) && (currentMillis - lastatoPumpTime > minatoOffTime)){ // switch is low and has been for at least 3 seconds
digitalWrite(atopumpPin, LOW);
atopumpRunning = true;
lastatoPumpTime = currentMillis;
}
}
lastlowatoWaterState = lowatoWaterState;
}
boolean lowwcWaterState = digitalRead(wclowWaterPin);
boolean highwcWaterState = digitalRead(wchighWaterPin);
if(lowwcWaterState != lastlowwcWaterState){
lastwclowWaterDetectTime = currentMillis;
}
if (wcpumpRunning) { // if the pump is on then let's see if we should turn it off yet
if ((highwcWaterState == HIGH) || (currentMillis - lastwcPumpTime >= maxwcRunTime)){
digitalWrite(wcpumpPin, HIGH);
wcpumpRunning = false;
lastwcPumpTime = currentMillis;
}
}
else { // pump is not running, see if we need to turn it on
if((lowwcWaterState == HIGH) && (currentMillis - lastwclowWaterDetectTime >= wcswitchDebounceTime) && (currentMillis - lastwcPumpTime > minwcOffTime)){ // switch is low and has been for at least 3 seconds
digitalWrite(wcpumpPin, LOW);
wcpumpRunning = true;
lastwcPumpTime = currentMillis;
}
}
lastlowwcWaterState = lowwcWaterState;
}
these lines then i get an error stating
expected unqualified-id before "if"
watersketch:95: error: expected unqualified-id before "if"
watersketch:100: error: expected unqualified-id before "if"
yes i did a bunch of copy and pasting i am a newbie to arduino but i am learning
i did a google search for this but nothing turned up a usable solution to my problem if some one could look at this and make a suggestion as to how i should fix it i would appreciate it
James
PS i know its something dumb that i have done