arduino real time clock ds3231 with lcd display factory

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

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.

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.

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.

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 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.

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.

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.

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.

The working of the Arduino DS3231 RTC Module Interface is very easy. Arduino first 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.

arduino real time clock ds3231 with lcd display factory

In today"s world, time is everything, and when it comes to specific electronics, timing is critical; just like us, humans, they also need a way to keep track of time. So how do electronics do it? The answer is DS3231, a Real-Time Clock, often known as an RTC, is a timekeeping device built into an Integrated Circuit, or IC. It is used in many time-critical applications and devices, such as servers, GPS, and data loggers. Let"s see what makes it TICK.

The DS3231 is an I2C real-time clock (RTC) with an inbuilt temperature compensated crystal oscillator (TCXO) and crystal that is both low-cost and exceptionally precise. When the module"s power is interrupted, the device has a battery input and keeps a precise time. The device"s long-term precision is improved by the inclusion of the crystal oscillator. The RTC keeps track of seconds, minutes, hours, days, dates, months, and years. For months with less than 31 days, the date at the end of the month is automatically modified, including leap year corrections. The clock has an AM/PM indication and works in either a 24-hour or 12-hour mode. Two programmable time-of-day alarms are included, as well as a programmable square-wave output. An I2C bidirectional bus is used to transport address and data serially.

The key components of a typical DS3231 RTC Module board are the DS3231 IC and the AT24C32 EEPROM IC to store the time and date data. Other components include a Power ON LED, a few resistors, capacitors, a battery holder, and pins for connecting to the microcontroller.

When the main power to the module is stopped, the DS3231 contains a battery input and maintains accurate time. The built-in power-sense circuit constantly checks the condition of VCC to identify power outages and switches to the backup supply automatically. So, even if the power goes out, your MCU will still be able to maintain track of time. On the DS3231 RTC Module, there is a CR2032 battery holder. A battery holder for a 20mm 3V lithium coin cell is located on the board"s bottom side. Any CR2032 battery will work.

The most significant difference between the DS3231 and the DS1370 is the timekeeping accuracy. For timekeeping, the DS1307 has an external 32kHz crystal oscillator, while the DS3231 has an internal oscillator.

The temperature-compensated crystal oscillator (TCXO) in the DS3231 and DS3234 fits the bill, with precision as good as ±2 ppm in temperatures ranging from 0°C to +40°C.

After making the above connections, you need to connect the Arduino UNO to your PC, open Arduino IDE, and install Arduino DS3231 Time Set Library. Open the Arduino IDE and select Library Manager from the menu bar. Now look for RTCLiband DS3231 and get the most recent version, as shown in the figure below.

You may manually set the time in this line by passing the date-time value to the function in the following order: year, month, date, hour, minute, and second. We"ll set the time of the system in the code below. As a result, we have commented out this line.

We include the below header files to the code, Wire.h to use I2C to communicate with the module, LiquidCrystal.h to show time on the LCD display, RTClib.h to set time to the display and format it.

If in case the RTC loses power and the time in the module goes wrong, the code will automatically set the time in the module and it will take the time from the computer"s clock. So make sure while setting time, the clock on your PC is set at the right time.

arduino real time clock ds3231 with lcd display factory

V3.0 - Using NodeMCU ESP8266 for controlling switches (Relay). Uses RTC (Real Time Clock - DS3231) and NTP (Network Time Protocol) for maintaining time. OLED Display (128x64) for instant updates. A webserver for Manual Controls. Vast application including Aquariums and IOT related.

arduino real time clock ds3231 with lcd display factory

…includes a very accurate temperature-compensated crystal oscillator and crystal. An optional backup battery (not included) can maintain the correct time even when power is interrupted.

arduino real time clock ds3231 with lcd display factory

The datasheet for the DS3231 explains that this part is an “Extremely Accurate I²C-Integrated RTC/TCXO/Crystal”. And, hey, it does exactly what it says on the tin! This Real Time Clock (RTC) is the most precise you can get in a small, low power package.

