Would appreciate any feedback on my sketch. I am multi-tasking today smoking some Boston Butts, watching olympic golf and writing a sketch. I am still waiting on some parts so cant test yet. I do a lot of coding in VBA which is completely different from the loop environment in Arduino. So not positive I got this correct.
Most of this description is repeated in the comments in the code. However, to sum it up, this is will control my reverse osmosis de-ionizing resin water purification unit. There will be three solenoids in the system, one on RODI input line, one on the output line and one on the flow restrictor bypass line to auto flush the membrane. The output of the RODI unit empties into a barrel with two float switches. The lower switch will initiate the fill mode and the higher switch terminate the fill mode.
When not filling all solenoids are closed (they are NC), when fill mode initiates (caused by the lower float closing) the input and output solenoids are opened and remain open until the upper float closes. On fill mode initiation the bypass solenoid will open for 20 seconds and do so each hour while in fill mode.
The solenoids will have a separate power source and be switched on by a jbtek 4 channel relay. Three relays for the solenoids and the fourth will run an outlet for a small pump that will be added later.
It did compile successfully but I am just not sure of the functionality.
Thanks again for taking a look. I appreciate any feedback!
Edit: forgot to mention I am using a mega, overkill but what I have on hand.
/*Reverse Osmosis De-Ionizing Water System Controller
*
* Water container with HighLevel (shutoff) float valve
* and LowLevel (initiate) float valve.
* Three solenoids on RODI unit all 4pack relay driven 12V:
* BypassSol (bypasses flow restricter for flush)
* OutputSol (opens/closes output line)
* InputSol (opens/closes input water line)
* Outlet: fourth relay controls 120V Outlet
*
* Theory of operation:
* Default state FillMode off (all solenoids closed)
* If LowLevl closes then FillMode on
* If FillMode on then InputSol and OutputSol Open
* When FillMode on open BypassSol for 20 seconds
* While FillMode on open BypassSol for 20 secondes every hour
* If HighLevel closes FillMode off
*
*/
const int BypassSol = 6;
const int OutputSol = 7;
const int InputSol = 8;
const int Outlet = 9;
const int HighLevel = 5;
const int LowLevel = 3;
boolean FillMode = false;
unsigned long HourTimer = 0;
unsigned long FlushTime = 0;
const long HourInterval = 3600000;
const long FlushInterval = 20000;
void setup() {
// Initiate serial coms
Serial.begin(9600);
pinMode(BypassSol,OUTPUT);
pinMode(OutputSol,OUTPUT);
pinMode(InputSol,OUTPUT);
pinMode(Outlet,OUTPUT);
pinMode(HighLevel,INPUT_PULLUP);
pinMode(LowLevel,INPUT_PULLUP);
}
void loop() {
unsigned long currentMillis = millis();
//
if (FillMode == false) {//if not in fillmode
if (LowLevel == LOW) {//if lowlevel float closes turn fillmode on
FillMode = !FillMode;
digitalWrite(BypassSol, HIGH);//turn bypass on for 20 secs to flush
delay (20000); //20 sec delay no issue for overflow
digitalWrite(BypassSol, LOW);
HourTimer = currentMillis;
}else{
//while not in fillmode all solenoids closed.
digitalWrite(OutputSol, LOW);
digitalWrite(BypassSol, LOW);
digitalWrite(InputSol, LOW);
digitalWrite(Outlet, LOW);
}
}else{//fillmode on
//while fill mode is on the following three solenoids are always open
digitalWrite(OutputSol, HIGH);
digitalWrite(InputSol, HIGH);
digitalWrite(Outlet, HIGH);
if (HighLevel == LOW){//if high level float closes turn fill mode off
FillMode = !FillMode;
}else{
if (currentMillis - HourTimer >= HourInterval){
digitalWrite(BypassSol, HIGH);//turn bypass on for 20 secs to flush
delay (20000); //20 sec delay no issue for overflow
digitalWrite(BypassSol, LOW);
HourTimer = currentMillis;
}
}
}
}