DS3231 Real Time Clock Tutorial with Arduino UNO R3

Overview

Interface DS3231 Precision RTC Module with Arduino

In many of projects, the microcontrollers (MCUs) we use are typically not equipped to handle time-related functions. While this may suffice for most cases, there are instances where accurate timekeeping becomes crucial. This is where the DS3231 Precision RTC module proves invaluable. With its precise timekeeping capabilities, it is well-suited for a diverse range of projects, such as clocks, timers, alarms, data logging, and time stamping.

The core of this module is based on the DS3231S RTC chip, known for its exceptional capabilities, coupled with the AT24C32 EEPROM. These components have been in use for a considerable period and enjoy robust library support, ensuring reliable and well-documented functionality.

Typically, these modules are equipped with a 200Ω resistor positioned alongside the IN4148 Zener diode, as depicted in the provided image. This resistor-diode combination forms a basic charging circuit specifically intended for LIR2032 rechargeable batteries.

However, it is important to note that certain DS3231 modules may be supplied with a non-rechargeable CR2032 battery instead. In such cases, it is crucial to remove the resistor from the circuit. Charging a non-rechargeable battery can lead to severe damage and should be avoided.

DS3231 RTC Chip

This module offers the flexibility to operate in either a 12-hour or 24-hour format, accommodating different time preferences. It includes an AM/PM indicator, making it easy to distinguish between morning and afternoon hours in the 12-hour mode. Additionally, it features two programmable time-of-day alarms, allowing you to set specific times for triggering alarms or performing actions.

At the core of this module lies the DS3231 RTC chip, designed by Maxim. This low-cost yet highly precise chip handles all timekeeping functions and establishes communication with the microcontroller via I2C.

The DS3231 excels in tracking various time elements, including seconds, minutes, hours, days, dates, months, and years. It even automatically adjusts the date for months with less than 31 days, and it accounts for leap year corrections, maintaining accuracy until the year 2100.

Furthermore, the DS3231 generates a stable and accurate reference clock on its 32K pin. This clock output, which is temperature compensated, proves useful in certain applications for measuring clock timing accuracy or serving as a clock source for other circuits.

Battery Backup

To ensure uninterrupted and precise timekeeping, the DS3231 IC includes a dedicated battery input. This feature allows the module to retain accurate time data even in situations where the main power supply is interrupted or disconnected. By utilizing a backup battery, the DS3231 ensures that timekeeping functions continue seamlessly, providing reliable time information regardless of power disruptions.

You are correct that the built-in power-sense circuit in the DS3231 continuously monitors the VCC (power supply) status. This circuit actively detects power failures and seamlessly switches to the backup power supply. As a result, even during a power outage, the DS3231 IC can continue to accurately keep time without any interruptions.

To provide backup power, the module includes a battery holder located at the bottom of the board. This battery holder is specifically designed to accommodate a 20mm 3V lithium coin cell. By inserting a compatible coin cell battery into the holder, you can ensure that the DS3231 module has a backup power source to maintain accurate timekeeping even when the main power supply is interrupted.

Assuming that you utilize a fully charged 220mAh coin cell battery and manage to keep the current draw of the DS3231 chip at a minimum of 3µA, it is estimated that the battery will be capable of powering the RTC (Real-Time Clock) module for a duration of at least 8 years. This long-term power supply from the coin cell battery eliminates the requirement for an external power source, providing extended and reliable operation of the RTC without the need for frequent battery replacements.

Lab Objectives

Understand the fundamental principles and components of the Arduino Uno R3 board and DS3231 module.

Acquire and display real-time data, including date and time, from the DS3231 module using the Arduino Uno R3.

Develop programming skills by writing code to control and utilize the DS3231 module with the Arduino Uno R3, enabling precise timekeeping and alarm triggers.

Gain hands-on experience in troubleshooting and resolving common issues related to the DS3231 module and Arduino Uno R3 board.

Implement alarm functionalities using the DS3231 module, allowing for scheduled events or notifications.

Apply the knowledge gained to create practical applications, such as real-time clock displays or time-triggered actions, using the UNO R3 board and DS3231 module.

Components and Supplies

Total price:$47.46 $32.46

Pinout

# Pin Function
1 32K pin outputs a stable and accurate reference clock.
2 INT/SQW pin provides either signal.
3 SCL a serial clock pin for the I2C interface.
4 SDA a serial data pin for the I2C interface.
5 VCC provides power to the module.
6 GND ground pin.
Lonely Binary Project Pinout

Wiring

# DS3231Pin UNO R3 Pin
1 SCL A5
2 SDA A4
3 VCC 5V
4 GND GND
Lonely Binary Project Wiring

Library

Lonely Binary Github Library
cvmanjoo/RTC

The RTC library is designed to function with DS3231 on various architectures. It offers compatibility with all architectures, making it suitable for use with Arduino boards. This library enables essential functionalities such as reading and setting the clock, as well as managing alarms and timers for I2C RTCs.

Installing a library is a straightforward process that can be done swiftly. To begin, launch the Arduino IDE. Once the editor is open, direct your attention to the left column. Here, you'll notice a few icons. Locate and click on the "library" icon. Instantly, a comprehensive list of all the libraries at your disposal will materialize. You also have the option to search for a specific library. Once you've identified the desired library, simply click on the "INSTALL" button, and the installation process will commence.

Lonely Binary Arduino IDE Libaray Installation

LONELY BINARY LEARNING CENTRE

4 thoughts on “DS3231 Real Time Clock Tutorial with Arduino UNO R3

t4s-avatar
RC

Impressed by the clear and concise info! Great resouce!

July 7, 2023 at 10:26am
t4s-avatar
Alan Cui

I have learned the knowledge and learned how to operate.
Very useful!!!

July 6, 2023 at 14:02pm
t4s-avatar
Sim

Awesome information!!

July 6, 2023 at 13:52pm
t4s-avatar
Kai

Good to Learn!

July 4, 2023 at 16:34pm

Leave a comment

Your email address will not be published. Required fields are marked *

Please note, comments must be approved before they are published