This is the workable code. I have been testing it and the timer works. Like I said I want to know when those relays come on. So then I can set up some triggers to text me``#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <gfxfont.h>
#include “Adafruit_MCP23017.h”
#include <SPI.h>
#include <DHT.h>
#include <DHT_U.h>
#include <Wire.h>
#include “RTClib.h”
#include “DHT.h”
#define DHTPIN 2 // what digital pin we’re connected to
#define DHTTYPE DHT11 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
#define OLED_RESET 0
Adafruit_MCP23017 mcp;
Adafruit_SSD1306 display1(OLED_RESET);
Adafruit_SSD1306 display2(OLED_RESET);
#if (SSD1306_LCDHEIGHT != 64)
#error(“Height incorrect, please fix Adafruit_SSD1306.h!”);
#endif
/-----( Import needed libraries for RTC )-----/
/-----( Declare Constants and Pin Numbers )-----/
// Not needed: RTC Lib expects connections as above
/-----( Declare objects )-----/
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;
int OnHour2; //= {17,18,19,20};//Array multi hour
int OnDay2;
int OnMonth2;
//int //OnYear2 = {2018.2019};
int OffMin2;
int OffHour2;
int OffDay2;
int OffMonth2;
//int OffYear2 = {2018, 2019,};
int OnMin3;
int OnHour3; //= {17,18,19,20};//Array multi hour
int OnDay3;
int OnMonth3;
//int //OnYear3 = {2018.2019};
int OffMin3;
int OffHour3;
int OffDay3;
int OffMonth3;
//int OffYear3 = {2018, 2019,};
/-----( Declare Variables )-----/
// NONE because the library handles this…
void setup() /****** SETUP: RUNS ONCE ******/
{
mcp.begin(); 0x20; // use default address 0
Serial.begin(9600);
display1.begin(SSD1306_SWITCHCAPVCC, 0x3D);// initialize with the I2C addr 0x3C (for the 128x64)
display2.begin(SSD1306_SWITCHCAPVCC, 0x3C);
dht.begin();
display1.display();
display2.display();
delay(2000);
Wire.begin();
rtc.begin(); // Start the RTC library code
mcp.pinMode(0, OUTPUT);
mcp.pinMode(1, OUTPUT);
mcp.pinMode(2, OUTPUT);
mcp.pinMode(3, OUTPUT);
mcp.digitalWrite(0, HIGH);
mcp.digitalWrite(1, HIGH);
mcp.digitalWrite(2, HIGH);
mcp.digitalWrite(3, HIGH);
/----( SET the date and time. Comment OUT these lines after setting )----/
// Put these “//” in front of the line you do NOT want to use
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(DATE), F(TIME)));
// This line sets the RTC with an explicit date & time, for example to set
// May 21, 2015 at 6pm you would call: (use 24 hour time)
//rtc.adjust(DateTime(2018, 1, 2, 15, 17, 0));
}//–(end setup )—
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
DateTime now = rtc.now(); // Read data from the RTC Chip
display1.clearDisplay();
// text display tests
display1.setTextSize(2);
display1.setTextColor(WHITE);
display1.setCursor(0, 0);
display1.print(now.year(), DEC); //
display1.print(‘.’);
display1.print(now.month(), DEC);
display1.print(‘.’);
display1.print(now.day(), DEC);
//display1.print(‘*’);
display1.setTextSize(2);
display1.setTextColor(WHITE);
display1.setCursor(10, 16);
display1.print(now.hour(), DEC);
display1.print(‘:’);
display1.print(now.minute(), DEC);
display1.print(‘:’);
display1.print(now.second(), DEC);
display1.println();
display1.setTextSize(2);
display1.setTextColor(WHITE);
display1.setCursor(0, 32);
display1.println(“Z1- Z2- Z3”);
display1.display();
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
display2.clearDisplay();
// text display tests
display2.setTextSize(2);
display2.setTextColor(WHITE);
display2.setCursor(0, 0);
display2.print(“Humi “);
display2.print(h);
//display2.print(”%”);
display2.setTextSize(2);
display2.setTextColor(WHITE);
display2.setCursor(0, 16);
display2.print("Temp ");
display2.print(f);
display2.print(“F”);
display2.setTextSize(2);
display2.setTextColor(WHITE);
display2.setCursor(0, 32);
display2.print(“Heat Index”);
display2.setTextSize(2);
display2.setTextColor(WHITE);
display2.setCursor(36, 48);
display2.print(hif);
display2.println(“F”);
display2.display();
//Serial.print(“Humidity: “);
//Serial.print(h);
//Serial.print(” %\t”);
//Serial.print(“Temperature: “);
//Serial.print(t);
//Serial.print(” *C “);
//Serial.print(f);
//Serial.print(” *F\t”);
//Serial.print(“Heat index: “);
//Serial.print(hic);
//Serial.print(” *C “);
//Serial.print(hif);
//Serial.println(” *F”);
delay(500);
//Serial.print(now.year(), DEC); //
//Serial.print(‘-’);
//Serial.print(now.month(), DEC);
//Serial.print(‘-’);
//Serial.print(now.day(), DEC);
//Serial.print(’ ‘);
//Serial.print(now.hour(), DEC);
//Serial.print(’:‘);
//Serial.print(now.minute(), DEC);
//Serial.print(’:');
//Serial.print(now.second(), DEC);
//Serial.println();
int OnMin1 = {20, 21, 22, 23, 24};
int OnHour1 = {21}; //= {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 = {25};
int OffHour1 = {21};
int OffDay1 = {1, 2};
int OffMonth1 = {2};
//int OffYear1 // = {2018, 2019,};
delay(500);//Relay 0
for (int i = 0; i < sizeof(OnHour1) / sizeof(OnHour1[0]); i++)
for (int j = 0; j < sizeof(OnMin1) / sizeof(OnMin1[0]); j++)
for (int k = 0; k < sizeof(OnDay1) / sizeof(OnDay1[0]); k++)
for (int l = 0; l < sizeof(OnMonth1) / sizeof(OnMonth1[0]); 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(1);
display1.setTextColor(WHITE);
display1.setCursor(0, 48);
display1.println("ON");
display1.display();
Serial.print("RELAY 1 ON");
Serial.print(now.month(), DEC);
Serial.print('-');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}
else if ((now.hour() == OffHour1[i]) && (now.minute() == OffMin1[j]) && (now.day() == OffDay1[k]) && (now.month() == OffMonth1[l])) {
mcp.digitalWrite(0, HIGH);
display1.setTextSize(1);
display1.setTextColor(WHITE);
display1.setCursor(0, 48);
display1.println("OFF");
display1.display();
Serial.print("RELAY 1 OFF");
Serial.print(now.month(), DEC);
Serial.print('-');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}
int OnMin2 = {30, 31};
int OnHour2 = {21}; //= {2, 4, 8, 3, 6}; //= {17,18,19,20};//Array multi hour
int OnDay2 = {1, 2}; //OnHour1 = 3; //= {17,18,19,20};//Array multi hour
int OnMonth2 = {2};
//int OnYear2 // = {2018.2019};
int OffMin2 = {32};
int OffHour2 = {21};
int OffDay2 = {1, 2};
int OffMonth2 = {2};
//int OffYear2 // = {2018, 2019,};
// Relay 1
for (int i = 0; i < sizeof(OnHour2) / sizeof(OnHour2[0]); i++)
for (int j = 0; j < sizeof(OnMin2) / sizeof(OnMin2[0]); j++)
for (int k = 0; k < sizeof(OnDay2) / sizeof(OnDay2[0]); k++)
for (int l = 0; l < sizeof(OnMonth2) / sizeof(OnMonth2[0]); l++) //This will turn one relay on and off
if ((now.hour() == OnHour2[i]) && (now.minute() == OnMin2[j]) && (now.day() == OnDay2[k]) && (now.month() == OnMonth2[l])) {
mcp.digitalWrite(1, LOW);
display1.setTextSize(1);
display1.setTextColor(WHITE);
display1.setCursor(50, 48);
display1.println("ON");
display1.display();
Serial.print("RELAY 2 ON");
Serial.print(now.month(), DEC);
Serial.print('-');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}
else if ((now.hour() == OffHour2[i]) && (now.minute() == OffMin2[j]) && (now.day() == OffDay2[k]) && (now.month() == OffMonth2[l])) {
mcp.digitalWrite(1, HIGH);
display1.setTextSize(1);
display1.setTextColor(WHITE);
display1.setCursor(50, 48);
display1.println("OFF");
display1.display();
Serial.print("RELAY 2 OFF");
Serial.print(now.month(), DEC);
Serial.print('-');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}
int OnMin3 = {47, 48};
int OnHour3 = {21}; //= {2, 4, 8, 3, 6}; //= {17,18,19,20};//Array multi hour
int OnDay3 = {1, 2}; //OnHour1 = 3; //= {17,18,19,20};//Array multi hour
int OnMonth3 = {2};
//int OnYear3 // = {2018.2019};
int OffMin3 = {50};
int OffHour3 = {21};
int OffDay3 = {1, 2};
int OffMonth3 = {2};
//int OffYear3 // = {2018, 2019,};
for (int i = 0; i < sizeof(OnHour3) / sizeof(OnHour3[0]); i++)
for (int j = 0; j < sizeof(OnMin3) / sizeof(OnMin3[0]); j++)
for (int k = 0; k < sizeof(OnDay3) / sizeof(OnDay3[0]); k++)
for (int l = 0; l < sizeof(OnMonth3) / sizeof(OnMonth3[0]); l++) //This will turn one relay on and off
if ((now.hour() == OnHour3[i]) && (now.minute() == OnMin3[j]) && (now.day() == OnDay3[k]) && (now.month() == OnMonth3[l])) {
mcp.digitalWrite(2, LOW);
display1.setTextSize(1);
display1.setTextColor(WHITE);
display1.setCursor(50, 48);
display1.println("ON");
display1.display();
Serial.print("RELAY 3 ON");
Serial.print(now.month(), DEC);
Serial.print('-');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}
else if ((now.hour() == OffHour3[i]) && (now.minute() == OffMin3[j]) && (now.day() == OffDay3[k]) && (now.month() == OffMonth3[l])) {
mcp.digitalWrite(2, HIGH);
display1.setTextSize(1);
display1.setTextColor(WHITE);
display1.setCursor(100, 48);
display1.println("OFF");
display1.display();
Serial.print("RELAY 3 OFF");
Serial.print(now.month(), DEC);
Serial.print('-');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}
}
//–(end main loop )—
/-----( Declare User-written Functions )-----/
//NONE
//( THE END )**
`