I have working Code but for some reason my one relay is not working up to par. Its tank2.
Its the only pin that doesnt turn on at its decided time. Could use a lil help.
//RTC
#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527
//LED
int mh = 12; // relay 1
int mhfan = 11; //relay 2
int cfl = 10; //relay 3
int led = 9; //relay 4
int tank2 = 8; // relay 5
int pump1Pin = 5; //relay 7
int pump2Pin = 6; //relay 8
int pump1State = HIGH;
int pump2State = LOW;
long previousMillis = 900000;
long interval = 900000;
void setup()
{
//RTC
Wire.begin();
Serial.begin(9600);
//setDateTime(); //MUST CONFIGURE IN FUNCTION
//LED
pinMode(mh,OUTPUT);
pinMode(cfl,OUTPUT);
pinMode(led,OUTPUT);
pinMode(mhfan, OUTPUT);
pinMode(tank2, OUTPUT); //THIS IS THE RELAY WITH ISSUES:sad2:
pinMode(pump1Pin,OUTPUT);
pinMode(pump2Pin,OUTPUT);
}
void loop()
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval)
{
previousMillis = currentMillis;
if (pump1State == HIGH)
pump1State = LOW;
else
pump1State = HIGH;
if (pump2State == LOW)
pump2State = HIGH;
else
pump2State = LOW;
digitalWrite(pump1Pin, pump1State);
digitalWrite(pump2Pin, pump2State);
}
printDate();
delay(1000);
}
/*void setDateTime()
{
byte second = 00; //0-59
byte minute = 59; //0-59
byte hour = 00; //0-23
byte weekDay = 3; //1-7
byte monthDay = 14; //1-31
byte month = 3; //1-12
byte year = 12; //0-99
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero); //stop Oscillator
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(weekDay));
Wire.write(decToBcd(monthDay));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(zero); //start
Wire.endTransmission();
}
*/
byte decToBcd(byte val)
{
// Convert normal decimal numbers to binary coded decimal
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val)
{
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
void printDate()
{
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
//int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
//TIME
int time = (hour * 60) + minute;
int time1 = (hour * 60) + minute;
int time2 = (hour * 60) + minute;
int time3 = (hour * 60) + minute;
int time4 = (hour * 60) + minute; //ASSOCIATED ISSUE
//LED's On
if((time >= 0 && time <= 389)||(time >= 1049 && time <= 1440))
{ digitalWrite(led, HIGH); }
else
{ digitalWrite(led,LOW); }
// Actinic on
if((time1 >= 359 && time1 <= 540)||(time1 >= 899 && time1 <= 1140))
{ digitalWrite(cfl, HIGH); }
else
{ digitalWrite(cfl,LOW); }
//Metal Halide Fan On
if(time2 >= 494 && time2 <= 944)
{ digitalWrite(mhfan, HIGH); }
else
{ digitalWrite(mhfan,LOW); }
//Metal Halide On
if(time3 >= 509 && time3 <= 930)
{ digitalWrite(mh, HIGH); }
else
{ digitalWrite(mh,LOW); }
//Tank 2 On ASSOCIATED ISSUE
if((time4 >= 0 && time4 <= 359)||(time4 >= 1079 && time4 <= 1140))
{ digitalWrite(tank2, HIGH); }
else
{ digitalWrite(tank2,LOW); }
//print the date EG 3/1/11 23:59:59
Serial.print(month);
Serial.print("/");
Serial.print(monthDay);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.println(second);
}