Important note: when running this code, you should probably use an external power supply (say 9VDC into the Arduino). When I ran the code on USB power, the NeoPixels drew too much current and this caused the RTC to provide strange numbers to the Arduino.

Download the code and uncompress in your Arduino sketch folder.

This Arduino sketch relies on a few Arduino libraries:

Follow the DS1307 RTC breakout tutorial to learn how to install the RTC library and set the time on the DS1307 RTC.

You will also need to install the NeoPixel library.

The DST_RTC library is used to keep the time accurate for Daylight Saving Time. 

See the following tutorial to learn how to install Arduino libraries.

Understanding the Code



The clock operates with two different brightness levels, so that it can switch to a dimmer level at nighttime. The two brightness levels are DAYBRIGHTNESS and NIGHTBRIGHTNESS. These values can be 0-255 although with 0 you won't be able to see anything.

The daytime / nighttime cutoffs are set with the MORNINGCUTOFF and NIGHTCUTOFF values, which define which hours the brightness transitions take place.

// nighttime dimming constants
// brightness based on time of day- could try warmer colors at night?

// cutoff times for day / night brightness. feel free to modify.
#define MORNINGCUTOFF 7  // when does daybrightness begin?   7am
#define NIGHTCUTOFF 22 // when does nightbrightness begin? 10pm

Start Pixel

You can define STARTPIXEL to define where the "midnight" point on the clock is. This can useful, for example, if you have the clock in an enclosure and you're unable to physically rotate the NeoPixel Ring.

#define STARTPIXEL 0 // where do we start on the loop? use this to shift the arcs if the wiring does not start at the "12" point

A value of 0 would mean the colored arcs would begin and end where the DIN wire connects from the microcontroller to the NeoPixel Ring. You can change the value from 0-59 to change where the arcs begin.

This guide was first published on Jul 01, 2014. It was last updated on Mar 08, 2024.

This page (Code) was last updated on Mar 08, 2024.

Text editor powered by tinymce.