How to Time the arduino using RTC that i can operate the valves at 7am, 12pm and 4 am.?

How to Time the arduino using RTC that i can operate the valves at 7am, 12pm and 4 am.?
0.0 0

#1

/ 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 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.
// The question is how do i Time the arduino using the RTC that i can operate the valves at 7am, 12pm and 4 am. ???

#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


#2

Firstly, welcome to the forums.

While we are primarily here to help people with their Free Code Camp progress, we are open to people on other paths, too. Some of what you are asking is pretty trivial in the Free Code Camp context, so you might find that if you’re not getting the instruction and material you need in your current studies, the FCC curriculum will really help you get started. At a modest guess I’d say investing a 4-5 hours working through the curriculum here will really pay off. You can find the curriculum at https://freecodecamp.org.

With your current questions, we don’t have enough context to know what you already know or don’t know, so it is impossible to guide you without just telling you the answer (which we won’t do).

Happy coding :slight_smile: