Introduction: 7 Segment Clock With Alarm & Temperature

Picture of 7 Segment Clock With Alarm & Temperature

Here is a simple 7 Segment clock which displays the time, the date and device temperature.

It uses a

DS3231 AT24C32 Memory Module For Arduino IIC Precision RTC

Arduino Uno

TM1637 4 digits display (with centre colon : )

Grounding pin 7 displays date & month

Grounding Pin 6 shows temperature

Step 1: Connecting the Hardware

For the Display

CLK = 9; //Set the CLK pin connection to the display
DIO = 8; //Set the DIO pin connection to the display



For the RTC

SDA Arduino pin A4

SCL Arduino pin A5

SQW Arduino pin 3 - Alarm interrupt


For display update interrupt

Arduino pin 13 to Arduino pin 2

Step 2: The Software

Picture of The Software

The sketch is attached and is pretty self explanatory.

In my previous rtc instructable, I set the SQW output to 1Hz and used the output to interrupt the Arduino to update the display.

The bit INTCON (reg 0Eh ) is set to 0 for a a constant 1Hz Square wave out.

I wanted to set an alarm which means this bit must be set to 1. It only triggers when the alarm condition is true, so I needed another way to update the display every second.

I could have used millis() in the loop, but I chose to use the Arduino internal timer interrupt (new ground for me !).

This link is brilliant, its what I used to set the interrupt.

Every second, pin 13 changes state, this fires interrupt 0 (pin 2) on the Arduino which updates the display.

I used Alarm 2 and set it to generate an interrupt every minute :-

See the datasheet (link below) to set the alarm for a specific time / date.

(The ISR just sets a flag & prints a message on the Arduino screen and does nothing practical though it could be used to trigger a relay or LED or buzzer etc. !)

//set alarm 2 every minute

// set_td(11,128);

// set_td(12,128);

// set_td(13,129);

I had to convert the bits to decimal as the rtc is programmed using BCD.

The set_td(x,y) function converts the data and writes it to the rtc registers.

This function is also called to set the date & time registers.

To write to the display, I had the help of this link

The colon ':' flashes every second by setting the high bit of the second display digit (see code).

Displaying the temperature comes from here :-

NOTE : if the temperature is 19 degrees, the Arduino Serial.println has a problem and displays it as -238, my guess is because 9 in BCD sets the MSB which for the temperature register which is stored as a two's compliment sets the 'sign' bit - just a guess ! HOWEVER, it is displayed on the 7 Segment correctly.