Although basic this clock keeps excellent time as tested against the one on my computer and allows you to set the time using two buttons. Because we are using four half-inch 7 segment LED displays, it will not be battery friendly, and I suggest powering it from the USB port to start with. To test, I attached a 9V PSU that plugs into the mains. I said in the previous project that this one would be somewhat more complex, and here's the circuit:




























This looks scary but it isn't. You are going to need a bigger breadboard than that supplied in the ARDX kit though. The shift registers are all 74HC595 and as you can see there are three of them, and the 7 segment displays are all common cathode types. Connect pins 16 & 10 together, and 16 to 5V, and connect 8 & 13 then 8 to GND.


Here's the code:



int uparray []= {126,12,182,158,204,218,250,14,254,222};

int hour=0;

int minu=0;

int tenmin=0;

long timesec = 60000;

long timethen= 0;

void setup () {

  for (int t=2;t<13;t++){

    pinMode (t,OUTPUT);

     digitalWrite(4, LOW);

    shiftOut(2,3, MSBFIRST,126);  

    digitalWrite(4, HIGH);

    digitalWrite(7, LOW);

    shiftOut(5,6, MSBFIRST,126);  

    digitalWrite(7, HIGH);

    digitalWrite(8, LOW);

    shiftOut(9,10, MSBFIRST,126);  

    digitalWrite(8, HIGH);




void loop (){

    if (digitalRead (A0)==HIGH){


      delay (300);

      digitalWrite(10, LOW);

    shiftOut(8,9, MSBFIRST,uparray[minu]);  

    digitalWrite(10, HIGH);}


        if (digitalRead (A1)==HIGH){



    mindisp ();




void hourdisp (){


    if (hour>2 && digitalRead (12)==HIGH){

   digitalWrite (11,LOW);digitalWrite (12,LOW);


 if(hour==0 && digitalRead (12)==LOW){

   digitalWrite (11,HIGH);digitalWrite (12,HIGH);}

   digitalWrite(4, LOW);

    shiftOut(2,3, MSBFIRST,uparray[hour]);  

    digitalWrite(4, HIGH);




void tenmindisp(){

   tenmin = tenmin+1;

if (tenmin>5){tenmin=0;hourdisp();}

  digitalWrite(7, LOW);

    shiftOut(5,6, MSBFIRST,uparray[tenmin]);  

    digitalWrite(7, HIGH);




void mindisp(){



  digitalWrite(10, LOW);

    shiftOut(8,9, MSBFIRST,uparray[minu]);  

    digitalWrite(10, HIGH);

    if (millis ()-timethen>timesec){

    minu = minu +1;


    if (minu>9){minu=0; tenmindisp ();}





If all is well then the display will display 000, and this means it's ready to set. Whichever button you've attched to A0 will move the minutes forward.Incidentally, if you scroll through 60 mins, it'll drag the hour forward too. See if you can modify the code to stop it doing this, and here's a hint: consider using a checkflag and an if....else statement.

Whichever button you've attached to A1 will move the hour forward, and leave the minutes alone.

And that's all it does. If you run it for a few hours, you'll find it keeps remarkably accurate time (test it against your computer clock). You're going to need a lot of jump wires to breadboard it out: very nearly all the ones that came in your ARDX kit if you have one. This many wires means that somewhere along the line you're going to misplace one in all probability. If you need to move wires, remove the power source first. The chips are not easy to damage, but scraping something live across them may do it.


Over the page we look at the code as usual.


A Basic Digital Clock , 7 Segment Display

More> Go Back



Input Pin

Set up your pushbuttons like this for a default low.