I have a very simple RTC circuit based on ds1307 attached to ATMEGA328 .
I have bootloaded this chip with external crystal and have let it run by itself on a circuit.
I have a relay that switched on during day time and switched off at night..
All seems to work well for like 1-2 days then somehow the whole thing stops working until i power cycle it.
I have powered arduino using a voltage regulated 12V wallwart and i have a voltage regulator IC as well to bring the 12v down to 5 on the circuit and use the same wallwart to energize the relay.
I am sure the 12V regulator has its own IC/Caps, etc
And the power comes to this setup from my Inverter and during the grid failure which happen a lot of time lol.. there is always a very slight power blink or something. Caps should take care of it as it is very very short.
My computers do not stop running during this break .
So its either the RTC that stops giving data to the atmega OR the whole mega crashes and requires a reboot.
RTC time is correct because when i reset the arduino once in a while, it just works
Also I feel like an Atmega is an overkill for a silly task, I m going to soon use an attiny84 for this but didnt find any readymade RTC code that works with 84 yet.
Is arduino dependable to run for like months without any action from the user? because if i plan to use this system to be able to run some important stuff like street lamps, and want to know if this is good enough to run for years without power cycles,etc or there are any special things to note before doing a system that is
Sorry if i sound silly, I m not an expert in electronics more like a noob, Im a software person and do this all at night for fun.
I know the word arduino like exactly some 50 days ago and have no other background .
Here is the code, I don't know if there is a problem with code here.
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int relayPin = 8; // select the pin for the LED
void loop() {
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
printtime();
if(!isday())
{
Serial.write("Its night time");
digitalWrite(relayPin, LOW);
}
else
{
Serial.write("Day time");
digitalWrite(relayPin, HIGH);
}
delay(1000);
}
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
boolean isday()
{
if((hour>4) && (hour<17))
{
return true;
}
return false;
}
void printtime()
{
Serial.print(hour, DEC);
Serial.print(":");
Serial.print(minute, DEC);
Serial.print(":");
Serial.print(second, DEC);
Serial.print(" ");
Serial.print(month, DEC);
Serial.print("/");
Serial.print(dayOfMonth, DEC);
Serial.print("/");
Serial.print(year, DEC);
Serial.print(" Day_of_week:");
Serial.println(dayOfWeek, DEC);
}