Thumbnail image

Simplest Arduino Clock With 7-digit segment display

Sat, Nov 30, 2013 3-minute read

From time to time, I’m also working on less “web” related project. This time, a wanted to play a bit with Arduino platform. The task was pretty simple – to build a clock. Yes – these days, we don’t have enough time measuring devices like mobiles, microwaves, computers – I wanted to build another one.

It was my first Arduino project so the task wasn’t  as easy as I expected. In the theory, we need only pass time & data from RTC to 7-Segment Display. Simple isn’t it? I found plenty of tutorials, had so many small issues like – digits wasn’t displayed correctly (mixed cables). I could only display one digit at the time in given position or – same digits everywhere (multiplexing). I couldn’t find shift register in my stock, so wanted to use whatever I already had.

I already was a proud owner of the whole set, which was:

  1. Arduino UNO R3,
  2. DS1307 Real Time Clock,
  3. 7-Segment Display,
  4. bunch of resistors, cables, and plenty of free time
7-Segment DisplayDS1307 Real Time ClockReal-Time-Clock-Module

working magic


Let’s cook!


SevSeg setup

From file:

The first argument (boolean) tells whether the display is common cathode (0) or common anode (1).
The next four arguments (bytes) tell the library which arduino pins are connected to the digit pins of the seven segment display. Put them in order from left to right.
The next eight arguments (bytes) tell the library which arduino pins are connected to the segment pins of the seven segment display. Put them in order a to g then the dp.

That was the hardest part of my whole build. Setting up SevSeg to work with my wiring.

sevseg.Begin(0, 4, 3, 2, 1, 12, 11, 10, 9, 8, 7, 6, 5);

Mine was pretty simple. I had a version with common cathode – the first digit is 0, then – pins connecting t a cathode (digit handling) and then segments displays – in my case digital outputs in androino 6-12 (A to G) Number 5 points to dot digit.

#include "SevSeg.h"
#include <DS1307RTC.h>
#include <Time.h>
#include <Wire.h>
//Create an instance of the object.
SevSeg sevseg;
void setup() {
    //I am using a common anode display, with the digit pins connected
    sevseg.Begin(0, 4, 3, 2, 1, 12, 11, 10 , 9, 8, 7, 6,5);`

    //Set the desired brightness (0 to 100);  
void loop() {  
    tmElements_t tm;  
    int time;  
    int dot;  
    if (
        time = tm.Hour * 100;  
        time += tm.Minute;  
    if ((tm.Second % 2) == 0)  
        dot = 4;  
        dot = 2;  
    //Produce an output on the display  
    sevseg.NewNum(time, dot);