/*NOTES:
Sketch to supply treated water to a hydroponics system.
A 12V DC water level board controls 9V power to an Arduino Uno R3 through a step down converter.
When the water is low the water level board switches power on to a water supply solenoid which is connected to the Arduino Uno R3 via a Normally Closed solenoid relay.
When the treated water tank begins to fill, a float level switch (2) in the bottom of the treated water tank closes and powers up the Uno.
The Uno then switches on a solution stirrer motor and a peristaltic pump feeding solution into the treated water tank for fixed time periods.
When the peristaltic pump stops the solution stirrer then stops.
When the water tank is full (float level switch 1 in the top of the treated water tank opens) the Uno turns off the water supply solenoid via the Normally Closed solenoid relay.
It then turns on the water transfer pump to feed hydroponic trays.
When the water tank drains, causing the water level switch 2 to open. The open circuit switches off the Uno.
*/
const byte relayDoingWhatPin = 2;
const byte stirrerMotorPin = 3;
const byte periPumpPin = 4;
const byte waterPumpPin = 5;
const byte floatSwitchPin = 6;
const byte ON = HIGH;
const byte OFF = LOW;
const byte relayOff = HIGH;
const byte relayOn = LOW;
void setup() {
Serial.begin(115200);
Serial.println("Setup-Start");
pinMode(relayDoingWhatPin, OUTPUT); // no comment needed constant-name explains itself
pinMode(stirrerMotorPin, OUTPUT); // no comment needed constant-name explains itself
pinMode(periPumpPin, OUTPUT); // no comment needed constant-name explains itself
pinMode(waterPumpPin, OUTPUT); // no comment needed constant-name explains itself
pinMode(floatSwitchPin, INPUT_PULLUP); // no comment needed constant-name explains itself
}
void loop() {
digitalWrite(stirrerMotorPin, ON); // no comment needed constant-name explains itself
delay(2000); // wait 20 seconds to get solution moving
digitalWrite(periPumpPin, ON); // no comment needed constant-name explains itself
delay(2000); // delay time 20 sec to measure fertilizer
digitalWrite(periPumpPin, OFF); // no comment needed constant-name explains itself
digitalWrite(stirrerMotorPin, OFF); // no comment needed constant-name explains itself
// as long as the IO-pin connected to floatSwitchPin has logic level LOW
// stay INSIDE the while-loop executing the commands INSIDE the while-loop
while (digitalRead(floatSwitchPin) == LOW) { // wait until float switch 1 shows treated water tank is full
digitalWrite(relayDoingWhatPin, relayOff); // no comment needed constant-name explains itself
digitalWrite(waterPumpPin, ON); // no comment needed constant-name explains itself
}
}