This is my first attempt at a sketch to feed hydro plants with fertilized water.
I expect there is poor programming in the code because I am new to it.
Apart from other probable programming mistakes I need to know why the while loop doesn't work?
Just advice on how to make that work would be greatly appreciated.
Here is my sketch. The notes describe what I've set out to do.
/*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.
*/
void setup() {
pinMode(2, OUTPUT); // 12V NC relay to switch off solenoid connected direct to UNO
pinMode(3, OUTPUT); // 12V growing solution stirrer motor through 12V relay module
pinMode(4, OUTPUT); // 12V peristaltic solution injection pump through 12V relay module
pinMode(5, OUTPUT); // 12V pump treated water to trays through 12V relay module
pinMode(6, INPUT_PULLUP); // float switch 1 (full holding tank) connected direct to UNO
}
void loop() {
digitalWrite(3, HIGH); // switch on growing solution stirrer motor
//delay(20000); // wait 20 seconds to get solution moving
digitalWrite(4, HIGH); // switch on peristaltic solution injection pump
//delay(20000); // delay time 20 sec to measure fertilizer
digitalWrite(4, LOW); // switch off peristaltic solution injection pump
digitalWrite(3, LOW); // switch off growing solution stirrer motor
while (digitalRead(6) == LOW) // wait until float switch 1 shows treated water tank is full
{
digitalWrite(2, HIGH); // switch off water supply solenoid
digitalWrite(5, HIGH); // run treated water pump to tray
}
}
