Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Sensor Series
      • Engineering Deep Dives
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Digital clock using Arduino, 7-segments, and MAX7219

By Nikhil Agnihotri November 21, 2020

A digital clock is a commonly used electronic gadget. A digital clock keeps track of time and displays the current time through an output device. The users can set or reset the clock using buttons. Electronic clocks are built using microcontrollers and may or may not use a real-time clock.

Here, a digital clock is designed using Arduino, 7-segments, and MAX7219 IC. As microcontrollers are usually capable of generating delays of a precise interval, this basic digital clock is built using microcontroller features alone. The digital clock designed here displays the current time and allows users to set or reset time.

Components Required

  1. Arduino UNO x1
  2. 7-Segments x6
  3. MAX7219 IC x1
  4. Push buttons x3
  5. Breadboard x1
  6. Jumper wires or connecting wires

Prerequisites

  1. Interfacing push buttons with Arduino
  2. Multiplexing 7-segments using MAX7219

Circuit Connections
The digital clock designed here is based on the MAX7219 IC-based 7-segment driver module. MAX7219 is an 8-digit common-cathode LED display driver. It allows interfacing a microcontroller to 7-segment display units up to 8 digits. In the module, the data pins of the 7-segments are connected to SEG A to SEG G and DP pins of MAX7219. The common-cathode terminals of the segments are connected to the DIG0 to DIG7 pins of MAX7219. Pins 4 and 9 of the IC are hard-wired to ground, and pin 19 is connected to the 5V terminal. The pin 18 of MAX7219 is also connected to 5V DC via a suitable resistor. The DIN, LOAD, and CLK pins of the IC can be connected to digital I/O pins of Arduino.

MAX7219 communicates with Arduino using an SPI-compatible interface. The DIN, LOAD, and CLK pins of the IC are connected to the pins 12, 10, and 11 of the Arduino UNO, respectively. The MAX7219 module is supplied 5V DC and ground from the Arduino itself.

Along with the MAX7219 IC-based 7-segment driver, 3 push buttons are also connected to the Arduino. These pushbuttons are interfaced at pins 0, 1, and 2 of Arduino UNO. These Arduino pins are internally pulled up. The button at pin 0 controls the mode of the clock. The button at pin 1 allows selecting seconds, minutes, and hours. The button at pin 2 increments the selected clock element, seconds, minutes, or hours.

Arduino Sketch

How the circuit works
There are 6 7-segments used with MAX7219 IC. A pair of 7-segments is used each to display seconds, minutes, and hours. The clock operates in two modes – normal mode (mode 0) and time setting mode (mode 1). In normal mode, the clock simply displays the current time, and Arduino updates it every second.

In time setting mode, the user can set the time using push buttons. The pushbutton at pin 0 of Arduino switches the clock between the two modes. The push buttons at pins 1 and 2 are operational only when the clock is in time-setting mode. The pushbutton at pin 1 allows switching to the selection of seconds, minutes, and hours. The push button at pin 2 increments the selected time element – seconds, minutes, or hours. If the seconds or minutes is incremented above 59 or hours is incremented above 12, they are reset to 0.

How the code works
The Arduino sketch begins by importing the SPI library of Arduino. The global variables are defined to assign pin numbers connected to DIN, CLK, and LOAD pins of MAX7219 IC. A variable of an array type is defined to store 16-bit commands for MAX7219. The variables are defined to store values of seconds, minutes, hours, clock mode, and select.

A character table is stored in the flash memory of Arduino UNO using PROGMEM construct. This table contains the bytes that must be written to the LED segments for displaying digits 0 to 9.

A function spiTransfer() is defined that shiftOut() function to transfer 16-bit data to MAX7219 IC. Each 16-bit data contains two bytes, the first byte is the address of the MAX7219 register, and the second byte is the data to be written to a selected register. Both bytes are passed as arguments to this user-defined function.

A function clearDisplay() is defined, in which, spiTransfer() function is used to write 0x00 to all the digit registers clearing all the digits. A function shutdown() is defined, which uses spiTransfer() function to write data to the shutdown mode register of MAX7219.

A function init_7seg() is defined to initialize the display. In the function, first, the MOSI, SCLK, and CS pins are set to digital output. The CS pin is set to HIGH to select MAX7219 on the SPI bus. A value of 0x00 is transferred to display test register (register address 15 or 0x0F) using spiTransfer() function to set MAX7219 to normal mode. A value of 0x07 is transferred to the scan limit register (register address 11 or 0x0B), allowing all 8 digits. A value of 0x00 is transferred to the decode mode register (register address 9 or 0x09) to select no decode for all digits.

