Arduino Digital Clock With/Without DS1307 RTC Module

A digital clock is a great invention in electronics science. Nowadays, digital clocks are used everywhere. The analog clocks are quite old-fashioned. So the digital clock takes its place day by day. The Arduino digital clock is looking very modern. It has many additional features also like temperature, alarm, timer, etc.

In this electronics project, we are going to build an Arduino digital clock with or without an RTC (Real Time Clock) module. The first circuit represents without RTC module and the second circuit represents with RTC module. The components we used in this project are quite basic and a little expensive. The circuit connection is very easy.

Principle Behind Arduino Digital Clock

We build this digital clock with an Arduino, RTC module, and LCD display in this project. Here the clock we made is 24 hours clock. This means the time shows by the clock is 00.00 AM to 23.59. After 23.59 it resets to 0 again.

Project

Arduino Digital Clock With/Without DS1307 RTC Module

About Parts

Arduino

arduino-nano

Arduino is one of the most popular electronics prototyping boards based on the ATmega328P microcontroller. ATmega328P is an AVR architecture based 8-bit microcontroller. Here I am using Arduino Nano for this project to give it a compact look.

16×2 LCD Display

A 16×2 LCD display is the most commonly used display unit for microcontroller-based applications. It supports 16 characters in a row with two such rows. It also supports special characters and even custom characters.

I2C LCD Display Module

i2c-module

I2C Module has an inbuilt PCF8574 I2C chip that converts I2C serial data to parallel data for the 16 pins LCD display. It is currently available with a default I2C address of either 0x27 or 0x3F. With this I2C LCD module, we can able to show data via only 2 wires that are SDA and SCL pins.

DS1307 Real Time Clock Module

ds1307 real time clock module

The DS1307 real-time clock (RTC) is a low power, full binary-coded decimal (BCD) clock plus 56 bytes of NV SRAM. Address and data are transferred serially through an I2C bus. This clock provides seconds, minutes, hours, days, dates, months, and years.

Arduino Digital Clock With DS1307 RTC Module

Circuit Diagram

Arduino Digital Clock Using RTC Module Circuit

Components Required

  • Arduino
  • 16×2 LCD Display
  • I2C Module
  • DS1307 Real Time Clock Module
  • Push Button (x3)
  • Buzzer
  • 9V Battery

Circuit Connection

A serial I2C bidirectional bus made a communication between the Arduino and the DS1307 RTC module. The I2C protocol is a technique for communicating a faster device (master mode) and a slower device (slave mode).

In Arduino, there are 2 pins for I2C communication. Those are A4 and A5. These pins act as SDA (serial data) and SCL (serial clock) respectively.

SDA and SCL pins of both the I2C display module and DS1307 RTC module are connected to A4 and A5 respectively.

Circuit Design Using PCB Software

To make the circuit compact and give a professional look, I have designed the PCB after testing all the features of the Arduino Digital Clock Circuit PCB on the breadboard. I will explain in detail how we can design and order PCB for our project.

Arduino Digital Clock Using RTC Module Pcb

For the Gerber file check out this link Arduino Digital Clock Using RTC.

Order PCB From PCBWay

This project is sponsored by PCBWay.com. PCBWay is a Chinese-based PCB (printed circuit board) prototype, PCB assembly, SMD Stencil, and Flexible PCB manufacturer. They ship to more than 170 countries worldwide and process more than 2100 PCB orders a day. It feels like PCBWay gives an excellent price and customer service factor in one single serving. The quality of the PCB is awesome and its thickness is really great. What is also spectacular about PCBWay to me, as a maker and customer, is their service. From their friendly support staff to their intuitive, user-friendly website features, it all counts towards what makes PCBWay an ideal company and brand for any electronic hobbyists In this article, I will state that how can we order PCB from PCBWay with step by step guide.

Features of PCBWay

1. PCB prototyping and manufacturing

They are not only producing FR-4 and Aluminum boards, but also advanced PCB like Rogers, HDI, Flexible and Rigid-Flex boards, at a very reasonable price.

Visit the link for Instant Quote

Visit the link for Gerber file viewer

2. PCB assembly

SMT & THT assembly starts from only $30 with a free stencil and free worldwide shipping. The components can be sourced and provided by PCBWay, or by clients themselves.

3. Layout and design

Partnering with quality service providers to offer design services.

4. Open source community

Student sponsorship shared PCB projects and so on.

5. 3D Printing & CNC

On-demand Production and Rapid Prototyping in as Fast as 1 Day Leading the Digital Manufacturing Revolution.

Step 1: Go to the PCBWay website and sign up/sign in. Into the PCB Prototype tab, enter the dimensions of your PCB, the number of layers, and the number of PCBs you require. After that proceed by clicking on the ‘Quote Now’ button.

