4-digit RTC Clock © LGPL

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

  • 2,704 views
  • 0 comments
  • 11 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.

Schematics

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

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);
   }

Comments

Author

Pentiumcadiz
pentiumcadiz
  • 2 projects
  • 1 follower

Additional contributors

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

Published on

January 7, 2017

Members who respect this project

Avatar?size=thumbAvatar?size=thumbAvatar?size=thumbAvatar?size=thumbAvatar?size=thumbAvatar?size=thumb

and 5 others

See similar projects
you might like

Similar projects you might like

BluSpike - Community Driven BLE Sensor Network

Project tutorial by Moheeb Zara

  • 44 views
  • 0 comments
  • 2 respects

NeoPixel Thermometer!

Project tutorial by fmattiussi

  • 91 views
  • 1 comment
  • 4 respects

Arduino - Web-Based Thermometer

Project tutorial by khanhhs

  • 1,035 views
  • 0 comments
  • 15 respects

Arduino - Have Fun with Color Sensor

Project tutorial by khanhhs

  • 952 views
  • 0 comments
  • 13 respects

Using Python and Arduino MKR1000 for Secure IoT

Project tutorial by Luigi Francesco Cerfeda

  • 3,184 views
  • 1 comment
  • 15 respects

Play Music With Your Remote

Project tutorial by Simone Adobs

  • 858 views
  • 12 comments
  • 7 respects
Add projectSign up / Login