I have tried many ways to solve the issue, I am led to believe that the issue could be a memory leak, but i have tried to fix that with watchdogtimer reset, tried to reset the arduino as well but it doesn't work after the first reset.
I am still not sure what the problem could be, any information would be appreciated.
I have included my code that I have stitched together using other references from the web. And a link to the schematic of my circuit along with a picture of a tiny rtc module.
Schematic: http://i.stack.imgur.com/xrGPd.jpg
Tiny rtc : http://i.stack.imgur.com/kgoou.jpg
CODE IS AS BELOW. ANY ADVICE WOULD BE APPRECIATED.
' // CODE STARTS HERE
Code: Select all
#include "Wire.h"
#define DS1307_ADDRESS 0x68
#define RELAY_PIN 2
#define Feed_PIN 4
#define led13 13
void setup() {
Wire.begin();
Serial.begin(9600);
pinMode(RELAY_PIN, OUTPUT);
pinMode(Feed_PIN, OUTPUT);
pinMode(led13, OUTPUT);
}
void loop() {
printDate();
// digitalWrite(led13, HIGH);
//delay(500);
//delay(500);
//digitalWrite(led13, LOW);
// byte zero = 0x00;
///Wire.write(zero);
}
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);
byte zero = 0x00;
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 -> sun-sat
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
//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);
if ( (hour == 9 && (minute >= 00 && minute <= 20)) ||
(hour == 12 && (minute >= 20 && minute <= 40)) ||
(hour == 15 && (minute >= 40 && minute <= 59)) ||
(hour == 18 && (minute >= 00 && minute <= 20)) ||
(hour == 20 && (minute >= 20 && minute <= 40)) ||
(hour == 22 && (minute >= 40 && minute <= 59)) ||
(hour == 1 && (minute >= 00 && minute <= 20)) ||
(hour == 3 && (minute >= 20 && minute <= 40)) ||
(hour == 5 && (minute >= 40 && minute <= 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);
Serial.print(':');
Serial.print(':');
Serial.println(", pump off!");
digitalWrite(RELAY_PIN, HIGH);
}
else {
digitalWrite(RELAY_PIN, LOW);
}
if ((hour == 2 && minute == 43 && second >= 52) ||
(hour == 10 && minute == 00 && second >= 52) ||
(hour == 13 && minute == 00 && second >= 52) ||
(hour == 16 && minute == 00 && second >= 52))
{
digitalWrite(Feed_PIN, HIGH);
Serial.println("feeding fish.....");
}
} // CODE ENDS HERE
'