Step 2: You will be redirected to a page where to set a few additional parameters like the board type, layers, material for PCB, thickness, and more, most of them are selected by default, if you are opting for any specific parameters, you can edit it in here.

Step 3: The final step is to upload the Gerber file and proceed with the payment. To make sure the process is smooth, PCBWAY verifies if your Gerber file is valid before proceeding with the payment. This way, you can be sure that your PCB is fabrication friendly.

Working Principle of Arduino Digital Clock With RTC Module

We build this project to create a real-time clock for our daily life. The working principle of this clock is so simple.

With a real-time clock module, this circuit is working in automatic mode. Although we can manually set the time as our requirements through Arduino code. As we say that this is an automatic clock so the system can set time and date itself like a computer.

The whole circuit is working as a continuous sequence. When the power goes out, the circuit will not reset to its initial position.

Arduino Code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2);
char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
void setup () 
{
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  if (! rtc.begin()) 
  {
    lcd.print("Can't Find RTC");
    while (1);
  }
  if (! rtc.isrunning()) 
  {
    lcd.print("RTC is NOT running!");
  }
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));//auto update from computer time
    //rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));// to set the time manualy 
}
void loop () 
{
    DateTime now = rtc.now();
    lcd.setCursor(0, 1);
    lcd.print("TIME");
    lcd.print(" ");
    lcd.print(now.hour());
    lcd.print(':');
    lcd.print(now.minute());
    lcd.print(':');
    lcd.print(now.second());
    lcd.print("  ");
    lcd.setCursor(0, 0);
    lcd.print("DATE");
    lcd.print(" ");
    //lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
    //lcd.print(" ");
    lcd.print(now.day());
    lcd.print('/');
    lcd.print(now.month());
    lcd.print('/');
    lcd.print(now.year());
    lcd.print("  ");   
}

Arduino Digital Clock Without RTC Module

Circuit Diagram

Arduino Digital Clock Circuit

Components Required

  • Arduino
  • 16×2 LCD Display
  • I2C LCD Display Module
  • Push Button (x3)
  • 9V Battery

Circuit Connection

To make the digital clock’s first circuit, we need an Arduino board, two pushbuttons, an LCD display, and an I2C Display Module.

First of all, connect all two push buttons’ any one terminal to the ground. Then other terminals of the two buttons are connected to analog pins D8 and D9 of the Arduino respectively.

In Arduino, there are 2 pins for I2C communication. Those are A4 and A5. These pins act as SDA (serial data) and SCL (serial clock) respectively.

SDA and SCL pins of the I2C display module are connected to A4 and A5 respectively.

Circuit Design Using PCB Software

To make the circuit compact and give a professional look, I have designed the PCB after testing all the features of the Arduino Digital Clock on the breadboard. I will explain in detail how we can design and order PCB for our project.

Arduino Digital Clock Pcb

For the Gerber file check out this link Simple Arduino Digital Clock

Working Principle of Arduino Digital Clock Without RTC Module

Without a real-time clock module, the circuit is working as a manual controller. We can manually set the time as our requirements.

The first button is for setting up the hour by sending a signal to the D8 pin. The second button is for setting up the minutes by sending a signal to the D9 pin of the Arduino.

The whole circuit is working as a continuous sequence. When the power goes out, the circuit will reset to its initial position. Then we need to again set the time via the push button. So this is a major drawback for this circuit.

Arduino Code

