Does the Atmega328p (used on the Arduino Uno) have a built in real-time clock? If so, is there any example on using this (i.e. setting the time, using daylight savings time, etc...)?
I have a project where I need to set the current time and trigger an action (digital output pin) if the time set is reached. My concern is if power is lost to the processor for a while and the time is lost. Are there any examples or schematics on using the Atmega328p to keep the time in event of power loss?
Actually, it does. The datasheet features list includes "Real Time Counter with Separate Oscillator". However, there are some limitations and compromises. The crystal pins are shared, so if the RTC is used, then the system clock must be the internal RC oscillator. This would prevent accurate timing for serial I/O. Also, the time-keeping code needs to be written, but this is nearly trivial, only a dozen lines or so, although an interrupt handler is probably required. Some pains in both hardware and software would have to be taken to achieve extended battery-backup capability.
So quite often an external RTC is not only easier to use, but is a better solution as well. My first thought is that is the way the OP should go.
I did an experimental project using the internal RTC, however there is no backup power, so if the main supply is lost, the time needs to be reset. Adafruit Industries' Ice Tube Clock I believe uses the internal RTC, and achieves some level of battery backup, but not nearly as long as some of the standalone RTCs which can run for years.
Thank you very much. I believe I'll use an external RTC like the DS1307 or DS3231. I think I can use the Time library for the Arduino and have a battery backup. Furthermore, the Time library actually allows to obtain the time via the internet, so if I'm using the Ethernet shield, I may be able to grab the time that way too. I'm always open for other suggestions or ideas (especially any example projects/code that might utilize these things I've mentioned). Thanks again.
DataCrypt:
Thank you very much. I believe I'll use an external RTC like the DS1307 or DS3231. I think I can use the Time library for the Arduino and have a battery backup. Furthermore, the Time library actually allows to obtain the time via the internet, so if I'm using the Ethernet shield, I may be able to grab the time that way too. I'm always open for other suggestions or ideas (especially any example projects/code that might utilize these things I've mentioned). Thanks again.
Sure thing! I've used both of those RTCs and they work well with the Time library. I also do the NTP synchronization. I've just posted a library that will do automatic time zone and daylight saving time adjustments. Combine that with NTP, and you have a clock that's always accurate and never needs adjusting! See: http://arduino.cc/forum/index.php/topic,96891.0.html