DIY Arduino Digital Clock: A Fun Beginner’s Project

By Tanmoy Kundu

Updated On:

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 an RTC module and the second circuit represents with an 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 shown 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

Arduino Digital Clock

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 which 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 of Arduino Digital Clock With DS1307 RTC Module

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.

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 of Arduino Digital Clock Without RTC Module

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’ in any one terminal to the ground. The 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 it a professional look, I 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 to 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 in 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 does RTC work?

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.

Tanmoy Kundu

I'm the founder of Circuit Diagrams, holds a B.Sc in Electronics and a Master's in Computer Applications (MCA). With a strong foundation in both hardware and software, I combines my passion for electronics and programming to create practical, real-world DIY projects. Driven by the goal of simplifying embedded systems and IoT development, I designs, tests, and documents each project to ensure it's accessible for students, beginners, and makers of all levels. My mission is to turn complex concepts into easy-to-follow solutions through detailed tutorials, eBooks, and custom circuit designs.

1 thought on “DIY Arduino Digital Clock: A Fun Beginner’s Project”

Leave a Comment

Item added to cart.
0 items - 0.00

Don't Try to Copy Content!!!