arduino with a ds1307 rtc and lcd display in stock

Hi, and welcome to this tutorial, it’s about another RTC (Real Time Clock) module, it’s the DS1307, previously I did a tutorial about the DS1302, and a project where I set it up using a keypad, then an Alarm Clock project based on that module, I also did a tutorial about the DS3132.
But today we’re about the DS1307, and I’m gonna use it with Arduino UNO board and I’ll also use a LCD i²c screen and OLED display, to show time and date in different formats.
“The DS1307 serial real-time clock (RTC) is a lowpower, full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially through an I2C, bidirectional bus. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year.”
OLED libraries: – Download here Adafruit OLED SSD1306 library – Download here Adafruit GFX Library
Important !! First time you must wire the module and upload the “SetTime” example, it sets the module to the compiling time of the code which is technically your real time and date.
N.B: If you are testing the module with multiple things it’s better to close the “SetTime” example, open it again and upload to the board, otherwise your module will be programmed with the first time the “SetTime” example was compiled, and you may think that your module doesn’t work well !!

you can use the basic structure of this project. We have already made various Arduino projects, Embedded projects, and Arduino tutorials on our website. You can visit them if you are new to the world of electronics and Arduino.
to display the time. You can make an Automatic pet Feeder, Automatic Light, time-based plant watering system, and much more using this. This reduces the manual stress on us.
the module is capable of counting seconds, minutes, hours, days, weeks, months, and years. Arduino uses the I2C communication protocol to send data to the LCD display,
which we are using here to display the time. The display updates every second to tell the most accurate time since the module is much accurate to tell the time.
The module is capable of running for more than 5 years continuously without affecting the count in time. this is possible because of the in-built cell.
the most professional PCB manufacturer for prototyping and low-volume production to work with in the world. With more than a decade in the field, PCBWAY committed to meeting the needs of customers from different industries in terms of quality, delivery, cost-effectiveness, and any other demanding requests. As one of the most experienced PCB manufacturers and SMT Assemblers in China, we pride ourselves to be your best business partners as well as good friends in every aspect of your PCB needs. They strive to make your R&D work easy and hassle-free.
NOTE- You need to install the three libraries LiquidCrystal_I2C.h, Wire.h, and DS1307.hwhich can be downloaded from HERE into your Arduino IDE before uploading the code.
Once the uploading of code is complete, LCD Display will be able to show the Time as per the code uploaded. I hope you found this guide helpful in making the project. If you have any doubts, you can put them in the comment section below.

