NerdKits - electronics education for a digital generation

Crystal Real Time Clock

Buy a NerdKits microcontroller kit and start learning real electronics.  Learn more.

Our USB NerdKits already include a 14.7456MHz crystal that is used to clock each instruction that the microcontroller executes. But we can also use this same crystal to keep track of "wall time" -- measured in seconds, minutes, hours, days, and more.

This project demonstrates a minimal piece of code that shows how to use interrupts, as well as the ATmega168's onboard Timer/Counter modules, to divide the 14745600 clock cycles per second down to just 100, and to keep time accurately in seconds.

This sample code just counts in seconds, and the result looks like this:

Crystal Real Time Clock

We expect that you'll do something more interesting with this, taking this example code and building on it to make accurate timers, alarm clocks, and other projects of that nature. Send us photos!

Parts List

No parts are needed beyond our USB NerdKit.

Source Code

You can download the source code here. Start with a standard NerdKits project and Makefile (included with the kit) and plug in this source code.

More Videos and Projects!

Take a look at more videos and microcontroller projects!


Did you know that LEDs (light emitting diodes) only conduct current in one direction, like normal diodes? Learn more...