A function setChar() is defined that writes a value to a digit register of MAX7219. Both value and digit are set as parameters of the function. In this function, first, data validation for digit number and the value passed is done. The verified value is passed to a given digit register using spiTransfer() function.

In the setup() function, init_7seg() and shutdown(false) functions are called. The spiTransfer(10, 8) function is called to set the intensity of the display. The display is cleared by calling the clearDisplay() function. The Arduino pins interfaced to push buttons are set as digital input using the pinMode() function.

In the loop() function, Arduino first checks for the pushbutton’s status at pin 0. If the button is pressed, it toggles the clock mode. The default mode is 0 or normal. By default, when the clock is powered on, it goes in normal mode and starts clocking from 12:00:00.

If the clock mode is 0, i.e., normal, Arduino updates the 7-segments with the current values of seconds, minutes, and hours every second using the setChar() function. If the clockmode is 1, i.e., time setting mode, Arduino checks the status of buttons at pins 1 and 2. If the button at pin 1 is pressed, it changes the select variable’s value, and accordingly, seconds, minutes, or hours are selected. If the button at pin 2 is pressed, the selected time element – seconds, minutes, or hours is increased by 1. When the user again presses the button at pin 0, the clock switches back to normal mode, clocking from the user’s time set.

Result

OLYMPUS DIGITAL CAMERA

OLYMPUS DIGITAL CAMERA

Demonstration video


Filed Under: Arduino Projects, Microcontroller Projects

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

Log in to leave a comment:

Lost your password?

Don't have an account? Register here

Submit a Guest Post

submit a guest post

EE TECH TOOLBOX

“ee
Tech Toolbox: Sensors
In this Tech Toolbox, we cover some of those technologies driving the next generation of connected systems, including ultra-low-power sensing strategies that extend node battery life, and 60 GHz CMOS radar for contactless health and presence detection.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions.

  • PCB manufacturing
  • Solenoid AC Magnetic field water pump
  • H-bridge power supply capacitor - heating and selection
  • how RS-485 transmits and receive logic levels between two MCUs
  • Solving adaptive frequency ..., process hf3d error: Failed to solve port 1, solving at too low frequency is a possible cause.

RSS Electro-Tech-Online.com Discussions

  • My Advanced Realistic Humanoid Robots Project
  • What is the most suitable light source for making a book light like this?
  • extracting material properties from open load resonance
  • Oshon Basic, programing IF statements
  • How charging is done in Transformer Inverters

Featured Tutorials

Learn - VHDL Tutorials (22 Part)

  • VHDL Tutorial – 11: Designing half and full-subtractor circuits
    VHDL Tutorial – 11: Designing half and full-subtractor circuits
  • VHDL Tutorial – 12: Design a 8-bit parity generator and circuit checker
    VHDL Tutorial – 12: Design a 8-bit parity generator and circuit checker
  • VHDL tutorial 13: Design 3×8 decoder and 8×3 encoder using VHDL
    VHDL tutorial 13: Design 3×8 decoder and 8×3 encoder using VHDL
  • VHDL Tutorial 14: Design 1×8  demultiplexer and 8×1 multiplexer using VHDL
    VHDL Tutorial 14: Design 1×8  demultiplexer and 8×1 multiplexer using VHDL
  • VHDL Tutorial 17: Design a JK flip-flop (with preset and clear) using VHDL
    VHDL Tutorial 17: Design a JK flip-flop (with preset and clear) using VHDL
  • VHDL Tutorial 18: Design a T flip-flop (with enable and an active high reset input) using VHDL
    VHDL Tutorial 18: Design a T flip-flop (with enable and an active high reset input) using VHDL
More Tutorials >

Recent Articles

  • Finwave launches RF switches up to 18 GHz
  • pSemi switch spans 5 MHz to 3.1 GHz
  • Navitas launches isolated TO-247 package for SiC
  • 3D scanning: How photogrammetry is reshaping digital engineering
  • EPC launches 3-phase GaN motor-drive boards

EE ENGINEERING TRAINING DAYS

engineering
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Sensor Series
      • Engineering Deep Dives
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
  • Guest Post Guidelines
  • Advertise
  • Subscribe