OK..
I cutted the watering process to small steps and I made it as simple as I can. Only the watering process. Serial monitor gives me this all at once without any delays.. after this nothing happens. What is wrong with the delays here?
Starting
Drain Valve Open
Drain Valve Closed
Main Valve Open
Fertilizer Pump 1 (GROW) Open
Fertilizer Pump 1 (GROW) Closed
Fertilizer Pump 2 (BLOOM) Open
Fertilizer Pump 2 (BLOOM) Closed
Fertilizer Pump 3 (MICRO) Open
Fertilizer Pump 3 (MICRO) Closed
Drain Valve Open
// --------CONSTANTS (won't change)---------------
#define DHTPIN 0 //D3
#define DHTPIN 2 //D4
#define DHTPIN 14 //D5
#define DHTPIN 12 //D6
#define DHTPIN 13 //D7
#define DHTPIN 15 //D8
#define DHTPIN 16 //D0
const int RELAY1 = D3; //Main Valve
const int RELAY2 = D4; //Lights ON/OFF
const int RELAY6 = D8; //Drain Valve
const int RELAY3 = D5; //Fertilizer Pump 1 GROW
const int RELAY4 = D6; //Fertilizer Pump 2 BLOOM
const int RELAY5 = D7; //Fertilizer Pump 3 MICRO
const int DrainValvePeriod = 5000; //Drain Valve period
const int FertilizerPump1BLOOMPeriod = 5000; //Fertilizer Pump 1 GROW ON BLOOMMIX period
const int FertilizerPump2BLOOMPeriod = 5000; //Fertilizer Pump 2 BLOOM ON BLOOMMIX period
const int FertilizerPump3BLOOMPeriod = 5000; //Fertilizer Pump 3 MICRO ON BLOOMMIX period
////------------ VARIABLES (will change)---------------------
byte MainValveState = LOW;
byte DrainValveState = LOW;
byte FertilizerPump1State = LOW;
byte FertilizerPump2State = LOW;
byte FertilizerPump3State = LOW;
unsigned long DrainValveStartMillis;
unsigned long FertilizerPump1BLOOMStartMillis;
unsigned long FertilizerPump2BLOOMStartMillis;
unsigned long FertilizerPump3BLOOMStartMillis;
unsigned long DrainValveCurrentMillis = 0;
unsigned long FertilizerPump1BLOOMCurrentMillis = 0;
unsigned long FertilizerPump2BLOOMCurrentMillis = 0;
unsigned long FertilizerPump3BLOOMCurrentMillis = 0;
//========================================
void setup() {
Serial.begin(115200);
delay (2000);
Serial.println("\Starting");
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);
pinMode(RELAY5, OUTPUT);
pinMode(RELAY6, OUTPUT);
digitalWrite(RELAY1, LOW); // set Main Valve OFF
digitalWrite(RELAY2, LOW); // set LIGHTS OFF
digitalWrite(RELAY3, LOW); // set Fertilizer Pump 1 GROW OFF
digitalWrite(RELAY4, LOW); // set Fertilizer Pump 2 BLOOM OFF
digitalWrite(RELAY5, LOW); // set Fertilizer Pump 3 MICRO OFF
digitalWrite(RELAY6, LOW); // set Drain Valve OFF
}
//========================================
void loop() {
DrainValveCurrentMillis = millis();
DrainValveBLOOM();
}
void DrainValveBLOOM()
{
if (DrainValveState == LOW)
{
digitalWrite(RELAY6, HIGH); //change the state of the Drain Valve to Open
Serial.println("Drain Valve Open");
DrainValveState = HIGH;
if (DrainValveCurrentMillis - DrainValveStartMillis >= DrainValvePeriod) //test whether the period has elapsed
{
digitalWrite(RELAY6, LOW); //if so, change the state of the Drain Valve to Closed
DrainValveState = LOW;
Serial.println("Drain Valve Closed");
DrainValveStartMillis = DrainValveCurrentMillis; //IMPORTANT to save the start time of the current RELAY state.
MainValveBLOOM();
}
}
}
void MainValveBLOOM()
{
if (DrainValveState == LOW)
{
digitalWrite(RELAY1, HIGH); //change the state of the Main Valve to Open
Serial.println("Main Valve Open");
MainValveState = HIGH;
FertilizerPump1BLOOMCurrentMillis = millis();
Fert1BLOOM();
}
}
void Fert1BLOOM()
{
digitalWrite(RELAY3, HIGH); //change the state of the Fertilizer Pump 1 (GROW) to Open
Serial.println("Fertilizer Pump 1 (GROW) Open");
FertilizerPump1State = HIGH;
if (FertilizerPump1BLOOMCurrentMillis - FertilizerPump1BLOOMStartMillis >= FertilizerPump1BLOOMPeriod) //test whether the period has elapsed
{
digitalWrite(RELAY3, LOW); //if so, change the state of the Fertilizer Pump 1 (GROW) to Closed
FertilizerPump1State = LOW;
FertilizerPump1BLOOMStartMillis = FertilizerPump1BLOOMCurrentMillis; //IMPORTANT to save the start time of the current RELAY state.
Serial.println("Fertilizer Pump 1 (GROW) Closed");
FertilizerPump2BLOOMCurrentMillis = millis();
Fert2BLOOM();
}
}
void Fert2BLOOM()
{
if (FertilizerPump1State == LOW)
{
digitalWrite(RELAY4, HIGH); //change the state of the Fertilizer Pump 2 (BLOOM) to Open
Serial.println("Fertilizer Pump 2 (BLOOM) Open");
FertilizerPump2State = HIGH;
if (FertilizerPump2BLOOMCurrentMillis - FertilizerPump2BLOOMStartMillis >= FertilizerPump2BLOOMPeriod) //test whether the period has elapsed
{
digitalWrite(RELAY4, LOW); //if so, change the state of the Fertilizer Pump 2 (BLOOM) to Closed
FertilizerPump2State = LOW;
FertilizerPump2BLOOMStartMillis = FertilizerPump2BLOOMCurrentMillis; //IMPORTANT to save the start time of the current RELAY state.
Serial.println("Fertilizer Pump 2 (BLOOM) Closed");
FertilizerPump3BLOOMCurrentMillis = millis();
Fert3BLOOM();
}
}
}
void Fert3BLOOM()
{
if (FertilizerPump2State == LOW)
{
digitalWrite(RELAY5, HIGH); //change the state of the Fertilizer Pump 3 (MICRO) to Open
Serial.println("Fertilizer Pump 3 (MICRO) Open");
FertilizerPump3State = HIGH;
if (FertilizerPump3BLOOMCurrentMillis - FertilizerPump3BLOOMStartMillis >= FertilizerPump3BLOOMPeriod) //test whether the period has elapsed
{
digitalWrite(RELAY5, LOW); //if so, change the state of the Fertilizer Pump 3 (MICRO) to Closed
FertilizerPump3State = LOW;
FertilizerPump3BLOOMStartMillis = FertilizerPump3BLOOMCurrentMillis; //IMPORTANT to save the start time of the current RELAY state.
Serial.println("Fertilizer Pump 3 (MICRO) Closed");
}
}
}