Arduino clock using RTC module and 7 Segment display

Introduction

In this arduino clock project we are displaying time on 7 segment tube display. Unlike other posts where I had used lcd display. Tube display board uses TM1637 chip. 

Parts required

For this project we need 3 important parts viz: Arduino , any RTC clock module(I have used DS1302), 7 segment 4 digit tube display.

Circuit/Schematic 

 

clock SchematicBread board diagram

Board connections are simple and self explanatory. Refer the schematic diagram above for details.

Program

Download the required arduino libraries and to the libraries.

// Example sketch for interfacing with the DS1302 timekeeping chip.
#include <Wire.h>
#include <stdio.h>
#include <DS1302.h>
#include <TM1637Display.h>

namespace {
// Set the appropriate digital I/O pin connections. These are the pin
// assignments for the Arduino as well for as the DS1302 chip.
//
const int CePin = 5; // Chip Enable
const int IoPin = 6; // Input/Output
const int SclkPin = 7; // Serial Clock

const int clk=2;
const int dio=3;

// Create a DS1302 object.
DS1302 rtc(CePin, IoPin, SclkPin);
TM1637Display display(clk,dio);
int printTime() {
// Get the current time and date from the chip.
Time t = rtc.time();
// Format the time and date and insert into the temporary buffer.
char buf[50];
snprintf(buf, sizeof(buf), "%02d:%02d",t.hr, t.min);
// Print the formatted string to serial so we can see the time for debuging
Serial.println(buf);
int dt=t.hr*100 + t.min;
return dt;
}

} // namespace
void setup() {
Wire.begin();
Serial.begin(9600);


display.setBrightness(0x0F);
display.clear();
// Initialize a new chip by turning off write protection and clearing the
// clock halt flag. These methods needn't always be called. See the DS1302
// datasheet for details.

// rtc.writeProtect(false);

// rtc.halt(false);
// Make a new time object to set the date and time.
// This need to be done first time to set the Date and time.
// Thursday, July 6, 2017 at 22:58:50.
// Time t(2017, 07, 6, 22, 58, 50, Time::kThursday);
// Set the time and date on the chip.
// rtc.time(t);
}
// Loop and print the time every second.
void loop() {
int decimaltime;
decimaltime=printTime();

display.showNumberDecEx(decimaltime,(0x80>>1),true,4,0);
delay(1000);
display.showNumberDec(decimaltime,true,4,0);
delay(1000);

}

The above project can be modified to work with RTC 1307 or other clock chip. For more details on real time clock refer my other projects on RTC

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.