4-digit RTC Clock

4-digit RTC Clock © LGPL

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

  • 23,606 views
  • 6 comments
  • 23 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
  • 3 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 15 others

See similar projects
you might like

Similar projects you might like

Digital Clock with Arduino, RTC and Shift Register 74HC595

Project tutorial by LAGSILVA

  • 20,732 views
  • 16 comments
  • 46 respects

Digital And Binary Clock With Two LED Matrix And RTC

Project tutorial by LAGSILVA

  • 6,117 views
  • 10 comments
  • 27 respects

Simple Arduino Digital Clock Without RTC

Project in progress by Annlee Fores

  • 96,298 views
  • 23 comments
  • 80 respects

Clock Set Date Time

Project tutorial by Tittiamo

  • 34,198 views
  • 26 comments
  • 43 respects

RTC Based Clock

Project tutorial by shivakumarj1995

  • 9,522 views
  • 13 comments
  • 12 respects

Tri-Mode Digital Clock With ATtiny85 And RTC

Project showcase by LAGSILVA

  • 5,207 views
  • 0 comments
  • 19 respects
Add projectSign up / Login