Arduino Projects

Arduino RTC DS3231 Time and Date display on a 16×2 LCD



Arduino RTC DS3231 Time and Date display on a 16×2 LCD- In this tutorial, you will learn how to make a real-time clock using Arduino, RTC DS3231 module and a 16×2 LCD. This is my first tutorial on the RTC DS3231 real-time clock and in this tutorial, I will explain the extreme basics.

Arduino RTC DS3231

While in my upcoming tutorial I will use the same DS3231 module in the Battery efficiency monitoring system.

Arduino RTC DS3231

In this project, the battery voltage is stored in the Arduino along with the date and time information. The information which is stored in the Arduino can be requested through Bluetooth using the cell phone application. The data which is received from the Arduino is stored in the database for the post-analysis.

In this tutorial, we will cover.

  1. RTC DS3231module Pinout
  2. Complete circuit diagram explanation
  3. Programming and finally number
  4. Testing

Let’s get started!!!!

For the Step by Step Explanation watch Video Tutorial given at the end of this article.

 Amazon Purchase links :

12v Adaptor:

Arduino Uno

Arduino Nano

Mega 2560:

RTC DS3231 Real Time Clock:

16X2 LCD

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines


Please Note: these are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

RTC DS3231 Real Time Clock:

Arduino RTC DS3231

This is the RTC DS3231 module. The RTC stands for Real-Time Clock. You might be thinking why we need the RTC DS3231 module when the Arduino itself has the built-in timekeeper. Arduino is really powerful and we can make a real-time clock, but the problem comes in when the Arduino is turned off, or the power is disconnected, the time and date information is completely lost.

Arduino RTC DS3231

But if you look at the RTC DS3231 module it has a battery and can keep track of the Time and Date information even if the main power supply is disconnected or we reprogram the microcontroller.

RTC DS3231 Features:

The RTC DS3231is a low-cost, highly accurate Real Time Clock, which can maintain hours, minutes, and seconds. This module can also maintain the day, month, and year information. The RTC DS3231 module also has automatic compensation for leap years and for months with fewer than 31 days.

This Module can be powered up using 3.3 volts or 5 volts.

As you can see clearly in the picture above, the DS3231 module has a total of 6 male headers and are clearly labeled. Out of these 6 Pins, we will be using only 4 Pins which are the SCL, SDA, VCC, and GND.

16X2 LCD:

Arduino RTC DS3231

This is the 16×2 LCD, as you can see I have already soldered some jumper wires. I have a very detailed getting started tutorial on the 16×2 LCD, which covers the extreme basics like for examples, Soldering, interfacing, and basic programming.

Arduino RTC DS3231 Circuit Diagram:

Arduino RTC DS3231

This is the complete circuit diagram explaining how a 16×2 LCD and RTC DS3231 module is connected with the Arduino. This schematic is designed in Cadsoft eagle 9.1.0 version. If you want to learn how to make a schematic and PCB, then watch the tutorial.

As you can see the ground of the Arduino is connected with pin number 1, 5 and pin number 16 of the LCD…5v from the Arduino is connected with pin number 2 and pin number 15…the middle pin of the variable resistor or potentiometer is connected with pin number 3 of the LCD…while the other two pins are connected with the ground and 5v. Pin’s 4 to 7 of the Arduino are connected with pins D7 to D4 of the LCD.

Pin number 8 of the Arduino is connected with the Enable pin of the LCD.

Pin number 9 of the Arduino is connected with the Rs pin of the LCD, while the R/W pin of the LCD is connected with the Ground.

The Vcc pin of the RTC DS3231 module is connected with the 3.3 volts pin of the Arduino, while the Ground of the DS3231 module is connected with the Arduino’s Ground. The SDA and SCL pins of the RTC DS3231 Real Time Clock module are connected with the Analog pins A4 and A5 of the Arduino. The RTC DS3231 module uses the SPI Protocol.

Interfacing DS3231 and 16×2 LCD with Arduino:

Arduino RTC DS3231

RTC DS3231 module and 16×2 LCD Interfacing with the Arduino is as per the circuit diagram already explained.

Arduino RTC DS3231 Programming:

Before, you start the programming, first of all, make sure that you download all the necessary libraries.

 * Connections
 * connect SDA of the RTC with A4
 * connect SCL of the RTC with A5
#include <LiquidCrystal.h>
#include <Wire.h>
#include "RTClib.h"

RTC_DS3231 rtc;

char daysOfTheWeek[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};

int Day; 
int Month;
int Year; 
int Secs;
int Minutes;
int Hours;

String dofweek; // day of week

String myDate; 
String myTime; 

// for the 16x2 LCD

#define rs 9 
#define en 8 
#define d4 7 
#define d5 6  
#define d6 5 
#define d7 4 
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup () 
  lcd.begin(16, 2);
  delay(3000); // wait for console opening

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
  // Comment out below lines once you set the date & time.
    // Following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // Following line sets the RTC with an explicit date & time
    // for example to set January 27 2017 at 12:56 you would call:
    // rtc.adjust(DateTime(2017, 1, 27, 12, 56, 0));

void loop () 
DateTime now =;
Day =; 
Month = now.month(); 
Year = now.year();
Secs = now.second(); 
Hours = now.hour(); 
Minutes = now.minute(); 
dofweek = daysOfTheWeek[now.dayOfTheWeek()];  

myDate = myDate +dofweek+ " "+ Day + "/" + Month + "/" + Year ; 
myTime = myTime + Hours +":"+ Minutes +":" + Secs ; 
// send to serial monitor
//Print on lcd
myDate = "";   
myTime = ""; 

Download Wire library: Wire

Download RTClib library:RTClib

For the Program Explanation and practical demonstration watch the following video. Don’t forget to Subscribe. Support my YouTube channel by liking and sharing this video.

Watch Video Tutorial:

Related Article:

16×2 LCD basic examples

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...


  1. hello what is the code to make the temperature come up on lcd screen since rtc modules can read the temp.

  2. Hi, could you help me with RTC project to give alert on certain periods of time using buzzer. And it should include push buttons for setting the time and date for the period intended. Thanks and looking forward to your positive and urgent responds.

Leave a Reply

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

Back to top button