Most RTC’s use an external 32kHz timing crystal that is used to keep time with low current draw. And that’s all well and good, but those crystals have slight drift, particularly when the temperature changes (the temperature changes the oscillation frequency very very very slightly but it does add up!) This RTC is in a beefy package because the crystal is inside the chip! And right next to the integrated crystal is a temperature sensor. That sensor compensates for the frequency changes by adding or removing clock ticks so that the timekeeping stays on schedule.

This is the finest RTC you can get, and now we have it in a compact, breadboard-friendly breakout. With a coin cell plugged into the back, you can get years of precision timekeeping, even when main power is lost. Great for data logging and clocks, or anything where you need to really know the time.

Vcc – this is the power pin. Since the RTC can be powered from 2.3V to 5.5V power, you do not need a regulator or level shifter for 3.3V or 5V logic/power. To power the board, give it the same power as the logic level of your microcontroller – e.g. for a 5V micro like Arduino, use 5V.

Along with keeping track of the time and date, this modules also have a small EEPROM, an alarm function and the ability to generate a square-wave of various frequencies.

This modules use the I2C bus, which makes connection very easy. First you will need to identify which pins on your Arduino or compatible boards are used for the I2C bus – these will be knows as SDA (or data) and SCL (or clock). On Arduino Uno or compatible boards, these pins are A4 and A5 for data and clock:

Connecting this module is easy as header pins are installed on the board at the factory. You can simply run jumper wires again from SCL and SDA to the Arduino and again from the module’s Vcc and GND pins to your board’s 5V or 3.3.V and GND. However these are duplicated on the other side for soldering your own wires.

The function setDS3231time() is used to set the clock. Using it is very easy, simple insert the values from year down to second, and the RTC will start from that time. For example if you want to set the following date and time – Wednesday November 26, 2014 and 9:42 pm and 30 seconds – you would use:

Note that the time is set using 24-hour time, and the fourth parameter is the “day of week”. This falls between 1 and 7 which is Sunday to Saturday respectively. These parameters are byte values if you are substituting your own variables.

Once you have run the function once it’s wise to prefix it with // and upload your code again, so it will not reset the time once the power has been cycled or micrcontroller reset.

Reading the time form your RTC Is just as simple, in fact the process can be followed neatly inside the function displayTime(). You will need to define seven byte variables to store the data from the RTC, and these are then inserted in the function readDS3231time().

Then you can use the variables as you see fit, from sending the time and date to the serial monitor as the example sketch does – to converting the data into a suitable form for all sorts of output devices.

Just to check everything is working, enter the appropriate time and date into the demonstration sketch, upload it, comment out the setDS3231time() function and upload it again. Then open the serial monitor, and you should be provided with a running display of the current time and date, for example:

From this point you now have the software tools to set data to and retrieve it from your real-time clock module, and we hope you have an understanding of how to use these inexpensive and highly accurate timing modules.

arduino real time clock ds3231 with lcd display factory

Real time clocks (RTCs) like DS3231 RTC are required in applications where we need to keep track of the current time for example in data logging, clock timers and alarms.

Most microcontrollers, including the Arduino, have a built-in timer that can keep track of longer time periods like minutes or days. However, this timer only keeps track of time since the microcontroller was last powered which means that whenever the power is turned off, the timer is set back to zero!

Real time Clocks on the other hand are simply watches that keep track of date and time even when the power supply to the microcontroller is turned off because they have power backups. In this tutorial I will look at how DS3231 RTC module works and how to interface it with Arduino for keeping time.

The DS3231 RTC module comes with I/O pins on either side. These pins configuration is similar and you can use whichever side you prefer depending on the application.

The major coponent of this RTC module is the DS3231 chip which is a low-cost and extremely accurate RTC chip. It is responsible for all timekeeping functions and can easily be interfaced with any microcontroller via the I2C protocol.

