Introduction
In this project, we will design a digital clock using Arduino that works in the Serial Monitor.
Unlike simple timer programs, this clock will start only after the user enters the present time manually in AM/PM format.
This project is very useful for beginners because it helps to understand:
-
Serial communication
-
Time calculation using
millis() -
String input handling
-
AM/PM logic
-
Digital clock formatting
The user must enter the time in this format:
Example:
After entering the time, the clock starts running like a real digital clock.
Components Required
-
USB cable
-
Arduino IDE
-
Serial Monitor
(No other external hardware is required.)
Working Principle
-
When the program starts, Arduino waits for the user to enter the current time.
-
The clock does not run until valid time input is received.
-
After setting the time, Arduino counts seconds using the
millis()function. -
Every second, it updates:
-
Seconds
-
Minutes
-
Hours
-
AM/PM
-
-
The updated time is displayed in the Serial Monitor continuously.
Time Input Format
The user must enter time in the following format:
Examples:
Arduino Program Code
How to Use
-
Upload the program to Arduino
-
Open Serial Monitor
-
Set:
-
Baud Rate = 9600
-
Line Ending = Newline
-
-
Enter time like:
-
Press Enter
-
The digital clock will start running
Sample Output
Detailed Program Explanation
This program uses variables to store hours, minutes, seconds, and AM/PM status. A flag variable (timeSet) ensures the clock does not start until the user enters time. The millis() function is used to create a 1-second interval without using the delay() function.
The program reads the input time from the Serial Monitor, separates hours, minutes, seconds, and AM/PM using sscanf(), and stores them in variables. Once time is set, the clock increments seconds every second. When seconds reach 60, minutes increase. When minutes reach 60, hours increase. When hours reach 12, AM/PM toggles. If hours reach 13, they are reset to 1 to maintain 12-hour format.
Finally, the time is printed in HH:MM:SS AM/PM format with leading zeros.
Advantages
-
No RTC module required
-
Works in Tinkercad
-
Easy to understand
-
Suitable for beginners
-
Supports AM/PM format
Applications
-
Learning Arduino timing
-
Digital clock project
-
Serial communication practice
-
Base code for alarm clock
-
Base code for LCD clock
Conclusion
This project demonstrates how to build a digital clock using Arduino Serial Monitor that starts only after entering the present time in AM/PM format. It is an excellent beginner project to understand time logic and serial input handling. The same program can be extended to include LCD display, alarm feature, or RTC module for real-time accuracy.