How To Make A Digital Clock With Arduino UNO

Digital Clock Arduino UNO
Share this blog with others!

In the previous blog, we learned how to connect the LCD Display to the Arduino UNO and how to Display Text in LCD Screen. In this blog, we will learn how to make a digital clock in Arduino UNO using a 16X2 LCD Screen.

Ever thought about how a digital clock is programmed to show the time on a display.

Now let’s put some jumper wires and resistors to make this project.

DIGITAL CLOCK in 16×2 LCD connected to ARDUINO UNO.

Display units play an important role in establishing good communication between the human and machine worlds. And so they are a big part of embedded systems.

Introduction

The 16×2 LCD Screen will have a total of 32 characters, 16 in the 1st line, and a further 16 in the 2nd line. In 16×2 LCD there are 16  pins overall if there are backlight, 14 pins if there is no backlight. In each character, there are 50 pixels.

Components Required for Digital Clock in Arduino UNO

Hardware: 

  • ARDUINO UNO
  • power supply (5v)
  • 16×2 LCD Screen
  • 100uF capacitor
  • Breadboard

Software:

  • Arduino IDE
  • LiquidCrystal Library
connect LCD to Arduino UNO

Digital Clock Circuit Diagram Arduino UNO

Digital Clock Circuit Diagram Arduino UNO
Digital Clock Circuit diagram ARDUINO UNO.

Now, let’s build the circuit. A circuit layout can be described in several ways. For this project (How To Connect LCD 16×2 Display To Arduino), we are using a physical layout diagram similar to the one shown above.

By comparing the wiring diagram with the sketched functions, You should start making sense of the circuit.

  • LCD RS pin to digital pin 12
  • Enable pin of LCD to digital pin 11
  • LCD D4 pin to digital pin 5
  • D5 pin of LCD to digital pin 4
  • LCD D6 pin to digital pin 3
  • D7 pin of LCD to digital pin 2
  • LCD R/W pin to ground
  • VSS pin of LCD to ground
  • LCD VCC pin to 5V
  • 10K resistor
  • ends to +5V and ground
  • wiper to LCD VO pin (pin 3)

If you want to see the stimulation of the project. Click here https://www.tinkercad.com/things/5nSdmAXX4Aj

Digital Clock Arduino UNO Code

In this blog, we understood how to connect the LCD screen to Arduino UNO.

Now, we will cover the code how to display clock in an LCD screen using Arduino IDE.

#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int h=12;
int m;
int s;
int flag;
int TIME;
const int hs=8;
const int ms=9;
int state1;
int state2;
void setup()
{
   lcd.begin(16,2);
}
void loop()
{
    lcd.setCursor(0,0);
    s=s+1;
    lcd.print("TIME:" );
    lcd.print(h);
    lcd.print(":");
    lcd.print(m);
    lcd.print(":");
    lcd.print(s);
    if(flag<12) lcd.print(" AM");
    if(flag==12) lcd.print(" PM");
    if(flag>12) lcd.print(" PM");
    if(flag==24) flag=0;
    delay(1000);
    lcd.clear();
    if(s==60) {
    s=0;
    m=m+1;
}
if(m==60)
{
    m=0;
    h=h+1;
    flag=flag+1;
}
if(h==13)
{
    h=1;
}
lcd.setCursor(0,1);
lcd.print("HACKTHEDEVELOPER");
//-----------Time setting----------//
state1=digitalRead(hs);
if(state1==1)
{
    h=h+1;
    flag=flag+1;
    if(flag<12) lcd.print(" AM");
    if(flag==12) lcd.print(" PM");
    if(flag>12) lcd.print(" PM");
    if(flag==24) flag=0;
    if(h==13) h=1;
}
    state2=digitalRead(ms);

    if(state2==1) {
        s=0;
        m=m+1;
    }
}
 

In this program, we have discussed many functions like delay()digitalWrite()pinMode().

It’s time to learn what are these functions and how they work.

delay() is a blocking function. It is the syntax of writing for giving hold between ON and OFF or 0 and 1 signal to the Arduino.
In the above code, we have provided 1000ms to the delay() function that is equal to 1 second.

digitalWrite() – This function helps in to write the command on the microcontroller i.e which should give LOW output or which pin should give HIGH output. digitalWrite(6, LOW); this line means pin number 6 will be LOW or OFF and digitalWrite(8, HIGH); pin number 8 will be HIGH or ON.

pinMode() – This function helps to assign the pin number and clarify that a specific pin number is given OUTPUT or take INPUT from the sensors or the components.

LiquidCrystal.h is a type of header file. SetCursor is a function that is present in the LiquidCrystal.h header file. With the help of this function, we fix the coordinate in LCD Display.

h,m,s,flag,TIME,hs,ms,state1,state2 are the variables in the program.

Lcd.begin(16,2), 16×2 means that the LCD has 2 lines, and can display 16 characters per line. Therefore, a 16×2 LCD screen can display up to 32 characters at once.

lcd.clear() helps to clear the screen.

lcd.print() function helps to print something on the LCD screen.

Hope you like it!

Take a look at other interesting Arduino Projects.


Share this blog with others!
0 0 vote
Article Rating
Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Jayesh Prakash
Jayesh Prakash
27 days ago

Wonderful piece of information 🤩

2
0
Would love your thoughts, please comment.x
()
x