4-digit RTC Clock © LGPL

A clock, controlled by a RTC module, that you can see on a 4-digit display.

  • 13,696 views
  • 5 comments
  • 18 respects

Components and supplies

About this project

4-Digit Clock based on a RTC module

I have got a DS1302 Real Time Clock Module with Battery Backup, and I was eager to making a digital clock. As I also had a 7-segment 4-digit display, I was looking for the best way to make that clock. But I was always reluctant to use this type of display, because of the amount of wires it requires.

Then, "digital tube" 4-wire 4-digit display came across, and I knew that was the solution I was searching for. Now I had all the pieces of my little system.

I used the examples of the DS1307RTC library to set the date and time on the RTC board. Then I created this sketch based on that example and based on Prometec's example to use the display.

It was a piece of cake. Great fun in a short time. Next challenge: making it on a Arduino Nano (instead of the UNO R3) and look for a nice box to keep it safe.

Code

4-digit RTC I2C clockArduino
Reloj digital mostrado a través de un display de 4 dígitos (digitaltube), y con el tiempo proporcionado por un Tiny RTC de Catalex.

Software programado por PentiumCadiz 7-1-17, basado en el ejemplo de la librería DS1307RTC y en el ejemplo de uso del display de Prometec http://www.prometec.net/display-con-interface/
// Reloj digital mostrado a través de un display de 4 dígitos (digitaltube), y con el tiempo
// proporcionado por un Tiny RTC de Catalex.

// Software programado por PentiumCadiz 7-1-17, basado en el ejemplo de la librería DS1307RTC 
// y en el ejemplo de uso del display de Prometec  http://www.prometec.net/display-con-interface/ 

#include <TM1637.h>

#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>

#define CLK 9
#define DIO 8

TM1637 Display1(CLK, DIO);
  int8_t Digitos[] = {0,1,2,3};
  int horas;
  int minutos;
  boolean alterna;

void setup() {
  Serial.begin(9600);
  while (!Serial) ; // wait for serial
  delay(200);
  Serial.println("DS1307RTC Read Test");
  Serial.println("-------------------");

  Display1.set();
  Display1.init();
  
}

void loop() {
  tmElements_t tm;

  if (RTC.read(tm)) {
    Serial.print("Ok, Time = ");
    print2digits(tm.Hour);
    Serial.write(':');
    print2digits(tm.Minute);
    Serial.write(':');
    print2digits(tm.Second);
    Serial.print(", Date (D/M/Y) = ");
    Serial.print(tm.Day);
    Serial.write('/');
    Serial.print(tm.Month);
    Serial.write('/');
    Serial.print(tmYearToCalendar(tm.Year));
    Serial.println();

    horas = tm.Hour;
    minutos = tm.Minute;
    CalculaDigitos(horas, minutos);
    if (alterna)
      {
        Display1.point(POINT_OFF);
        alterna = false;
      }
      else
      {
        Display1.point(POINT_ON);
        alterna = true;
      }
    
  } else {
    if (RTC.chipPresent()) {
      Serial.println("The DS1307 is stopped.  Please run the SetTime");
      Serial.println("example to initialize the time and begin running.");
      Serial.println();
    } else {
      Serial.println("DS1307 read error!  Please check the circuitry.");
      Serial.println();
    }
    delay(9000);
  }
  delay(1000);
}

void print2digits(int number) {
  if (number >= 0 && number < 10) {
    Serial.write('0');
  }
  Serial.print(number);
}

void CalculaDigitos( int hor, int minu)
   {
      int8_t Digit0 = minu %10 ;
      int8_t Digit1 = (minu % 100) / 10 ;
      int8_t Digit2 = hor % 10 ;
      int8_t Digit3 = (hor % 100) / 10 ;

      Digitos[3] = Digit0 ;
      Digitos[2] = Digit1 ;
      Digitos[1] = Digit2 ;
      Digitos[0] = Digit3 ;

      Display1.display(Digitos);
   }

Schematics

4-digit RTC I2C clock
A digital clock you can make in a short time.
x7vmu5RlEYC2g9I4Dt5m.fzz

Comments

Author

Pentiumcadiz
pentiumcadiz
  • 3 projects
  • 2 followers

Additional contributors

  • My code is based on prometec's code by Prometec

Published on

January 7, 2017

Members who respect this project

DefaultJfo caricatura 1DefaultMichaalfrazierKc2ipxImages qo0hw5riazCnyn noo6fluiipJimmytime

and 10 others

See similar projects
you might like

Similar projects you might like

Night Light Assistant

Project tutorial by Gabriele Fugazzi

  • 1,128 views
  • 4 comments
  • 8 respects

Smart Energy Saver for Your Home

Project tutorial by Dhairya Parikh

  • 3,621 views
  • 8 comments
  • 12 respects

A Geiger Counter Simulator

Project tutorial by organtin

  • 1,370 views
  • 1 comment
  • 7 respects

Twilight Switch With Levels

Project in progress by Rafa Salvador

  • 1,239 views
  • 1 comment
  • 5 respects

Arduino MKR DIN Rail Mount

Project showcase by hwhardsoft

  • 1,072 views
  • 0 comments
  • 4 respects

Simple Water Quality Analysis

Project showcase by Wen-Liang Lin

  • 7,423 views
  • 5 comments
  • 11 respects
Add projectSign up / Login