Relay and Time

I want to turn 3 relays on at different times during the day. I am able to turn them on at one time but not multiply times during the day I tried to used arrays before the setup and this would only turn the relay on for the first number in the array.

RTC_DS1307 rtc;    // Create a RealTimeClock object
int OnMin1;
int OnHour1;
int OnDay1;
int OnMonth1;
//int OnYear1     //[] = {2018.2019};

int OffMin1;
int OffHour1;
int OffDay1;
int OffMonth1;
//int OffYear1     //[] = {2018, 2019,};

int OnMin2  [] = {18, 20};
int OnHour2 [] = {21}; //= {2, 4, 8, 3, 6};       //[]= {17,18,19,20};//Array multi hour
int OnDay2  [] = {29};
int OnMonth2  [] = {1};
//int //OnYear2  [] = {2018.2019};

int OffMin2  [] = {19, 21};
int OffHour2  [] = {21};
int OffDay2   [] = {29};
int OffMonth2  [] = {1};
//int OffYear2   [] = {2018, 2019,};

int OnMin3 [] = {20, 23};
int OnHour3 [] = {21}; //= {2, 4, 8, 3, 6};       //[]= {17,18,19,20};//Array multi hour
int OnDay3 [] = {29};
int OnMonth3  [] = {1};
//int //OnYear3 [] = {2018.2019};

int OffMin3 [] = {21, 24};
int OffHour3  [] = {21};
int OffDay3  [] = {29};
int OffMonth3  [] = {1};
//int OffYear3  [] = {2018, 2019,};

I put the arrays in the loop and it would turn the relays on for multiply minutes but would not turn on a different time of the day. Where have I gone wrong?? LOL

int OnMin1 [] = {5, 6, 8, 9};
int OnHour1 [] = {9}; //= {2, 4, 8, 3, 6};       //[]= {17,18,19,20};//Array multi hour
int OnDay1  [] = {01};  //OnHour1 = 3;  //[]= {17,18,19,20};//Array multi hour
int OnMonth1 [] = {2};
//int OnYear1     //[] = {2018.2019};

int OffMin1  [] = {7, 10};
int OffHour1 [] = {9};
int OffDay1  [] = {01};
int OffMonth1[] = {2};
//int OffYear1     //[] = {2018, 2019,};


  delay(500);//Relay 0
  for (int i = 0; i < sizeof(OnHour1) / sizeof(OnHour1[i]); i++)
    for (int i = 0; i < sizeof(OnMin1) / sizeof(OnMin1[i]); i++)
      for (int i = 0; i < sizeof(OnDay1) / sizeof(OnDay1[i]); i++)
        for (int i = 0; i < sizeof(OnMonth1) / sizeof(OnMonth1[i]); i++)      //This will turn one relay on and off

          if ((now.hour() == OnHour1[i]) && (now.minute() == OnMin1[i]) && (now.day() == OnDay1[i]) && (now.month() == OnMonth1[i])) {
            mcp.digitalWrite(0, LOW);
            display1.setTextSize(2);
            display1.setTextColor(WHITE);
            display1.setCursor(0, 48);
            display1.println("ON");
            display1.display();
            Serial.print("RELAY 1 ON");
          }
        
          else if ((now.hour() == OffHour1[i]) && (now.minute() == OffMin1[i]) && (now.day() == OffDay1[i]) && (now.month() == OffMonth1[i])) {
            mcp.digitalWrite(0, HIGH);
            display1.setTextSize(2);
            display1.setTextColor(WHITE);
            display1.setCursor(0, 48);
            display1.println("OFF");
            display1.display();
            Serial.print("RELAY 1 OFF");
          }

Your nested for loops each need a different variable. By making them all i, you're defeating the checks you're doing to check hours & day etc.

a handy library to do this more easily.

for (int i = 0; i < sizeof(OnHour1); i++)
    for (int j = 0; j < sizeof(OnMin1); j++)
      for (int k = 0; k < sizeof(OnDay1); k++)
        for (int l = 0; l < sizeof(OnMonth1); l++)      //This will turn one relay on and off

          if ((now.hour() == OnHour1[i]) && (now.minute() == OnMin1[j]) && (now.day() == OnDay1[k]) && (now.month() == OnMonth1[l])) {
            mcp.digitalWrite(0, LOW);
            display1.setTextSize(2);
            display1.setTextColor(WHITE);
            display1.setCursor(0, 48);
            display1.println("ON");
            display1.display();
            Serial.print("RELAY 1 ON");
          }
        
          else if ((now.hour() == OffHour1[i]) && (now.minute() == OffMin1[j]) && (now.day() == OffDay1[k]) && (now.month() == OffMonth1[l])) {
            mcp.digitalWrite(0, HIGH);
            display1.setTextSize(2);
            display1.setTextColor(WHITE);
            display1.setCursor(0, 48);
            display1.println("OFF");
            display1.display();
            Serial.print("RELAY 1 OFF");
          }

sprinkfitter:

for (int i = 0; i < sizeof(OnHour1); i++)

for (int j = 0; j < sizeof(OnMin1); j++)
     for (int k = 0; k < sizeof(OnDay1); k++)
       for (int l = 0; l < sizeof(OnMonth1); l++)      //This will turn one relay on and off

if ((now.hour() == OnHour1[i]) && (now.minute() == OnMin1[j]) && (now.day() == OnDay1[k]) && (now.month() == OnMonth1[l])) {
           mcp.digitalWrite(0, LOW);
           display1.setTextSize(2);
           display1.setTextColor(WHITE);
           display1.setCursor(0, 48);
           display1.println(“ON”);
           display1.display();
           Serial.print(“RELAY 1 ON”);
         }
       
         else if ((now.hour() == OffHour1[i]) && (now.minute() == OffMin1[j]) && (now.day() == OffDay1[k]) && (now.month() == OffMonth1[l])) {
           mcp.digitalWrite(0, HIGH);
           display1.setTextSize(2);
           display1.setTextColor(WHITE);
           display1.setCursor(0, 48);
           display1.println(“OFF”);
           display1.display();
           Serial.print(“RELAY 1 OFF”);
         }

What I do here… reboots and reboots relay is always on

Earlier you had:

sizeof(OnMonth1) / sizeof(OnMonth1[i]

which should really have been

sizeof(OnMonth1) / sizeof(OnMonth1[0]

Now it's gone entirely, so you are trying to read memory outside your array bounds. I'm not sure that that would cause a crash, but it's not a good thing.

Thanks All that works!!!