The DS3231 RTC is driven by a 32kHz Temperature Compensated Crystal Oscillator (TCXO) which is packaged inside the chip. This Crystal Oscillator is highly immune to the external temperature changes that often affect oscillation frequency and this is the reason why the module is more accurate at time keeping than other RTC modules.

Right next to the integrated crystal is a temperature sensor which compensates the frequency changes by adding or removing clock ticks so that the timekeeping stays on track.

The on board 32 bytes 24C32 EEPROM chip can be used to save settings or really anything. The 24C32 EEPROM uses I2C interface for communication and shares the same I2C bus as DS3231. The I2C address of the EEPROM can be changed easily with the three A0, A1 and A2 solder jumpers at the back. Each one of these is used to hardcode in the address. If a jumper is shorted with solder, that sets the address.

There is a battery backup at bottom side of the board that holds a 20mm 3V lithium coin cell (any CR2032 battery can fit well) for maintaining accurate timekeeping when main power to the device is interrupted. So you don’t need to worry about power outages, your MCU can still keep track of time.

Before using the DS3231 rtc module, we need to first update it’s time and date settings. This is done by connecting the RTC module to an Arduino board and using already made libraries, we can be able to see the set time and date on the serial monitor.

The RTClib.h library is easy to use because it will automatically set the current date and time using the time on your computer. In case you need further reference on how to install the RTClib.h library from the Arduino IDE Library Manager you can check the link below where I describe in detail how this is done.

Then an object rtc is created from the RTC_DS3231 class which is part of the RTClib library. Also a 2D character array for storing the days of the week is defined.

In the setup section, we initialize the RTC module using the begin() method and the lostPower() method reads the DS3231 RTC’s internal I2C registers to check if the chip has lost track of time. If the function returns true, we can then set the date and time.

Note: After setting the desired time these statements should be commented out of the code sketch to avoid repetitive resetting of the time and date whenever you want to upload anew program

TimeSpan() function is used to add or subtract time to or from the current time. For example now() + TimeSpan(seconds) returns the future time with seconds added into current time.

The time and date can also be set manually using the code below. In this case we need to change the setup part of the code where the time and date are set from this line of code below.

Since both the RTC and LCD are using I2C communication then the clock (SCL) and data (SDA) lines of both modules will be connected to Arduino analog pins A5 and A4 respectively as shown below.

Finally, I’ll demonstrate how the DS3231 RTC module can be used to make a simple digital clock using Arduino and SSD1306 OLED.  Before proceeding you should know how to interface the OLED with Arduino.

The schematic of the setup is as shown below. Since both the SSD1306 OLED and the DS3231 RTC are I2C devices we just connect the corresponding pins as;

The code is almost the same as was used in the previous tutorials only that this time we add the part for the OLED. In this case the date, time and temperature will be automatically updated and displayed on the OLED.

display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)// Check your I2C address and enter it here, in Our case address is 0x3C

The display depends on the size of the OLED you are using. The above code is for a 128×32 display. You have to adjust the declaration of the width and height of the OLED and the parameters in the setCursor() function depending on the size of the display being used.

In the next setup of the DS32331 OLED clock we are going to use the memory storage capacity of the DS3231 RTC. We are going to include buttons to enable manual adjustment of the date and time which is written to the EEPROM of the RTC module. The schematic for this setup is shown below.

When this code is uploaded to the Arduino board, you can use the buttons to set the time and date which will be stored by the RTC and can keep accurately this set time even when the power supply to the microcontroller is turned off. The OLED will display the set time, date and temperature.

arduino real time clock ds3231 with lcd display factory

The Arduino is an amazing device. It’s useful for prototyping and can also be used to construct a complete project. It has an analog to digital converters (ADC), digital I/O pins, it handles interrupts and it can communicate via a serial port, SPI, and I2C.

A “real time clock” is essentially a digital clock whose output can be read by a computer or microcontroller.  It has its own oscillator that it uses to count time and it has registers that allow you to set the current time and date.

The device you are using to read this article likely has a real time clock and if you are attached to the Internet you probably are synchronizing this to a network time server (if your device is a phone it may be time synchronized to your telephone companies carrier signal instead).

Unix time is the number of seconds that have elapsed since midnight January 1, 1970 (which was a Thursday if you’re interested).  If you are on Linux (or at the terminal on a Mac, which uses Unix as its underlying operating system) you can type “date +%s” to get the current Unix time.

Unix time is useful when you are writing a program that needs to calculate the time difference between two dates and times, as it involves simple addition and subtraction, without having to worry about days, months and years.

The issue with leap seconds is generally taken care of by synchronizing your real time clock with a local or network time source, which itself will have compensated for leap seconds.

The problem with 2038 is likely to be resolved within the next 19 years, I suspect just shifting to a 64-bit standard would resolve this for several millennia!

One chip is theDS3231, a highly accurate real time clock that uses an I2C interface.  This chip has its own internal crystal oscillator, so no external crystal is required.

Another very popular chip is theDS1307. Like the DS3231 it also communicates using the I2C bus, however, this chip requires an external timing crystal.

As the Tiny RTC uses the I2C bus it is very easy to hook it up to an Arduino.  The I2C bus provides power, clock and data signals, so only four connections are required.

Before you hook up your real time clock module it would be a good idea to install the coin cell battery, if you haven’t already. That way you will ensure that the device will keep time even after you power down the Arduino.

Some Arduino clones also have separateSDAandSCLpins, usually located on the same side as the digital I/O pins above theAREFpin.  You can use these connections instead of the analog pins if you wish, they are actually just duplicates.

There are several libraries available that will work with the Tiny RTC. I’m going to use two libraries that were contributed by Paul Stoffregen, a well-known figure in the Arduino community.

The Arduino Library Manager can be also used to install two updated versions of these libraries, these were updated by Michael Margolis.  You can find them as follows:

Once you have the libraries installed open your Arduino IDE and select theFilemenu item and selectExamples. A sub-menu will appear, scroll down until you get to theExamples from Custom Librariessection.

As you might have guessed from its name theSetTimesketch sets the time on the Tiny RTC module. You’ll need to run this, or something similar, before you can use the clock.

SetTime uses two functions, getTime and getDate, to retrieve the time and date respectively from your computer clock. As most Internet-connected computers synchronize to a network time protocol (NTP) server this will probably be very accurate.

Without using a data structure the time will be reported in Unix time, which I described earlier.  ThetmElements_tdata structure breaks this down into elements like seconds, minutes, hours, days, months and years.

Otherwise, the sketch is fairly straightforward. It gets the current system time from the computer running the IDE and writes it to the DS1307 chip on the Tiny RTC module. It does all of this in the Setup section so there is no code in the loop.

Al that is left is to read those time values and print them to the serial monitor. A function calledprint2digitsis used for the hours, minutes and seconds to format the display nicely, with leading zeros for numbers below 10.

The two sketches we have just looked at illustrate how to set and read the time from the Tiny RTC module, and they accomplish this very well. But the module has an additional function, the ability to output a square wave.

You can use this square wave as a timing source for another circuit. It could be used to drive a stepper motor to create an analog clock. And, as I will show you here, it can be used to generate an interrupt for your Arduino.

To use the square wave output as an interrupt for your Arduino you will need to connect the SQ output on the Tiny RTC module to one of the interrupt pins on the Arduino.

An LED is also connected to the Arduino to indicate when an interrupt is being serviced. This is actually optional as it is connected to pin 13 and the Uno also has a built-in LED connected to that pin. If you wish you can leave it out and just monitor the LED on your Uno board.

I found a great sketch that shows how to use the square wave output, it was originally published by Robert Ulbricht on theArduino Slovakia website. Fortunately, there is an English translation available.

The functionsetSQWis really where the “action” is. This function writes to the control register in the DS1307 and sets the square wave frequency to 1Hz.

ThehandleIntfunction is the interrupt handler. Every time a pulse is received on the D2 pin it will be called.  This is set up in the Setup function using theArduino attachInterrupt function.

The previous sketch illustrated how to use the SQ square wave output from the Tiny RTC module as an interrupt. And while it does a great job of displaying interrupt operation it really doesn’t have many practical uses.

After all, there are many simpler methods of blinking an LED. In fact, if you really wanted to use the Tiny RTC to blink an LED you could just attach it directly to the SQ output, eliminating the Arduino entirely (although you’d need the Arduino to set the SQ output to 1Hz first).

Take another look at theReadTestsketch from the DS1307RTC examples. You’ll notice that it reads the time and then adds two delays that total exactly one second. It then does it all over again.

If you’re just building a clock this will work well, as every second you’ll read the time and it will have advanced one second.  But what if you want to do something else in the Loop after you read and display the time?

If the ”something else” takes less than a second then you’ll be displaying the same time more than once. On a display like an LCD or OLED this is not such a bad thing as you might never notice it, but on the serial monitor it will stand out.

If the “something else” takes more than one second you’ll miss reading the clock and it wil skip one or more seconds. You can alleviate this problem somewhat by simply not displaying seconds but still, your minutes may not change at precisely the right time.

To illustrate how to take advantage of interrupts to solve the timing problem I’m going to build a temperature and humidity meter that can also tell time.  I’m going to stick to the serial monitor for my display, but you could easily modify the code to use an OLED or LCD display.

If you wish you could modify the sketch to use the DHT22 or DHT11, I used the AM2320 because I was already using I2C for the real time clock and because I had one handy!

No matter which sensor you choose for your design you’ll encounter the same dilemma – these temperature and humidity sensors require at least two seconds between readings to stabilize.  And so if you read it in the Loop you’ll get an erratic display.

The latter library is not called directly in the sketch, instead, it is used by the AM2320 Library. Without it installed your sketch will fail to compile.

TheprintCurrentTimefunction prints the time, date, temperature and humidity to the serial monitor. It takes the temperature and humidity as an input and reads the real time clock, it then writes everything to the serial monitor.

By doing this we only read the temperature and humidity sensor every 10 seconds, which gives it plenty of time to stabilize. You can reduce this number if you wish, but don’t go below two seconds.

We then check to see if the tick count is the same as it was before. If it is then we don’t do anything. If it isn’t then it means a second has elapsed, so we callprintCurrentTimeto read the time and write everything to the serial monitor.

Load the sketch and give it a test. Note that since the temperature and humidity are only updated every 10 seconds it won’t immediately respond to a change in these values. In normal situations this shouldn’t really be an issue.

Adding a real time clock to an Arduino makes it possible to build devices that are aware of the current time and date. This can allow you to create fancy timers and delay circuits, or just build a really cool and unique digital clock.

A Real Time Clock can be added to your Arduino project in order to tell the time. Today I will show you how to use the Tiny RTC, a real time clock based upon the popular DS1307 chip.

arduino real time clock ds3231 with lcd display factory

A Real Time Clock module gives the ability for an Arduino to keep track of the current time, and be able to track time even when the device loses power. Many libraries for Clock Modules are surprisingly difficult to implement, but the one from Rinky-Dink is very easy.

Make sure to recomment out time setting code, and reupload code once clock has been set. If you do not the Arduino will reset the clock to the time you configured every time it loses power.

arduino real time clock ds3231 with lcd display factory

rtc module clock arduino rtc arduino clock clock real time arduino clock rtc ds1307 arduino clock rtc 3231 clock raspberry rtc ds3231 ds3231 rtc real time clock rtc raspberry nano shield real time clock arduino clock rtc rtc module rtc module rtc module rtc arduino adduino arduous raspberry afruit ino ds3231 raspberry clock arduino time arduino rtc module rtc module ds3231 module ds3231 module ds1307 time arduino rtc ds1307 arduino adafruit arduino i2c arduino real time modul horlog arduino horlog camera ds 3231 rtc modul ds. 3231 arduino arduino real time clock raspberry rtc arduino ds1307 azdelivery rtc clock rtc arduino arduino rtc ds3231 arduino time azdelivery real time clock ds 1307 clock ds3231 i2c clock real time clock module real time raspberry rtc ds 1307 rtc i2c module clock arduino ds1 307 module rtc ds1307 pi rtc rtc 1307 ds3231 at24c32 clock rtc raspberry module time arduino arduino rtc clock ds3231 and battery horlog arduino azdelivery arduino rtc module arduino ds1307 arduino arduino arduino clock module ds1307 rtc rtc clock DS3231 rtc module

arduino real time clock ds3231 with lcd display factory

In this Arduino Tutorial we will learn how to use the DS3231 Real Time Clock Module. You can watch the following video or read the written tutorial below.

The first question that comes here is why we actually need a separate RTC for our Arduino Project when the Arduino itself has built-in timekeeper. Well the point is that the RTC module runs on a battery and can keep track of the time even if we reprogram the microcontroller or disconnect the main power.

The DS3231 is a low-cost, highly accurate Real Time Clock which can maintain hours, minutes and seconds, as well as, day, month and year information. Also, it has automatic compensation for leap-years and for months with fewer than 31 days.

Once we connect the module we need to program the Arduino Board to work with the Real Time Clock. However, when it comes to programing a communication between Arduino and an I2C module the code isn’t that small and easy. Luckily, there are already several libraries for the DS3231 RTC which can be found on the internet.

So once we download and install the library we can use its first demo example to initially activate the clock of the RTC module. In the setup section of the demo example code we can notice that there are three line that we need to uncomment in order to initially set the day of the week, the time and the data.

The first line is for setting the day of the week, the second line is for setting the time in hours, minutes and seconds, and the third line is for setting the date in days, months and years.

Now even if we disconnect the Arduino power and then reconnect it and run the Serial Monitor again we can notice that the time keeps going without being reset.

So now we have our Real Time Clock up and running and we can use in any Arduino Project. As a second example I connected an LCD to the Arduino and printed the time and the date on it.

arduino real time clock ds3231 with lcd display factory

DS3231 RTC is a Precise Real-Time Clock Module with a 32Kbit EEPROM and a built-in 10-bit temperature sensor having a resolution of 0.25C. The DS3231 RTC module Precise Real-Time Clock Module is a low-cost, extremely accurate I²C real-time clock (RTC) with an integrated temperature-compensated crystal oscillator (TCXO) and crystal. The device incorporates a battery input and maintains accurate timekeeping when the main power to the device is interrupted. The integration of the crystal resonator enhances the long-term accuracy of the device as well as reduces the piece-part count in a manufacturing line. The ds3231 Arduino is available in commercial and industrial temperature ranges and is offered in a 16-pin, 300-mil SO package.

arduino real time clock ds3231 with lcd display factory

We try our best to reach each and every corner of India using a few of the best courier services running in the Country such as Delhivery, DTDC, BlueDart, XpressBees, Ecom Express, etc. as per the feedback for the courier partner at the customer"s location. A few of the interior parts of India which are not covered by these courier services are covered by India-Post by us. We apply our best effort on daily basis to dispatch the order the same day it is ordered or within the next 24 hours of the order placed. Most of the orders that are placed before 1 PM are dispatched and shipped the same day. The orders placed post that is scheduled for next day shipment. The same effort is applied throughout the week including weekdays and sometimes weekends and public holidays as well. We facilitate local pickup (self-pickup for the local customers) on the weekdays and partially on weekends also.

arduino real time clock ds3231 with lcd display factory

In this tutorial, we will interface DS3231 RTC Real Time Clock module with Arduino which is used to get current time. We will display RTC values on an OLED. We will build a Real Time Clock (RTC) with the help of DS3231 module, Arduino and OLED display. A real time clock is basically a digital clock which is responsible for keeping track of accurate time in terms of hours, minutes, seconds, months, days and sometimes even years. They are helpful and used in situations where low power mode is used. There are many RTCs available in the market such as DS3221 and DS1307 which usually consist of a controller, oscillator, and an embedded quartz crystal resonator. In this user guide, we will focus on DS3231 RTC module and program it with Arduino in Arduino IDE to create a Real Time Clock.

The DS3231 precision RTC module is one of the most commonly used RTC module which keeps track of the current data and time. It is used in electronics projects for time keeping, data logging, building clocks, timers etc. This module runs on the DS3231S RTC chip and also contains the AT24C32 EEPRROM for accurate time keeping. It has a very accurate real time clock which houses an integrated temperature compensated crystal oscillator and crystal. Additionally, due to the presence of the crystal resonator, the DS3231 module gives more accurate time keeping results in the long run.

One of the interesting features of this RTC module is that it consists of a CR2032 battery holder where a 20mm 3V Lithium coin cell is inserted. Therefore, even if the power supply to the module is cut off, it will still keep track of the data and time. Once the timekeeping is started, it will always be maintained.

The DS3231 is a low cost RTC module that communicates with the microcontroller using I2C communication protocol. Let us look at the pinout of the DS3231 precision RTC module.

As mentioned previously, the DS3231 module uses I2C communication protocol to communicate with the microcontroller. The SSD1306 OLED that we are using also has an I2C interface. Hence, we will use the same I2C pins of Arduino to connect with both the RTC module and the OLED.

The OLED display and the RTC module both require an operating voltage in the range of 3.3-5V hence we will connect the VCC terminal with 3.3V which will be in common with the Arduino board. SCL of the display and the RTC module will be connected with the SCL pin of Arduino. Likewise, the SDA of the display and RTC module will be connected with the SDA of Arduino. The ground of all the devices will be held common.

As we are using DS3231 RTC module with Arduino, hence we will require a library while programming in Arduino IDE. We will use the RTClib by Adafruit which is a great Arduino RTC library tested for DS3231 Precision RTC, PCF8523 RTC and DS1307 RTC. Open this link which opens the GitHub page for the RTClib library. Head over to Code > Download ZIP and download the zip file.

Now open Arduino IDE and go to Sketch > Include Library > Add .ZIP library and select the zip file that you just downloaded. This adds the library to your IDE.

To use the OLED display in our project, we have to install the Adafruit SSD 1306 library and Adafruit GFX library in Arduino IDE. Follow the steps below to successfully install them.

We will start off by including the necessary libraries for this project. Wire.h will allow us to communicate through the I2C protocol. Whereas the OLED libraries are the ones which we previously installed and are required for the proper functionality of the OLED display. The RTClib.h will help us access functions to build the RTC.

Then, we will initialize the OLED display by creating an object of Adafruit_SSD1306 and specifying the width, height, I2C instance (&Wire), and -1 as parameters inside it.’ -1′ specifies that the OLED display which we are using does not have a RESET pin. If you are using the RESET pin then specify the GPIO through which you are connecting it with your development board.

Moreover, we will also initialize the OLED display and the RTC module by using display.begin() and rtc.begin() respectively. Make sure you specify the correct address of your OLED display. In our case, it is 0X3C.

First, we will set the size of the text using setTextSize() and pass the size as a parameter inside it. Next, we will control the color of the text by using the setTextColor() function and passing WHITE as an argument. We will use the setCursor() function to denote the x and the y axis position from where the text should start. Then we print the text ‘RTC CLOCK’ on the display for 5 seconds using display.print().

Then, we display the time in HH:MM:SS along with the day, date, month and year on the OLED. This is achieved by first clearing the display, setting the text size, setting the cursor position and then printing the text using display.println().

To see the demonstration of the above code, upload the code to Arduino. But, before uploading code, make sure to select the Arduino board from Tools> Boardand also select the correct COM port to which the Arduino board is connected from Tools> Port.

The following figure depicts the 2d model of the DS3231 Real-Time Module. It shows us the physical dimensions required when a PCB card is designed.about:blank