0% found this document useful (0 votes)
9 views1 page

Arduino DS3231 RTC Module Tutorial - Real Time Clock

This document provides a tutorial on interfacing the DS3231 Real Time Clock (RTC) Module with Arduino, detailing its components, pin descriptions, and circuit design. It includes code examples for setting up the RTC with an LCD display to show the current date and time. The DS3231 is highlighted for its accuracy and integrated features, making it suitable for various applications like data logging and GPS modules.

Uploaded by

Joseph Nkoa Akoa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Arduino DS3231 RTC Module Tutorial - Real Time Clock

This document provides a tutorial on interfacing the DS3231 Real Time Clock (RTC) Module with Arduino, detailing its components, pin descriptions, and circuit design. It includes code examples for setting up the RTC with an LCD display to show the current date and time. The DS3231 is highlighted for its accuracy and integrated features, making it suitable for various applications like data logging and GPS modules.

Uploaded by

Joseph Nkoa Akoa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

 

LEARN T U TO R I A L S DIY PRODUCT REVIEWS G U I D E S & H O W TO ABOUT

Home Arduino, DIY Projects

Arduino DS3231 RTC Module Tutorial


August 29, 2018 By Administrator

In this project, I will discuss about DS3231 RTC Module, important components and features of this module and nally show you how
to Interface a DS3231 Real Time Clock (RTC) Module with Arduino.

Outline 
Introduction
A Brief Note on DS3231 RTC IC
Pin Description of DS3231 IC
DS3231 RTC Module
Components and Pin of DS3231 RTC Module
Interfacing DS3231 RTC Module with Arduino
Circuit Diagram
Components Required
Circuit Design
Code
Working
Applications

Introduction
Real Time Clock or RTC is a timekeeping device in the form of an Integrated Circuit or IC. RTC is an integral component of many time
critical applications and devices like Servers, GPS, Data Loggers etc.

I have already implemented a couple of projects using Real Time Clock or RTC Module earlier with both 8051 Microcontroller and
Arduino.

With 8051, I have used DS1307 RTC Module in a project called RFID BASED CAR PARKING SYSTEM. Coming to Arduino, I have used
the same DS1307 RTC in ARDUINO ALARM CLOCK and ARDUINO REAL TIME CLOCK TUTORIAL USING DS1307. If you want a quick
reference, you can go through the provided links.

Also, in the Arduino Real Time Clock Tutorial using DS1307 project, I have talked about the need for an RTC. So, I won’t go into that
aspect again. I will directly jump into the IC of interest: the DS3231 RTC IC.

A Brief Note on DS3231 RTC IC


The DS3231 is an RTC IC developed by Maxim Integrated. It is a low cost, extremely accurate RTC IC with communication over I2C
Interface. An interesting feature of DS3231 RTC IC is that it has integrated crystal oscillator and temperature sensor and hence you
don’t have to connect an external crystal.

It is available in SO-16 Package. Although it needs only 8 pins in the available 16 pins to function, the integration of crystal makes the
IC bulkier and hence it is packed as a 16-pin IC instead of 8-pin IC.

The following image shows the Pin diagram of the DS3231 RTC IC.

Pin Description of DS3231 IC

Coming to the pin description of DS3231 IC, the following table gives a simple functionality overview of the pins.

Pin Number Pin Name Description

1 32KHz 32KHz output

2 VCC DC Power Pin

3 INT/SQW Active LOW Interrupt or Square wave output

4 RST Active LOW Reset

5 – 12 NC No Connection

13 GND Ground

14 VBAT Back-up Power Supply Input from Battery

15 SDA Serial Data I/O

16 SCL Serial Clock Input

NOTE: Pins 5-12 are NC Pins. They can be tied to GND.

DS3231 RTC Module


Using DS3231 IC as the main component, several manufacturers developed DS3231 RTC Modules with all the necessary components.
Almost all the modules available today consists of an additional IC, 24C32N (or something similar). This secondary IC is an EEPROM IC
of 32Kb size.

Since both RTC and EEPROM ICs are interfaced through I2C Protocol, you won’t need any extra pins as both these I2C Devices can act
as slaves while a microcontroller acts as a master.

The DS3231 RTC Module used in this project is shown in the image below.

Since RTC is all about maintaining time irrespective of the power supply, you can connect a 3V CR2032 Lithium Battery to the RTC IC to
keep the clock ticking. In the DS3231 Module, there is a provision for you to connect a battery using the battery holder provided on
the back.

Components and Pin of DS3231 RTC Module

As mentioned earlier, DS3231 IC and 24C32 EEPROM IC are the main components on a typical DS3231 RTC Module board. Apart from
that, there are a few other components like Power ON LED, few resistors, capacitors, a battery holder and pins for connecting with
microcontroller.

The following image shows the components and pins on the DS3231 RTC Module.

Interfacing DS3231 RTC Module with Arduino


If you remember an earlier project using MicroSD Card Adapter, I have setup a simple data logging application where the data from a
sensor is captured and stored in the microSD Card in the form of a text le.

By integrating a Real Time Clock like DS3231 to the above project, you can keep track of the data log with accurate time details.

