Digital Clock with Arduino using DS3231 RTC and 7-segment LED

Introduction

Arduino is a popular microcontroller board that can be used to build various electronic projects. One of the common projects that can be built with Arduino is a Digital Clock with Arduino using DS3231 RTC and 7-segment LED. By using a real-time clock (RTC) module, such as the DS3231, and a 7-segment LED display, we can build an accurate and reliable clock that displays time and date. This project is a great way to learn about microcontroller programming, sensor interfacing, and display handling.

Hardware Required

You will require the following Hardware Components to make Digital Clock with Arduino using DS3231 RTC and 7-segment LED display

Components#Buy From Amazon
Arduino UNO1Buy Link
DS3231 real-time clock module1Buy Link
7-segment LED display TM16371Buy Link
Jumper WiresBuy Link
Breadboard1Buy Link

What is the DS3231 Module?

DS3231 is a highly accurate real-time clock (RTC) module that can be used to keep track of time even when the device is turned off or disconnected from a power source. The module is equipped with a temperature-compensated crystal oscillator (TCXO) which provides high-accuracy time-keeping (+/- 2ppm) and a battery backup that can last up to several years.

The DS3231 module communicates with a microcontroller or single-board computer (SBC) via the I2C interface and provides the current time and date information including seconds, minutes, hours, day, date, month, and year. The module also has alarm functions and a temperature sensor which can be used to trigger certain events or tasks.

The DS3231 is commonly used in various projects that require accurate time-keeping such as clocks, data loggers, temperature and humidity sensors, and automation systems. It is also popular among hobbyists and electronics enthusiasts due to its ease of use and low cost.

Interfacing-DS3231-RTC-Real-Time-Clock-Module-with-Arduino

Specifications

  1. Supply voltage range: 2.3V to 5.5V
  2. Operating temperature range: -40°C to +85°C
  3. RTC accuracy: ±2ppm (at 0°C to +40°C)
  4. Timekeeping current: 0.25mA (typical)
  5. Battery backup current: 0.35μA (typical)
  6. I2C bus frequency: Up to 400kHz
  7. Two time-of-day alarms
  8. 1Hz and 32.768kHz square-wave outputs

Features

  1. High accuracy – DS3231 has an accuracy of ±2 ppm, which is much higher than other RTCs available in the market.
  2. Low power consumption – It consumes only 0.25 mA in normal operation and has a backup supply voltage of 1.8V to 5.5V.
  3. Simple interface – DS3231 uses a simple I2C interface for communication with other devices.
  4. Battery backup – DS3231 has a built-in backup battery that keeps the clock running even when the main power is disconnected.
  5. Programmable alarms – DS3231 has two programmable alarms that can be used for various applications.

Pinout

Pin Configuration

Pin NameDescription
VCCConnected to Positive of power source
GNDConnected to ground.
SDASerial Data pin (I2C interface)
SCLSerial Clock pin (I2C interface)
SQWSquare Wave output pin
32K32K oscillator output

Circuit Diagram

The following circuit shows you the connection of the Digital Clock with Arduino using DS3231 RTC and 7-segment LED display Please make the connection carefully

Digital-Clock-with-Arduino-using-DS3231-RTC-and-7-segment-LED-Arduino-Circuit

Circuit Connections

ArduinoDS3231 Module7 Segment Display
5VVCC PinVCC Pin
GNDGND PinGND Pin
A4SDA
A5SCL
D2CLK
D3DIO

Working Explanation

The DS3231 RTC module provides accurate time and date information and also includes an onboard temperature sensor. The 7-segment LED display is used to display the current time and date. The Arduino is programmed to read the time and date data from the RTC module and then display it on the LED display. The code can also include functions to adjust the time and date, set alarms, and switch between different display modes.

The RTC module communicates with Arduino using the I2C protocol, while the 7-segment LED display can be interfaced using either the SPI or shift register method. The Arduino board reads the data from the RTC module and sends it to the LED display to display the time and date.

To display the time and date on the 7-segment LED display, the Arduino needs to decode the time and date data and convert it into a format that can be displayed on the LED display. This can be achieved using various techniques, such as multiplexing and software decoding.

Installing Arduino IDE Software

First, you will require to Download the updated version of Arduino IDE Software and Install it on your PC or laptop. if you Learn How to install the Arduino step-by-step guide then click on how to install Arduino Button given Blow

Installing Libraries

Now when you are Ready to upload the code, to the Arduino Board you will need first to add the Following Libraries in Arduino, If you Learn How to add the library in the Arduino step-by-step guide click on how to install the library Button given Blow

Code

//For more Projects: www.arduinocircuit.com
#include "RTClib.h"
#include <TM1637Display.h>

// Define the connections pins:
#define CLK 2
#define DIO 3

// Create rtc and display object:
RTC_DS3231 rtc;
TM1637Display display = TM1637Display(CLK, DIO);

void setup() {
  // Begin serial communication at a baud rate of 9600:
  Serial.begin(9600);
  // Wait for console opening:
  delay(3000);

  // Check if RTC is connected correctly:
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  // Check if the RTC lost power and if so, set the time:
  if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
    // The following line sets the RTC to the date & time this sketch was compiled:
    //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    rtc.adjust(DateTime(2021,5,13,15,28,05));     //2021/5(Month)/16(Day) -- 15H:28H:05S
  }

  // Set the display brightness (0-7):
  display.setBrightness(5);
  // Clear the display:
  display.clear();
}

void loop() {
  // Get current date and time:
  DateTime now = rtc.now();

  // Create time format to display:
  int displaytime = (now.hour() * 100) + now.minute();

  // Print displaytime to the Serial Monitor:
  Serial.println(displaytime);

  // Display the current time in 24 hour format with leading zeros enabled and a center colon:
  display.showNumberDecEx(displaytime, 0b11100000, true);

  // Remove the following lines of code if you want a static instead of a blinking center colon:
  delay(1000);

  display.showNumberDec(displaytime, true); // Prints displaytime without center colon.

  delay(1000);
}

Applications

  1. This clock can be used as a desk or wall clock in homes and offices.
  2. It can be integrated with other projects that require accurate timing information, such as data loggers and environmental monitoring systems.
  3. The clock can be customized to display information in different formats, such as 12-hour or 24-hour time, and in different languages.
  4. The project can be expanded to include additional features, such as setting alarms and displaying temperature and humidity information.
  5. It can be a fun and educational project for beginners to learn about microcontroller programming and sensor interfacing.

Conclusion

Building a clock with Arduino, DS3231 RTC, and a 7-segment LED display is a great way to learn about microcontroller programming and sensor interfacing. This project can be expanded and customized to suit different requirements and applications, making it a versatile and useful project. The accuracy and reliability of the DS3231 RTC module make it an ideal choice for time-sensitive applications. By following the instructions and code examples available online, anyone can build their

See Also

  1. Arduino Cooling System using DHT Sensor for beginners
  2. KY-011 Two Color LED module with Arduino
  3. LED Brightness Control using Potentiometer with Arduino

Leave a Comment


error: