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


/ 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


void loop()


t = rtc.getTime();


Serial.print(" hour(s), ");


Serial.print(" minute(s)");

Serial.println(" ");

delay (1000);

if(t.hour == OnHour && t.min == OnMin)




else if(t.hour == OffHour && t.min == OffMin)



void Startwatering(int id)


     if( id== 0)






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

pinMode(valvePorts[thisvalve], OUTPUT);




} // close for loop

 }// close if loop 

} // close for loop


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

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: