ok i'm having issues where all of my relays go hi for a split second right after halide 3 turns on and right before Blue 3 shuts off cant seem to figure it out hopefully one of you guys can help me with this issue.
// Date and time functions using RX8025 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "Sodaq_DS3231.h"
char weekDay[][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
const int Relay1 = 22;
const int Relay2 = 23;
const int Relay3 = 24;
const int Relay4 = 25;
const int Relay5 = 26;
const int Relay6 = 27;
const int Relay7 = 28;
const int Relay8 = 29;
const int actinicSwitch = 8;
const int halideSwitch = 9;
void setup ()
{
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
pinMode(Relay3, OUTPUT);
pinMode(Relay4, OUTPUT);
pinMode(Relay5, OUTPUT);
pinMode(Relay6, OUTPUT);
pinMode(Relay7, OUTPUT);
pinMode(Relay8, OUTPUT);
pinMode(actinicSwitch, INPUT);
pinMode(halideSwitch, INPUT);
digitalWrite(Relay8, HIGH); // unused relay at current time high to turn off led notifier
Serial.begin(9600);
Wire.begin();
rtc.begin();
}
uint32_t old_ts;
void loop ()
{
DateTime now = rtc.now(); //get the current date-time
uint32_t ts = now.getEpoch();
if (old_ts == 0 || old_ts != ts) {
old_ts = ts;
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.date(), DEC);
Serial.print('/');
Serial.print(now.year(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.print(' ');
Serial.print(weekDay[now.dayOfWeek()]);
Serial.println();
unsigned int currentTime = now.hour() * 100 + now.minute() ; // time in 24hr format fits an int as max is 2359
int actinicState = 0;// Switch state for actinic Override Switch
actinicState = digitalRead(actinicSwitch);
int halideState = 0;// Switch state for halide Override Switch
halideState = digitalRead(halideSwitch);
//---------------------------------------------ACTINIC LIGHT CONTROL---------------------------------------------
//Turns Blue T5 #1 on and off
if (currentTime >= 1200 && currentTime <= 1359) {
digitalWrite(Relay1, LOW); // Blue #1 on between 12pm and 2pm
}
else if (currentTime >= 1730 && currentTime <= 1929) {
digitalWrite(Relay1, LOW); // Blue #1 on between 530 and 730pm
}
else if (actinicState == HIGH) {
digitalWrite(Relay1, LOW); // Turns Blue #1 with Switch Override
}
else {
digitalWrite(Relay1, HIGH); // Blue #1 off rest of time
}
// Turns Blue T5 #2 on and off
if (currentTime >= 1230 && currentTime <= 1429) {
digitalWrite(Relay2, LOW); // Blue #2 on between 12:30pm and 2:30pm
}
else if (currentTime >= 1800 && currentTime <= 1959) {
digitalWrite(Relay2, LOW); //Blue #2 on between 600 and 800pm
}
else if (actinicState == HIGH) {
digitalWrite(Relay2, LOW); // Turns Blue #2 on with Switch Override
}
else {
digitalWrite(Relay2, HIGH); // Blue #2 off rest of time
}
//turns Blue T5 #3 on and off
if (currentTime >= 1300 && currentTime <= 1459) {
digitalWrite(Relay3, LOW); // Blue #3 on between 1pm and 3pm
}
else if (currentTime >= 1830 && currentTime <= 2029) {
digitalWrite(Relay3, LOW);//Blue #3 on between 6:30 and 8:30pm
}
else if (actinicState == HIGH) {
digitalWrite(Relay3, LOW); // Turns Blue #3 on with Switch Override
}
else {
digitalWrite(Relay3, HIGH); // Blue #3 off rest of time
}
//---------------------------------------------HALIDE LIGHT CONTROL-----------------------------------------------
// ON TIMES INCLUDE OVERLAP FOR LIGHT WARMUP
// Turns Halide#1 on and off
if (currentTime >= 1359 && currentTime <= 1729) {
digitalWrite(Relay4, LOW); // on after 2pm off at 5:30pm
}
else if (halideState == HIGH) {
digitalWrite(Relay4, LOW); // Turns Halide #1 on with Switch Override
}
else {
digitalWrite(Relay4, HIGH); // turns Halide #1 off rest of time
}
// Turns Halide#2 on and off
if (currentTime >= 1429 && currentTime <= 1759) {
digitalWrite(Relay5, LOW); // on after 2:30pm off at 6pm
}
else if (halideState == HIGH) {
digitalWrite(Relay5, LOW); // Turns Halide #2 on with Switch Override
}
else {
digitalWrite(Relay5, HIGH); // turns Halide #2 off rest of time
}
// Turns Halide#3 on and off
if (currentTime >= 1459 && currentTime <= 1829) {
digitalWrite(Relay6, LOW); // on after 3pm off at 6:30pm
}
else if (halideState == HIGH) {
digitalWrite(Relay6, LOW); // Turns Halide #3 on with Switch Override
}
else {
digitalWrite(Relay6, HIGH); // turns Halide #3 off rest of time
}
//-----------------------------------------------LED LIGHT CONTROL-----------------------------------------------
// Turns leds on and off
if (currentTime >= 1200 && currentTime <= 2029) {
digitalWrite(Relay7, HIGH); // turns leds off between 12pm and 8:30pm
}