RTC DS3231 Arduino tutorial

How to Use RTC DS3231 Pinout Arduino

Posted on

Use RTC DS3231 Pinout Arduino – RTC is the main component of timing, used on wall clocks, computers, mobile phones, watches, servers, gps, power meters and others. All information on digital devices that require time, generally uses RTC. But why do we have to use RTC? Can’t we make a manual program by using delay as a 1 second delay? The answer is the first, RTC has a precision level of time calculation. Second RTCs have a consistent time setting that does not have to be reset when the electrical power of a device suddenly down. If you use Arduino, by using delay 1 second, when suddenly the Arduino resource down, Arduino starts from 0 again. It’s not good to make timings.

DS3231 RTC Modul Datasheet

One of the most widely used RTCs is DS3231. Based on the datasheet, this MAXIM INTEGRATED RTC has features:

  • Real time to count seconds, minutes, hours, dates, months and years is valid until 2100.
  • Accuracy of ± 2ppm from 0 ° C to + 40 ° C
  • Accuracy of ± 3.5ppm from -40 ° C to + 85 ° C
  • Digital temperature sensor output accuracy ± 3 ° C
  • I2C Communication (400kHz)
  • 3.3V battery backup voltage

 

DS3231 Arduino Library

To operate this RTC using Arduino, we need a library. Many have created library for RTC DS3231. In this article I only use the library made by Henning Karlsen, the owner of the site RinkyDinkElectronics.com. If you want to see the website, please click here. Download the Arduino RTC DS3231 library below:

Download Libary DS3231

Enter the DS3231 library that you have downloaded to the Arduino IDE using this steps:

  • Open the Arduino IDE
  • Click Sketch > Include Library > Add. ZIP Library
  • Search for the DS3231.zip Library that you have downloaded
  • Click OK

DS3231 Pinout Schematic

DS3231 module have 6 pin, but we just using 4 pin. DS3231 pinout is I2C Communication. Make a schematic of Arduino DS3231 RTC as shown below:

Read other articles  Arduino RC522 RFID TUTORIAL

RTC DS3231 Arduino tutorial

 

Read Data From RTC DS3231

The following is a basic program that can display the day, date and time. Please upload the program below.

#include <DS3231.h>

DS3231  rtc(SDA, SCL);

void setup()
{
  Serial.begin(115200);

  rtc.begin();
}

void loop()
{
  // Show day of the week
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");
  
  // Date date
  Serial.print(rtc.getDateStr());
  Serial.print(" -- ");

  // Show time
  Serial.println(rtc.getTimeStr());
  
  delay (1000);
}

Then open the serial monitor on the Arduino IDE. The results will appear as shown below.

rtc arduino datasheet

 

Set the time as desired

In the picture above, data was obtained on Sunday, on the 26th, on the 12th of month, in 2000. While at 7:00, 9 minutes. However, how do you set the current time? For example, we set it on Wednesday, the 13th of the 3rd month of 2019. At the time this article was created.

Use the following command:

rtc.setDOW(WEDNESDAY);  // rtc.setDOW(day) for set day of the week
rtc.setTime(0, 0, 0);   // rtc.setTime(hour,minute,seconds) for set time in format 24
rtc.setDate(0, 0, 0);   // rtc.setDate(date,month,year) for set date

For example the program is below:

#include <DS3231.h>

DS3231  rtc(SDA, SCL);

void setup()
{
  Serial.begin(115200);

  rtc.begin();

  rtc.setDOW(WEDNESDAY);  // rtc.setDOW(day) for set day of the week
  rtc.setTime(10, 0, 0);   // rtc.setTime(hour,minute,seconds) for set time in format 24
  rtc.setDate(13, 3, 2019);   // rtc.setDate(date,month,year) for set date

}

void loop()
{
  // Show day of the week
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");

  // Date date
  Serial.print(rtc.getDateStr());
  Serial.print(" -- ");

  // Show time
  Serial.println(rtc.getTimeStr());

  delay (1000);
}

Then the results appear as shown below:

rtc arduino ds3231 turorial

2 thoughts on “How to Use RTC DS3231 Pinout Arduino

  1. Hello there, My name is Aly and I would like to know if you would have any interest to have your website here at hamboelektronik.com promoted as a resource on our blog alychidesign.com ?

    We are updating our do-follow broken link resources to include current and up to date resources for our readers. If you may be interested in being included as a resource on our blog, please let me know.

    Thanks, Aly

Leave a Reply

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