// The idea of this project is to open 3 valves one after the other for 5 minutes each, at a time like 7am, 12pm, 4pm in a day.
// The for loop should be executed at 7am, where valve 1 is open and water is pumped for 5minutes, then valve 1 closes and valve 2 runs for 5 minutes, then valve 3 opens and runs for 5 minutes.
// the program comes to a stop. now at 12pm, the same cycle or process repeats for the 3 valves.
// Any expert help ??
#include <SoftwareSerial.h>
#include <DS3231.h>
// intialise Valves for Each Vegetation Bed
int valvePorts[] = { 4,5,6};
int valveCount= 3;
DS3231 rtc(SDA, SCL);
Time t;
const int OnHourOne = 12; // assuming that one Tank- valve takes 5minutes each
const int OnMinOne = 00;
const int OffHourOne = 12;
const int OffMinOne = 30;
const int OnHourTwo = 16;
const int OnMinTwo = 00;
const int OffHourTwo = 16;
const int OffMinTwo = 30;
void setup()
{
for( int thisvalve=0; thisvalve =<valveCount; thisvalve++) {
pinMode(valvePorts[thisvalve], OUTPUT);
}
pinMode(Waterpump,OUTPUT); // Waterpump
Serial.begin(9600);
}
void loop()
{
t = rtc.getTime();
Serial.print(t.hour);
Serial.print(" hour(s), ");
Serial.print(t.min);
Serial.print(" minute(s)");
Serial.println(" ");
delay (1000);
if(t.hour == OnHour && t.min == OnMin){
Startwatering(1);
}
else if(t.hour == OffHour && t.min == OffMin){
Startwatering(0);
}
void Startwatering(int id) {
if( id== 0)
{
return;
}
while(valvePorts[thisvalve],HIGH)
{
for( int thisvalve=0; thisvalve =<valveCount; thisvalve++)
pinMode(valvePorts[thisvalve], OUTPUT);
{
digitalWrite(Waterpump,LOW);
delay(5000)
}
}// close while loop
} // close for loop