#include <Wire.h>  
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Digital LCD Constrast setting
int cs=9;// pin 9 for contrast PWM
const int contrast = 100;// default contrast
// initial Time display is 12:00:00 PM
int h=12;
int m=00;
int s=00;
int flag=1; //PM
// Time Set Buttons
int button1;
int button2;
// Pins definition for Time Set Buttons
int hs=8;// pin 0 for Hours Setting
int ms=9;// pin 1 for Minutes Setting
// Backlight Time Out 
const int Time_light=150;
int bl_TO=Time_light;
int bl=10;
const int backlight=120;
// For accurate Time reading, use Arduino Real Time Clock and not just delay()
static uint32_t last_time, now = 0; // RTC
void setup()
{
  lcd.init();
  lcd.backlight();
  
  pinMode(hs,INPUT_PULLUP);// avoid external Pullup resistors for Button 1
  pinMode(ms,INPUT_PULLUP);// and Button 2
  analogWrite(cs,contrast);// Adjust Contrast VO
  analogWrite(bl,backlight);// Turn on Backlight
  now=millis(); // read RTC initial value  
}
void loop()
{ 
  lcd.init();
  lcd.backlight();
  
// Update LCD Display
// Print TIME in Hour, Min, Sec + AM/PM
 lcd.setCursor(0,0);// for Line 2
 lcd.print(" ELECTRO GADGET");
 
 lcd.setCursor(0,1
 
 );
 lcd.print("Time ");
 if(h<10)lcd.print("0");// always 2 digits
 lcd.print(h);
 lcd.print(":");
 if(m<10)lcd.print("0");
 lcd.print(m);
 lcd.print(":");
 if(s<10)lcd.print("0");
 lcd.print(s);
 if(flag==0) lcd.print(" AM");
 if(flag==1) lcd.print(" PM");
// improved replacement of delay(1000) 
// Much better accuracy, no more dependant of loop execution time
for ( int i=0 ;i<5 ;i++)// make 5 time 200ms loop, for faster Button response
{
  while ((now-last_time)<200) //delay200ms
  { 
    now=millis();
  }
 // inner 200ms loop
 last_time=now; // prepare for next loop 
 // read Setting Buttons
 button1=digitalRead(hs);// Read Buttons
 button2=digitalRead(ms);
 //Backlight time out 
 bl_TO--;
 if(bl_TO==0)
 {
  analogWrite(bl,0);// Backlight OFF
  bl_TO++;
 }
 
 // Hit any to activate Backlight 
 if(  ((button1==0)|(button2==0)) & (bl_TO==1)  )
 {
  bl_TO=Time_light;
  analogWrite(bl,backlight);
  // wait until Button released
  while ((button1==0)|(button2==0))
  {
   button1=digitalRead(hs);// Read Buttons
   button2=digitalRead(ms);
  }
 }
 else
 // Process Button 1 or Button 2 when hit while Backlight on 
 {
  if(button1==0){
   h=h+1;
   bl_TO=Time_light;
   analogWrite(bl,backlight);
  }
 if(button2==0){
  s=0;
  m=m+1;
  bl_TO=Time_light;
  analogWrite(bl,backlight);
  }
/* ---- manage seconds, minutes, hours am/pm overflow ----*/
 if(s==60){
  s=0;
  m=m+1;
 }
 if(m==60)
 {
  m=0;
  h=h+1;
 }
 if(h==13)
 {
  h=1;
  flag=flag+1;
  if(flag==2)flag=0;
 }
 if((button1==0)|(button2==0))// Update display if time set button pressed
 {
  // Update LCD Display
  // Print TIME in Hour, Min, Sec + AM/PM
  lcd.setCursor(0,0);
  lcd.print("Time ");
  if(h<10)lcd.print("0");// always 2 digits
  lcd.print(h);
  lcd.print(":");
  if(m<10)lcd.print("0");
  lcd.print(m);
  lcd.print(":");
  if(s<10)lcd.print("0");
  lcd.print(s);
  if(flag==0) lcd.print(" AM");
  if(flag==1) lcd.print(" PM");
 
  lcd.setCursor(0,1);// for Line 2
  lcd.print("lcd clock");
 }
 } // end if else
}// end for
// outer 1000ms loop
 s=s+1; //increment sec. counting
    
    
// ---- manage seconds, minutes, hours am/pm overflow ----
 if(s==60){
  s=0;
  m=m+1;
 }
 if(m==60)
 {
  m=0;
  h=h+1;
 }
 if(h==13)
 {
  h=1;
  flag=flag+1;
  if(flag==2)flag=0;
 } 
 
 
// Loop end
}

Applications of Arduino Digital Clock

  • This clock is used in data logging applications.
  • It can be used in time stamps.
  • As an alarm and timer.
  • As a simple clock in houses, offices, etc. 

Frequently Asked Questions

How do I set the time on my Arduino RTC?

For this project, it needs to set the real-time into Arduino code when uploading. But after that, we need not set the time every time when better die. Just remove the old battery and put the new one that’s it.

Does Arduino have a real-time clock library?

Yes, there is a few Arduino real-time clock (RTC) libraries in the library manager of the Arduino IDE software. These help to compile Arduino code and upload it into the Arduino board.

How can I make an Arduino based clock without an RTC module?

To make this clock is too easy. But the only drawback of this clock is when the power cut down, we need to set the time again from the beginning. To build this clock go to this blog and check out the second circuit.

Why RTC is used in Arduino digital clocks?

The main purpose of using an RTC or a real-time clock is to provide a precise time and date which is very accurate. RTC is an electronic device in the form of an Integrated Chip (IC) available in various packaging options. It is powered by an internal lithium-ion battery.

How do RTC works?

An RTC maintains its clock by counting the cycles of an oscillator (32.768KHz Crystal Oscillator) circuit, an internal capacitor-based oscillator, or even an embedded quartz crystal. Some RTCs maintain the oscillator setting at the last known point before it went out of the lock with the power input.

What is the full form of RTC?

The full form of RTC is a Real-Time Clock.

1 thought on “Arduino Digital Clock With/Without DS1307 RTC Module”

Leave a Comment