Hence, interfacing DS3231 RTC Module with Arduino has a numerous application and advantages.

Circuit Diagram

Components Required
Arduino UNO
DS3231 RTC Module
16×2 LCD Display
Mini Breadboard
10KΩ POT
Connecting Wires

Circuit Design

First, let me begin the connections between Arduino and DS3231. Since the interface between them is I2C, identify the I2C Pins on
your Arduino Board (if you are using any other board than UNO).

In Arduino UNO, A4 and A5 are SDA and SCL pins. Connect these pins with corresponding SDA and SCL pins of the DS3231 Module.
Also, connect the VCC and GND of the RTC Module to +5V and GND of Arduino.

To view the output, I have used an LCD Module. Connect the RS and E pins of LCD to Pins 7 and 6. Connect D4-D7 of LCD to 5-2 of
Arduino.

Code
I have used a special library called “RTClib” from Adafruit (which is a forked version of JeeLab’s RTC Library). Download the library from
this link and place the extracted folder in the libraries directory of Arduino.

Since the communication is I2C, I have also used the “Wire” library. You don’t need to download this library as it is integrated with
Arduino IDE.

1 #include <Wire.h>
2 #include <LiquidCrystal.h>

3 #include "RTClib.h"
4
5 DateTime now;
6 char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};

7
8 RTC_DS3231 rtc;
9 LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // (rs, e, d4, d5, d6, d7)

10
11 void showDate(void);
12 void showTime(void);

13 void showDay(void);
14
15
16 void setup ()
17 {

18 [Link](9600);

19 [Link](16,2);
20 //delay(2000);

21 if (! [Link]())

22 {
23 [Link]("Couldn't find RTC Module");

24 while (1);

25 }
26
27 if ([Link]())
28 {

29 [Link]("RTC lost power, lets set the time!");

30 [Link](DateTime(F(__DATE__), F(__TIME__)));
31 }

32 [Link](DateTime(F(__DATE__), F(__TIME__)));

33 }
34
35 void loop ()

36 {
37 now = [Link]();

38 showDate();

39 showDay();
40 showTime();

41 }

42
43
44 void showDate()
45 {
46 [Link](0,0);

47 [Link]([Link]());
48 [Link]('/');

49 [Link]([Link]());

50 [Link]('/');
51 [Link]([Link]());

52 }

53 void showDay()
54 {

55 [Link](11,0);

56 [Link](daysOfTheWeek[[Link]()]);
57 }

58 void showTime()

59 {
60 [Link](0,1);

61 [Link]("Time:");
62 [Link]([Link]());
63 [Link](':');

64 [Link]([Link]());
65 [Link](':');

66 [Link]([Link]());

67 [Link](" ");
68 }

Arduino_DS3231_RTC_Tutorial.ino hosted with ❤ by GitHub view raw

Working
The working of the Arduino DS3231 RTC Module Interface is very easy. Arduino rst initializes the RTC Module with its slave address
(0x68 for DS3231 IC).

Arduino then updates the internal registers of the RTC IC with the date and time at which the code is compiled and uploaded to
Arduino. The uploaded date and time can be viewed on the LCD display.

If you want the DS3231 Module to keep time even after you disconnect power to Arduino, you can connect a 3V Lithium Battery.

Applications
Servers
Data Loggers
GPS Modules
Power Meters

Related Posts:
How to Connect PCF8574 I2C LCD with Arduino?
Interfacing I2C LCD with STM32F103C8T6 | STM32 I2C LCD…
Interfacing Nokia 5110 LCD with Arduino | Hookup Guide
Interfacing I2C LCD with ESP32 | ESP32 I2C LCD Tutorial
Voltage Divider Circuit
Expand Arduino's IO | Interfacing PCF8574 with Arduino

3 Responses

Lee hongshik says: September 29, 2018 at 4:38 am

I’ve teached at vocational high school. With the arduino-uno using, trying to work. I have problems making code in
the skech window.
Thanks a lot.

Reply

najiha says: October 16, 2018 at 9:55 am

i try to run this code, but it has error. Finally i realize there is [Link](); missing in void setup. i added up
[Link](); in void setup and finally i can export compiled binary for proteus simulation. and it shows exact output

Reply

najiha says: October 16, 2018 at 10:16 am

[Link](); is missing in void setup. try add it up at given codes. i’ve just found out what was missing as it shows
some error.

Reply

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

Comment *

Name *

Email *

Website

Post Comment

General Projects Projects Tutorials


Get Our Latest Newletters
Tutorials Electrical Mini projects Capacitors
Get Great Content That You Love. No Ads Or Spams, We Promise. Symbols Electronics Microcontroller Resistors
Courses Embedded Arduino Filters
Calculator Power Solar Diodes
Enter your email Sign Up Robotics Free circuits Transistors
ARM Home Automation Ampli ers
IOT Seminar Topics IO Devices
Electronics Thyristors
Questions DC Circuits
    Number System

About Advertise with us Contact

Af liate Disclosure Disclaimer Terms and Conditions Privacy Policy

Copyright © 2021 [Link]

You might also like