Open-source Arduino Clock

This project is open-source code for an Arduino-based clock released under the GPL Creative Commons license. It’s a work-in-progress, and contributions are definitely welcome.

Nick Hardeman at Parsons used it to make his Morning Monster alarm clock.

An open-source clock for Arduino. This project will be enhanced on a regular basis
(cc) by Rob Faludi
#define vers = "1.01"

#define ledPin 13
#define secondPin 4
#define minutePin 5
#define hourPin 6
#define weekdayPin 7

int second=0, minute=0, hour=0, weekday=1; // declare time variables
// these time variables are declared globally so they can be used ANYWHERE in your program

void setup() {

blinkLED(ledPin, 4, 100); // blink an LED at the start of the program, to show the code is running
Serial.begin(9600); // start up serial communications
pinMode(secondPin, INPUT); //pins for normally closed switches to set the time
pinMode(minutePin, INPUT);
pinMode(hourPin, INPUT);
pinMode(weekdayPin, INPUT);
digitalWrite(secondPin, HIGH); // writing an input high turns on pull-up resistors
digitalWrite(minutePin, HIGH);
digitalWrite(hourPin, HIGH);
digitalWrite(weekdayPin, HIGH);

void loop() {

static unsigned long lastTick = 0; // set up a local variable to hold the last time we moved forward one second
// (static variables are initialized once and keep their values between function calls)

// move forward one second every 1000 milliseconds
if (millis() - lastTick >= 1000) {
lastTick = millis();

// move forward one minute every 60 seconds
if (second > 59) {
second = 0; // reset seconds to zero

// move forward one hour every 60 minutes
if (minute > 59) {
minute = 0; // reset minutes to zero

// move forward one weekday every 24 hours
if (hour > 23) {
hour = 0; // reset hours to zero

// reset weekdays on Saturday
if (weekday > 7) {
weekday = 1;

checkButtons(); // runs a function that checks the setting buttons

void checkButtons() {
static boolean secPressed=false, minPressed=false, hourPressed=false, wkdayPressed=false; //track button state

if (digitalRead (secondPin)==LOW && secPressed == false) { // if a normally closed switch is pressed
second++; // advance by one second
secPressed = true; // note the pressed state
if (digitalRead (secondPin)==HIGH) secPressed = false; // reset the state when the button is released

if (digitalRead (minutePin)==LOW && minPressed == false) {
minPressed = true;
if (digitalRead (minutePin)==HIGH) minPressed = false;

if (digitalRead (hourPin)==LOW && hourPressed == false) {
hourPressed = true;
if (digitalRead (hourPin)==HIGH) hourPressed = false;

if (digitalRead (weekdayPin)==LOW && wkdayPressed == false) {
secPressed = true;
if (digitalRead (weekdayPin)==HIGH) wkdayPressed = false;

void printWeekday (int dayNum) {
// print a weekday, based on the day number
switch (dayNum) {
case 1:
Serial.print ("Sunday");
case 2:
Serial.print ("Monday");
case 3:
Serial.print ("Tuesday");
case 4:
Serial.print ("Wednesday");
case 5:
Serial.print ("Thursday");
case 6:
Serial.print ("Friday");
case 7:
Serial.print ("Saturday");

void serialOutput() {
// this function creates a clock you can read through the serial port
// your clock project will have a MUCH more interesting way of displaying the time
// get creative!
printWeekday(weekday); // picks the right word to print for the weekday
Serial.print(", "); // a comma after the weekday
Serial.print(hour, DEC); // the hour, sent to the screen in decimal format
Serial.print(":"); // a colon between the hour and the minute
Serial.print(minute, DEC); // the minute, sent to the screen in decimal format
Serial.print(":"); // a colon between the minute and the second
Serial.println(second, DEC); // the second, sent to the screen in decimal format

// this utility function blinks the an LED light as many times as requested
void blinkLED(byte targetPin, int numBlinks, int blinkRate) {
for (int i=0; i < numBlinks; i++) {
digitalWrite(targetPin, HIGH); // sets the LED on
delay(blinkRate); // waits for a blinkRate milliseconds
digitalWrite(targetPin, LOW); // sets the LED off



23 thoughts on “Open-source Arduino Clock”

  1. Pingback: My Arduino Notebook » Blog Archive »

  2. Pingback: DIY: Binary Clock with Arduino at

  3. Pingback: links for 2008-07-18 « Donghai Ma

  4. Pingback: vkick Blog Site » Blog Archive » Clock without additional chip?

  5. Pingback: Ma cosa c’è di veramente nuovo nelle nuove tecnologie? (assignment fuori categoria) « Insegnare Apprendere Mutare

  6. Pingback: Arduino + LCD: Zegarek z budzikiem, budzik z zegarkiem | fri2go [at]

  7. Pingback: seatomato daily » Blog Archive » [Night Sundial] Research - Reading Time: Open Source Arduino Clock Project

  8. Hi,
    I am new in programming but interested in your project.Pls after compiling or verifying there is error ‘It’ is not declare in the scope ( for (int i=0; i&It;numBlinks; i++) {) {in the last but of the sketch.Can u kindly help me ?

  9. I’d like to make a suggestion. Instead of using a big switch, i would add this line below the hour/minute/weekday declarations:

    String weekdays[] = {“Sunday”, “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”};

    and replace printWeekday(weekday); with Seria.print(weekdays[weekday-1]);

    In the project i used, i even modified the weekday starting value, so that Sunday is 0, not 1, to simplify the code even more

  10. it keeps giving em the error “expected primary-expression befor “;” token” in this line at the bottom of the code.

    for (int i=0;i<;numBlinks; i++) {

    What's wrong?

  11. Hi,
    I’m working on a distributed control algorithm for quadrotors. Just by skimming through your code I see that the fastest you are writing to the serial port (i.e. to the Xbee) is every 1 second. And that is one packet. From their spec sheet Xbee’s (S2) can handle 250kbs. But that is per frame. The question I’m interested is how many packets can you write per second. If I have 200 bit frames can I write that say (approx) 1000 times a second to the Xbee? Can Xbee supprot 1000HZ on the serial port? If not, in your experience have you come across something that can handle this sampling rate?

    Remus C Avram

  12. A nice improvement is to add a battery backup at the Arduino’s power in fitting, so as to make it fully blackout-proof. Even better, you get to choose the size of the batteries.

    Most alarm clocks with battery backup have a serious design flaw. It remembers the time, but if the blackout is right at the time the alarm is supposed to go off, it won’t. Almost as bad, clock radios with this feature default to a buzzer that is pathetically too weak.

  13. Pingback: Firefly – week 1 – UWE Product Design Physical Computing

  14. hi sir ,

    i want your help , how to know my current time of the programming code, for example 6 pm clock to 12 am , in between time i need.i am waiting for yours answers.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top