-2

The idea of this project is to open 3 valves one after the other for 5 minutes each, at a time like 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 5 minutes, 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.
The question is how do I Time the Arduino using the RTC that I can operate the valves at 7am, 12pm, and 4am?

#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)

      if(id==1)

     {


   for( int thisvalve=0; thisvalve <=valveCount; thisvalve++)

pinMode(valvePorts[thisvalve], OUTPUT);


   {   

  digitalWrite(Waterpump,LOW);

 delay(5000)  

  } // close for loop

     }// close if loop 

 } // close for loop 
gre_gor
  • 1,680
  • 4
  • 18
  • 28
shasha
  • 1

1 Answers1

0

Many ways of doing it.

  1. Poll the rtc constantly until the set time is reached. Then operate the valves. Or

  2. Set an alarm on the rtc for the next time to operate the valves. The rtc will interrupt the mcu when the time is up. The mcu can then operate the valves.

You don't have to use an rtc for this.

dannyf
  • 2,770
  • 10
  • 13