We are all aware that most MCUs used in our projects are time-agnostic; that is, they are unaware of the time around them. It’s fine for most of our projects, but every now and then, when you come across an idea where keeping time is critical, the DS1307 precision RTC module comes in handy. It is suitable for a wide range of projects, including clocks, timers, and alarms, as well as data logging and time stamping.
This module is built around the highly capable DS1307 RTC chip and the AT24C32 EEPROM, both of which have been around for a while and have good library support.
At the heart of the module is a low-cost, extremely accurate RTC chip from Maxim — the DS1307. It handles all timekeeping functions and communicates with the microcontroller over I2C.
The DS1307 can keep track of seconds, minutes, hours, days, dates, months, and years. It can work in either a 12-hour or 24-hour format and has an AM/PM indicator. For months with fewer than 31 days, it automatically adjusts the date at the end of the month, including leap year corrections (valid up to 2100).
Another interesting feature of the DS1307 is the SQW pin, which can be programmed to output one of four square-wave frequencies: 1Hz, 4kHz, 8kHz, or 32kHz.
The DS1307 requires an external 32kHz crystal for timekeeping, the frequency of which is easily affected by external temperature. Even though this change in frequency is negligible, it does add up.
The built-in power-sense circuit continuously monitors the status of VCC to detect power failures and automatically switches to the backup supply. This means that even in the event of a power outage, the IC can still keep time.
Assuming you use a fully charged 47mAh coin cell battery and keep the chip current draw to a minimum of 300nA, the battery should be able to power the RTC for at least 17 years without the need for an external power supply.
The DS1307 RTC module also includes a 32-byte (4K x 8-bits) AT24C32 EEPROM (non-volatile) chip with 1,000,000 write cycles. This chip doesn’t really have anything to do with the RTC, but it can be useful for things like data logging or storing any other data that you want to be non-volatile.
The AT24C32 EEPROM is rated for 1,000,000 write cycles, so it won’t wear out during normal data logging applications as long as you’re not writing data every second.
After installing the DS18B20, you will be able to obtain temperature readings from the DS pin. These readings can be used to compensate for temperature-based time drift.
The module has a simple I2C interface that takes up two addresses. The DS1307 RTC chip’s fixed I2C address is 0x68, and the 24C32 EEPROM’s fixed I2C address is 0x50.
The SDA and SCL signals, as well as power and ground, are also broken out to the other side of the module to allow these signals to be looped out to another module.
DS pin should provide temperature readings if a DS18B20 temperature sensor is installed using the three mounting holes in the upper right corner, close to the battery holder (marked U1).
BAT is a backup supply input for any standard 3V lithium cell or other energy source to keep accurate time when the device’s main power is interrupted.
Now we are left with the pins that are used for I2C communication. Note that each Arduino board has different I2C pins that must be connected correctly. On Arduino boards with the R3 layout, the SDA (data line) and SCL (clock line) are on the pin headers close to the AREF pin. They are also referred to as A5 (SCL) and A4 (SDA).
It takes a lot of effort to communicate with an RTC module. Fortunately, the uRTCLib library was created to hide all of the complexities, allowing us to issue simple commands to read the RTC data.
To install the library, navigate to Sketch > Include Library > Manage Libraries… Wait for the Library Manager to download the library index and update the list of installed libraries.
At the end of the tutorial, we’ve also included code for reading and writing the onboard 24C32 EEPROM. If you’re interested, you’ll need to install the uEEPROMLib library. Look for ‘ueepromlib‘ and install it as well.
The sketch begins by including the Arduino.h and uRTCLib.h libraries for communicating with the module. We then create an uRTCLib library object and define the daysOfTheWeek 2D character array to store the days information.
set(ss, mm, hh, day, dd, mm, yy) function sets the RTC to an explicit date and time. For example, to set January 13, 2022 at 12:56, you would call: rtc.set(0, 56, 12, 5, 13, 1, 22);
dayOfWeek() function returns the current day of the week (1 to 7). This function is typically used as an index for a 2D character array that stores information about the days.
As an added bonus, the DS1307 RTC module includes 32 bytes of Electrically Erasable ROM. Its contents will not be erased even if the device’s main power is interrupted.
This is a simple sketch that attempts to write an integer, float, character, and string to the 24C32 EEPROM and then reads them back. This sketch can be extended to save settings, passwords, or just about anything.
When reading/writing the EEPROM, keep in mind that different data types take up different amounts of memory. For example, a character is one byte, an integer is two bytes, and a float is four bytes.
However, if you are storing an integer, you must reserve two memory locations for each value, so you will want to store data in every other memory location, such as (0,2,4,6….).

In this project I have created a digital clock. we can watch the current date and time on the lcd display this project uses DS1307 based RTC module to to maintain the time and date value.
this module is build around DS1307 chip which is a real time clock that means we can get hour, second, minutes, day, date, month and year value fromitthis module require external power source so that it can power the module during power failure so if we remove the power supply of our clock it would not lost its time for this we uses a 3V li-ion battery this module support I2C (two wire interface) to talk to master device Like Arduino in this case once we store the current time value of second hour minute day date month and year into their corresponding registers and and then ds1307 maintains the time and updates the register values to know more about ds1307 you can have a look at he datasheet ds1307 stores the data in BCD(binary coded decimal) format
to display time and date I have used used 16*2 lcd because it is easy to control it by Arduino in comparison to 7 segment display we can interface with lcd by the help of LiquidCrystal library of arduino
these resistors are necessary for I2C interface because I2C devices have open collector configuration these pullup resistors pull the SDA and SCL line high

