RTC Basic
RTC DS3231 Arduino Using Library RinkyDink – RTC is the main component of timing, whether it is used on wall clocks, computers, cellphones, watches, servers, gps, power meters and others. All information on digital devices that take time, generally using RTC.
But why should we use RTC as timing? Can’t we make a manual program by using delay as a 1 second delay?
The answer is that first, RTC has a high degree of precision in timing calculations. Both RTCs have consistent timings that don’t have to be reset when a device’s power suddenly goes out.
If you use Arduino, by taking advantage of the delay for a 1 second delay, when suddenly the Arduino power goes out, the Arduino starts the time from 0 again. Not very good for Timing.
One of the most widely used RTC is the DS3231. Base on datasheet, This RTC made by MAXIM INTEGRATED has a Real time feature to count seconds, minutes, hours, date, month and year valid up to 2100.
- Accuracy ±2 ppm from 0°C to +40°C
- Accuracy ±3.5ppm from -40°C to +85°C
- Accuracy Digital temperature sensor output ±3°C
- I2C communication (400kHz)
- Battery backup voltage 3.3V
Library DS3231
To operate this RTC using Arduino, we need a library, friends. Many have made a library for this RTC DS3231.
In this article, I only use a library made by Henning Karlsen, the owner of the RinkyDinkElectronics.com site.
If you want to see the website, please click here. Download the Arduino DS3231 RTC library below:
Download Libary DS3231 Rinky Dink
If you have, enter the Library DS3231 library that you have downloaded to the Arduino IDE by:
- Open Arduino IDE
- Click Sketch > Include Library > Add .ZIP Library
- Look for the DS3231.zip Library that friends have downloaded
- Click OK
Arduino DS3231 Circuit
Make the Arduino DS3231 RTC circuit as shown below:

Get Data Program Code
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);
String day, Monday;
void setup()
{
Serial.begin(115200);
//uncomment while if using Arduino leonardo
//while (!Serial) {}
rtc.begin();
}
void loop()
{
if (rtc.getDOWStr() == "Monday") {
day = "Monday";
}
if (rtc.getDOWStr() == "Tuesday") {
day = "Tuesday";
}
if (rtc.getDOWStr() == "Wednesday") {
day = "Wednesday";
}
if (rtc.getDOWStr() == "Thursday") {
day = "Thursday";
}
if (rtc.getDOWStr() == "Friday") {
day = "Friday";
}
if (rtc.getDOWStr() == "Saturday") {
day = "Saturday";
}
else if (rtc.getDOWStr() == "Sunday") {
day = "Sunday";
}
// Show the day
Serial.print(day);
Serial.print(" ");
// Show the date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Show the tie
Serial.println(rtc.getTimeStr());
delay (1000);
}
Then open the serial monitor on the Arduino IDE. The result will look like in the image below.

Set the time as you wish
In the picture above, the data obtained is Sunday, the 1st of the 1st month of 2000. The hour is 1 minute. But how do we organize the data according to the current time?
For example, let’s set it on Wednesday, the 13th of the 3rd month of 2019. And 14 o’clock at the time this article was written. The trick is to use the following command:
rtc.setDOW(WEDNESDAY); // rtc.setDOW(hari) for set the day
rtc.setTime(0, 0, 0); // rtc.setTime(hour,minute,second for set 24 mode
rtc.setDate(0, 0, 0); // rtc.setDate(date,month, year) set the date
An example of the program is as follows:
#include <DS3231.h>
DS3231 rtc(SDA, SCL);
String day, Monday;
void setup()
{
Serial.begin(115200);
//uncomment while if using Arduino leonardo
//while (!Serial) {}
rtc.begin();
rtc.setDOW(WEDNESDAY); // rtc.setDOW(hari) for set the day
rtc.setTime(14, 0, 0); // rtc.setTime(hour,minute,second)
rtc.setDate(13, 3, 2019); // rtc.setDate(date,month,year)
}
void loop()
{
if (rtc.getDOWStr() == "Monday") {
day = "Monday";
}
if (rtc.getDOWStr() == "Tuesday") {
day = "Tuesday";
}
if (rtc.getDOWStr() == "Wednesday") {
day = "Wednesday";
}
if (rtc.getDOWStr() == "Thursday") {
day = "Thursday";
}
if (rtc.getDOWStr() == "Friday") {
day = "Friday";
}
if (rtc.getDOWStr() == "Saturday") {
day = "Saturday";
}
else if (rtc.getDOWStr() == "Sunday") {
day = "Sunday";
}
// Show the day
Serial.print(day);
Serial.print(" ");
// Show the date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Show the time
Serial.println(rtc.getTimeStr());
delay (1000);
}
Then the results that appear as in the image below:

That’s a tutorial on how to use the Arduino DS3231 RTC, if you have any questions, suggestions, please write them in the comments column. Happy learning, happy working.
If you want to try the adafruit RTClib library, I’ve made a tutorial and the program code. You can read the article How to Use the Arduino RTC DS3231 Using the Adafruit Library.
Thank you for visiting Chip Piko’s website. Hope this is useful.