I was trying to use your code to display the same date & time as my monitor on my LCD 16x2. It mostly works, but instead of displaying 14:05, maybe 07:05, it respectively displays 14:5 & 7:5 or 70:5. How to solve this?
Hi Sharon, Thanks for your comment. This is a basic circuit and the Alarm functionality is not available for the moment. I am planning to build a complete one later. For now please see this link [https://goo.gl/9p15MV] I think this link has an example code for you.
Hi I don"t know what I am doing wrong but I get this error when I compile the code in the Arduino IDE: "RTClib.h:5: error: redefinition of "RTC_DS1307 RTC""

Time is vital in today"s society, and when it comes to certain electronics, timing is crucial; just like us, they require a means to keep track of time, and precise time. So, how do electronics accomplish this? A Real-Time Clock, or RTC, is a timekeeping device embedded inside an Integrated Circuit, or IC. The answer is DS1307. Many time-critical applications and devices rely on it, including servers, GPS, and data loggers.
The DS1307 is a battery-backed clock/calendar with 56 bytes of SRAM. The clock/calendar displays data in seconds, minutes, hours, days, dates, months, and years. Each month"s end date is automatically changed, particularly for months with fewer than 31 days.
They come in the form of integrated circuits (ICs) that control time like a clock and date like a calendar. The key advantage of RTC is that it has a battery backup system that keeps the clock/calendar working even if the power goes out. The RTC requires a tiny amount of electricity to stay active. These RTCs may be found in various applications, including embedded devices and computer motherboards.
DS If your module has a DS18B20 temperature sensor fitted immediately next to the battery holder, the pin is designed to output temperature information (labeled as U1).
BAT is a backup supply input for any standard 3V lithium battery or another energy source that allows the gadget to keep a precise time when the primary power is lost.
The DS1307 RTC module includes all onboard components necessary for the proper operation of a DS3107 chip. Furthermore, it has a holder for a 20mm 3V lithium coin battery. Any CR2032 battery can be used in this module. Let"s go through each of the module"s components one by one. The DS1307 keeps track of the seconds, minutes, hours, days, and months. This chip resets its seconds, minutes, hours, and date at the end of every month. Time can be displayed in 12-hour format with AM and PM or in 24-hour format.
The DS1307 chip requires a 32KHz external crystal oscillator to function (time-keeping). As a result, the RTC module has a 32KHz external crystal oscillator. However, there is one issue with this 32KHz crystal oscillator: changes in ambient temperature alter the crystal oscillator"s oscillation frequency. The difference in the external crystal oscillation frequency of 32KHz is insignificant. However, in the long term, it is a mistake. It causes a monthly clock drift of 2-3 minutes.
The DS1307 RTC module also has a 24C32 EEPROM onboard. This EEPROM has a 32-byte capacity and only allows for regional read-write operations. Using an RTC module for Alarm-based projects may leverage this memory to save time. For example, we wish to wake up every day at 8:00 a.m. We may record this time value in EEPROM, and an alarm will sound anytime the time equals the saved value.
These EEPROM chips use the I2C interface to connect with microcontrollers like Arduino. As a result, it uses the same I2C bus as the DS1307. To communicate with EEPROM (o 0x50 Hex) and DS1307 chip on the same I2C bus, different slave addresses are set to them.
A holder for connecting a CR2032 coil cell may be found on the rear side of an RTC module. This backup battery is intended to preserve precise time even if the primary power supply attached to the DS1307 fails. This chip has a power sensor circuit that detects main power and switches to the backup coil cell when main power is lost.
An external DS18B20 digital temperature sensor can be connected to an empty slot on this module. The three empty pinouts in the bottom right corner serve as a placeholder for the DS18B20 sensor, whose output may be received through the RTC module"s DS pin.
After making the above connections, you need to connect the Arduino Uno to your PC, open Arduino IDE, and install Arduino DS1307 Time Set Library. Open the Arduino IDE and select Library Manager from the menu bar. Now look for RTCLib and get the most recent version, as shown in the figure below.
You may manually set the time on this line by giving the following date-time values to the function: year, month, day, hour, minute, and second. In the code below, we"ll set the system"s time. As a result, this line has been commented out.
Wire.h is used to connect with the module via I2C, LiquidCrystal_I2C.h is used to show time on the LCD display, and RTClib.h is used to set and format the time on the display.
If the RTC loses power and the time in the module becomes incorrect, the code will automatically adjust the time in the module using the computer"s clock. So make sure the clock on your computer is set to the correct time when setting the time.
The only difference between the DS3231 and the DS1307 is that the DS3231 has a temperature compensated crystal built-in, which makes it more precise, but the chip is also considerably bigger. They share the same I2C address, thus libraries designed for the DS1307 should also function for the DS3231.
The address byte starts with the 7-bit DS1307 address, which is 1101000, and then the *direction bit (R/W), which is a 0 for a write. The device produces an acknowledge on the SDA line after receiving and decoding the address byte.
The 32-kHz clock is used to run the RTC. There are fixed-length seconds and one variable-length second for each hour. There are 3599 seconds of constant length. The 32-kHz clock ticks precisely 32,768 times per second.

In this tutorial, we will learn to interface DS1307 RTC module with Arduino UNO. Firstly, we will look into these questions: What is RTC (Real-time clock)? Why real-time clock is used? How an RTC module communicates with Arduino on an I2C communication bus? How to make a digital clock using Arduino and DS1307 RTC module? Secondly, we will discuss pinout, pin configuration details, interfacing circuit with Arduino, and example code at the end.
Before going further into this article, you should have a basic knowledge of Arduino programming and how to use Arduino IDE. You should know how to interface LCD with Arduino and how to use the input/ output ports of Arduino. If you don’t know how to do these things, we recommend you to go through the following articles to get a better understanding of this articles:
As its name suggests, a real-time clock is used to keep a record of the time and to display time. It is used in many digital electronic devices like computers, digital smartwatches, data loggers, and situations where you need to keep track of time. one of the great benefits of a real-time clock is that it also keeps a record of time even if the power supply is not available.
Now the question is how can an electronic device like real-time clockwork without the use of a power supply. Because almost all RTC modules come with small coin size 20mm 3V lithium coin cells which can work for years. Usually, CR2032 coil cells are used.
At the center of the DS1307 RTC module is an 8-pin DS1307 chip. It provides a real-time clock that is used to keep track of seconds, minutes, hours, days, months, and years. It uses the I2C communication protocol for communicating with other devices like in our case we are using Arduino. Arduino reads values of time and date from DS1307 using the I2C communication protocol. Moreover, it also has a feature to keep a record of the exact time in case of power failure with the help of a backup battery. It is used to make a real-time clock using some other electronic components.
VBAT: Connect a CR2032 coil cell as backup power. Its value should be between 3-5 volt. voltage more than 5 volts may burn DS1307 permanently. A backup battery is used to keep track of time in case of power failure.
SQW pin provides square waves of different frequencies such as 1Hz, 4kHz, 8kHz, or 32kHz. The frequency of output wave can be selected by sending a signal to DS1307 over an I2C bus.
If you want to use this IC directly with Arduino, you need to use external components to connect with DS1307. The following circuit diagram shows the connections of all required components with DS1306:
DS1307 RTC module has all onboard components which are required for the correct functionality of a DS3107 chip. On top of that, it contains a holder to connect a 20mm 3V lithium coin cell. This holder can contain any CR2032 battery. Now let’s discuss the components of this module one by one.
At the center of the DS1307 RTC module is a chip which we have discussed earlier. This chip keeps track of seconds, minutes, hours, days, and months. At the end of every month, this chip automatically adjusts its seconds, minutes, hours, and date. It is also possible to configure time display in 12-hour with an AM and PM or 24-hour format.
As discussed earlier, the DS1307 chip requires 32KHz of an external crystal oscillator for its operation (time-keeping). Therefore, the RTC module comes with 32KHz of an external crystal oscillator.
But there is one problem with this 32KHz crystal oscillator that is a change in environmental temperature affects the oscillation frequency of the crystal oscillator. This change in 32KHz of external crystal oscillation frequency is negligible. But it shows an error in the long run. It gives a clock drift of 2-3 minutes per month.
DS1307 RTC module also contains onboard 24C32 EEPROM. This EEPROM can store 32 bytes and have limited read-write operations. We can use this memory to save time when we want to use an RTC module for Alarm based projects. For example, we want to set an alarm at 8:00 AM every day. We can save this time value into EEPROM and whenever the time matches with this saved value, an alarm starts.
These EEPROM chips also communicate with microcontrollers or Arduino over the I2C bus. Hence, it shares the same I2C bus as DS1307. Different slave addresses are assigned to EEPROM (o 0x50 Hex) and DS1307 chip to communicate with them on the same I2C bus.
On the back side of a RTC module, there is a holder to connect the CR2032 coil cell. This backup battery is used to keep track of time accuracy even when the main power source which is connected to DS1307 fails. This chip contains a power sensing circuitry which senses the main power and whenever the main power shutdown, it switches to the backup coil cell.
In backup mode, DS1307 consumes only 300nA current. That means a backup battery based on a coin cell can work for more than 17 years. Because, generally, the capacity of CR2032 battery is 47mAh and chip consumes only 300nA when powers through a battery.
There is an empty slot available on this module to connect an external DS18B20 digital thermometer. The three empty pinouts in the bottom right corner is a place holder for the DS18B20 sensor and output of the sensor can be received from DS pin of RTC module.
The following figure shows the pinout diagram. This module exposes a total of 7 pins out of which two are power supply pins and two are for SCL and SDA pins for the I2C communication bus. We have already seen the functionality of all these pins in the previous sections.
But it demands an exercise to write code from scratch. Luckily, an Arduino RTCliblibrary is available, which implements callback functions to get time measurements from an RTC module. This library hides all the complexity to interact with an RTC module over I2C communication. We can use simple callback functions implemented by RTClib to read data from DS1307.
To apply this library, first, we need to install this library in Arduino IDE by going to Arduino’s library manager. Open Arduino IDE, go to Tools > Manage Libraries.
After that, this window library manager window will appear. Search for “RTClib” by typing in the search bar. You will see many options for DS1307. But the one that we will use in this tutorial is RTClib by Adafruit. Select RTClib by Adafruit and click on the install button.
When you click on the install button, you may get a message that RTClib may require other libraries dependencies which is currently not installed in your Arduino IDE. We recommend you to install all dependencies by clicking on install button. Otherwise, RTClib will not work properly.
In your Arduino IDE, open up the serial monitor and set the baud rate to 115200. The serial monitor will start displaying the current date and time along with future date and time and time since midnight of 1/1/1970.
In this section, we will see a proteus simulation of DS1307 RTC module by using all external components and display the value of time and data on 16×2 LCD.
The following circuit shows the connections of DS1307chip along with external components with an Arduino. SCL and SDA pins of DS1307 are connected with SCL and SDA pins of Arduino. If you have already gone through the above-mentioned article on LCD interfacing with Arduino and other basic articles to get a know-how of Arduino, you can easily understand the following circuit.

In the Arduino Real Time Clock Tutorial, we will learn about Real Time Clock (RTC) and how Arduino and Real Time Clock IC DS1307 are interfaced as a time keeping device. If you recall, we have already implemented an Arduino Alarm Clock using RTC DS1307 in an earlier project.
But that project didn’t cover the basics of Real Time Clock or RTC, the specifications of DS1307 RTC IC and how to interface a Real Time Clock like DS1307 or DS3231 with Arduino.
An RTC or Real Time Clock is a Timekeeping device, usually in the form of an Integrated Circuit (IC). An RTC is battery powered and keeps track of the current time even when there is no power.
Real Time Clock ICs are present in computers, servers, many embedded systems and in fact they are used wherever it is required to keep an accurate time.
Even though Arduino and almost all microcontrollers have built-in timers and timekeepers (millis () in case of Arduino), they are power dependent i.e. they run as long as there is power supply. Once the power is turned off (manually or due to power outage), all the timers are reset to 0.
While timekeeping using internal timers is acceptable for simple projects, we need an alternative in projects like data loggers, clocks, alarms, etc. where the timer runs independently irrespective of the external power or if the Microcontroller (or Arduino) is reprogrammed.
Here comes the use of Real Time Clock ICs. Almost all RTC ICs are low-current devices that run for years on a single lithium cell (usually CR2032). One of the popular and most commonly used RTC ICs is the DS1307 Real Time Clock.
The DS1307 RTC is a low cost, low power real time clock IC that can maintain full clock and calendar i.e. hours, minutes, seconds as well as year, month and day. Some of the well-known features of the popular DS1307 RTC are mentioned below.
DS1307 RTC is available as modules, which consists of all the necessary components like Battery, connectors, pull-up resistors and crystal. One such module is used in this project and is shown below.
The following image shows the pin diagram of the DS1307 RTC IC. In order to reduce the power consumption, the number of pins on the IC has to be reduced. Hence, DS1307 RTC used I2C Communication.
X1 and X2: These are pins for connecting the crystal of frequency 32.768 KHz to enable the internal oscillator. If an external oscillator is connected to X1, then X2 can be left floating.
Now that we have seen a little bit about the Real Time Clock IC DS1307, we will proceed with the interface of Arduino and Real Time Clock. As mentioned earlier, the DS1307 RTC Module uses I2C Communication.
In the Arduino Real Time Clock I2C interface, the Arduino Microcontroller always acts as Master and the DS1307 acts as Slave. The Master in I2C Communication i.e. Arduino in this case, is responsible for clock signal, bus access, start and stop signals.
The following image shows the circuit diagram of the Arduino Real Time Clock DS1307 Interface. This circuit explains just the basic connections with respect to a DS1307 Module (a board that contains the DS1307 IC along with the crystal, Battery and pullup resistors).
In order to understand better about the DS1307 RTC Module, the following image will help you as it contains the circuit of a typical DS1307 Real Time Clock Module.
The design of the Arduino RTC Interface is quite straight forward. Connect the SDA and SCL pins of the DS1307 RTC to the SDA and SCL pins of Arduino i.e. pins A4 and A5.
A simple project where Arduino UNO is interfaced with DS1307 Real Time Clock is implemented here. In this project, we will be programming the DS1307 RTC with current date and time and see whether it actually keeps that data even if the power supply to Arduino is removed.
A special library called “RTClib” is used in the programming and it can be downloaded from this link. Make sure that it is downloaded first and added to the Arduino library database.
In order to upload the data and time into the DS1307 RTC IC, we have used a feature available in the RTClib library, where the Arduino will upload the date and time from the computer while uploading the code.

This post shows a simple real time clock and calendar example using an Arduino UNO board and DS1307 RTC chip where time and calendar are displayed on 1602 LCD screen and it can be set with two push buttons.
The DS1307 is an IC (integrated circuit) which has only 8 pins, it’s low cost, easy to use and it has the ability to count time and date in real time (more details are in the datasheet).
In the circuit there are 2 push buttons (B1 & B2) connected to pins 8 and 9 respectively, the two push buttons are used to set time date parameters (minutes, hours, date, month and year). Button B1 selects the parameter and B2 increments the selected parameter.
Arduino real time clock with DS1307 code:The Arduino code below doesn’t use any library for the DS1307 RTC, the Wire library is for the communication between the Arduino and the DS1307 using I2C protocol.
void blink_parameter() : this small function works as a delay except that it is interrupted by the buttons B1 (connected to pin 8) and B2 (connected to pin 9). When called and without pressing any button the total time is 10 x 25ms = 250ms. With this function we can see the blinking of the selected parameter with a frequency of 2Hz. So a delay of 250ms comes after the print of the selected parameter and after that delay a 2 spaces is printed which makes the parameter disappears from the LCD and another 250ms delay comes after the print of the 2 spaces.
Downloads:To be able to simulate this example, Proteus needs the Arduino library which can be downloaded from the link below. After extracting the files (ARDUINO.IDX and ARDUINO.LIB) put it in the Library folder (ex: C:\Program Files\Labcenter Electronics\Proteus 8 Professional\LIBRARY):

Upload the below code to set time and date.Uploading this code will load the time and date to RTC from your computer.After uploading the code open serial monitor to see the time and date.
Don"t use latest version of arduino IDE for programming.If you use latest arduino IDE, you cannot set time and date in RTC.You also need to add some libraries if you use latest IDE.I found problem with the latest arduino IDE.I strongly recommend to use arduino 1.6.1 IDE version.If you use this version you no need to add libraries because all the libraries were inbuilt in this version.I have also attached the libraries for latest arduino IDE users.

TheReal Time Clock (RTC) is an time tracking device in the form of integrated Circuit with battery backup which is used to keep the data records with respect to current time. The RTC device keep running with the help of battery backup even there shut down at microcontroller device or Power failure.
We have seen many tutorials earlier for interfacing RTC DS1307 with Arduino , ESP32 boards, PIC microcontroller using Proteus Simulation tools. In this tutorial we will interface real hardware of RTC DS1307 with Arduino UNO board.
The RTC DS1307 serial real-time clock (RTC) is a low power, full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially through an I2C, bidirectional bus. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with AM/PM indicator. The DS1307 has a built-in power-sense circuit that detects power failures and automatically switches to the backup supply. Timekeeping operation continues operates from the backup supply.
The chip maintains seconds, minutes, hours, day, date, month, and year information. The date at the end of the month is automatically adjusted for months with fewer than 31 days, including corrections for leap year (valid up to 2100).
The built-in power-sense circuit continuously monitors the status of VCC to detect power failures and automatically switches to the backup supply. So, you need not worry about power outages, your MCU can still keep track of time.
The bottom side of the board holds a battery holder for 20mm 3V lithium coincells. Any CR2032 battery can fit well. Assuming a fully charged CR2032 battery with capacity 47mAh is used and chip consumes its minimum 300nA, the battery can keep the RTC running for a minimum of 17.87 years without an external 5V power supply.
DS1307 RTC module also comes with a 32 bytes 24C32 EEPROM chip from Atmel having limited read-write cycles. It can be used to save settings or really anything. The 24C32 EEPROM uses I2C interface for communication and shares the same I2C bus as DS1307.
Connections for Standard 32.768kHz Quartz Crystal. The internal oscillator circuitry is designed for operation with a crystal having a specified load capacitance (CL) of 12.5pF. X1 is the input to the oscillator and can optionally be connected to an external 32.768kHz oscillator. The output of the internal oscillator, X2, is floated if an external oscillator is connected to X1.
Backup Supply Input for Any Standard 3V Lithium Cell or Other Energy Source. Battery voltage must be held between the minimum and maximum limits for proper operation. Diodes in series between the battery and the VBAT pin may prevent proper operation. If a backup supply is not required, VBAT must be grounded. The nominal power-fail trip point (VPF) voltage at which access to the RTC and user RAM is denied is set by the internal circuitry as 1.25 x VBAT nominal. A lithium battery with 48mAh or greater will back up the DS1307 for more than 10 years in the absence of power at +25°C.
Serial Data Input/Output. SDA is the data input/output for the I2C serial interface. The SDA pin is open drain and requires an external pullup resistor. The pullup voltage can be up to 5.5V regardless of the voltage on VCC.
Serial Clock Input. SCL is the clock input for the I2C interface and is used to synchronize data movement on the serial interface. The pullup voltage can be up to 5.5V regardless of the voltage on VCC.
Square Wave/Output Driver. When enabled, the SQWE bit set to 1, the SQW/OUT pin outputs one of four square-wave frequencies (1Hz, 4kHz, 8kHz, 32kHz). The SQW/OUT pin is open drain and requires an external pullup resistor. QW/OUT operates with either VCC or VBAT applied. The pullup voltage can be up to 5.5V regardless of the voltage on VCC. If not used, this pin can be left floating.
Primary Power Supply. When voltage is applied within normal limits, the device is fully accessible and data can be written and read. When a backup supply is connected to the device and VCC is below VTP, read and writes are inhibited. However, the timekeeping function continues unaffected by the lower input voltage.
Interfacing RTC DS1307 is very easy as this module module supporting to I2C two wire protocol. Also the connection 16×2 LCD display with Arduino made easy using I2C module. To getting data and writing a data for this two devices we have configure I2C address correctly. Please refer my earlier tutorials for how to find or scan the the i2C address using Arduino IDC.
After interfacing and connecting all necessary connection as per circuit diagram let’s prepare Arduino Sketch. To run the RTC with Arduino IDE this project we nee to include RTC DS1307 library . Open new files and copy the below code and upload it to Arduino Board.
With this user guide, we have seen how we can interface the RTC module with Arduino and can be configured as real time clock monitoring device with the help of LCD display.

By continuing to use AliExpress you accept our use of cookies (view more on our Privacy Policy). You can adjust your Cookie Preferences at the bottom of this page.

To calculate the overall star rating and percentage breakdown by star, we don’t use a simple average. Instead, our system considers things like how recent a review is and if the reviewer bought the item on Amazon. It also analyzed reviews to verify trustworthiness.

Sometimes it may be necessary to use a display while making a hardware project, but the size and the type of the display may vary according to the application. In a previous project, we used a 0.96″ I2C OLED display, and in this project we will have an I2C 20×4 character display.
This liquid crystal display has 4 lines, 20 character in each line and cannot be used to display graphics. The main feature of this display that it uses I2C interface, which means that you will need only two wires to connect with Arduino. At the back side of the screen there is a small PCB soldered in the display, this circuit is a serial LCD 20 x 4 module and it also has a small trimpot to adjust the contrast of the LCD.
Display’s backlight is blue and the text is white. It is fully compatible with Arduino and has 5V input voltage. Its I2C address could be 0x27 or 0x3F. You can get it for about $7 from Bangood store.
DS3231 is a low-cost, accurate I2C real-time clock (RTC), with an integrated temperature-compensated crystal oscillator (TCXO) and crystal. The device incorporates a battery input, so that if power is disconnected it maintains accurate time.
RTC maintains seconds, minutes, hours, day, date, month, and year information. Less than 31 days of the month, the end date will be automatically adjusted, including corrections for leap year. The clock operates in either the 24 hours or band / AM / PM indication of the 12-hour format. Provides two configurable alarm clock and a calendar can be set to a square wave output. Address and data are transferred serially through an I2C bidirectional bus.
This RTC module operates at input voltage range between 3.3V and 5.5V, so it can be connected with 3.3V or 5V pins. It is available on Banggood store for about $2.
First we need to download the library of the display, which includes all required functions to configure and write on the display. You can find it here.
Unzip the library and add it to the Arduino libraries folder, then run Arduino IDE and copy the following code. The first two lines are to include both of I2C and LCD libraries.
lcd.setCursor(3,0) will set the cursor of the LCD in the specified location, the first argument for the column and the second for the row starting form 0.
Here we will use a small breadboard to connect the RTC module and display with the Arduino’s I2C pins (A4 and A5). The SCL pins are connected with analog 5 pin and the SDA pins with analog 6 pin. The top rail of the breadboard used as I2C bus and the bottom one is power bus.
In addition to setup and loop function, we will create four other functions to organize the code. As the corners and vertical lines of the frame are special characters, we have to create them manually. So we will use a function to create them and another one to print them on the LCD.
Inside the loop function the time will be read from the real time clock module and the printed to the LCD using a custom function for each of time and date.
At first, we have to include the three libraries, I2C, LCD, and RTC and set the LCD address. Inside the setup function the display is initialized, then we will call createCustomCharacters() function and print them.
Each character can be 5-pixel long in width and 8-pixel in height. So to create a custom character we need to create a new byte. We need 5 characters, the vertical line and the four corners. The yellow pattern shows you how the character will be displayed on the LCD.
Inside createCustomCharacters() function, we called lcd.createChar(#, byte array) function. The LCD supports up to 8 custom characters numbered from 0 to 7. It will assign the index in the first argument to the character given by the byte array. To print this character we can use lcd.write(byte(#)) function.
This function is very simple, it uses lcd.setCursor(#,#) to move the cursor and lcd.print(“”) to print the given string. The function will print the top and bottom horizontal lines, then printing other custom characters.
As we discussed earlier, the loop function will get the current time and date every second and refresh them on the display. First we defined a time element “tm” which has current time data, then if the time is correct and the RTC module working fine the time and date will be printed.
We can add some instructions so, if the DS1307 is stopped or there is a circuit error,we can light a LED to indicate the problem. The loop will wait for 1 second before starting the next iteration.
PrintTime function uses three arguments, the column and line where it will print the time, and the time element. lcd.print(tm.Hour) will print the hour, then if the minutes and seconds are less than 10 we will add 0 to the left. And the same method is used to print the date.
Now everything is ready, upload the code to your Arduino and enjoy watching your new clock. You can find the full Arduino sketches and libraries in the attachment below.
Ms.Josey
Ms.Josey