Skip to main content

Arduino Real Time Clock Module DS3231

Arduino Real Time Clock Module DS3231

We all know most of the microcontrollers can measure time in milliseconds and perform tasks timely, But what if all of a sudden the power is lost even though if the power is back again all the times will be reset. Also most of the MCUs are unaware of the around them in this case the DS3231 Real time module will come in handy.

           1 - Will provide a stable reference clock value
           2 - This pin can be used as a interrupt.
           3 - This line carries the serial clock signal(Serial Clock).
           4 - This line will transmit and receive serial data(Serial Data).
           5 - 3.3V-5V power input.
           6 - Ground pin.

Real Time Module to Arduino uno Connection

SCl------------------------>Arduino SCL
SDL----------------------->Arduino SDL
VCC----------------------->Arduino 5V
GND----------------------->Arduino Ground

Code Segment to Set DAY,TIME,DATE

First of all we will need to set the current time hence the module is shipped from the factory without the battery the time is reset. So to set the time the following code is uploaded just once.
we need to edit the Date Of the Week, Time and the date.

void setup()
{
  // Setup Serial connection
  Serial.begin(115200);
  
  // Initialize the rtc object
  rtc.begin();
  
  // The following lines can be uncommented to set the date and time
  rtc.setDOW(ENTER CURRENT DATE OF THE WEEK);     // Set Day-of-Week to SUNDAY
  rtc.setTime(ENTER CURRENT TIME);     // Set the time to 12:00:00 (24hr format)
  rtc.setDate(ENTER CURRENT DATE);   // Set the date to January 1st, 2014
}
void loop(){
  }

Once this code is uploaded the the module stores the data in the EEPROM, We have to comment back the three lines. Just like the following code

void setup()
{
  // Setup Serial connection
  Serial.begin(115200);
  
  
  // Initialize the rtc object
  rtc.begin();
  
  // The following lines can be uncommented to set the date and time
  //rtc.setDOW(DAY);     // Set Day-of-Week to SUNDAY
  //rtc.setTime(TIME);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(DATE);   // Set the date to January 1st, 2014
}
void loop(){
  
  void loop()
{
  // Send the current Day-of-Week
  Serial.print(rtc.getDOWStr());
  Serial.print("///");
  
  // Send current date
  Serial.print(rtc.getDateStr());
  Serial.print("///");
  // Send time
  Serial.println(rtc.getTimeStr());
  
  //stays 5 seconds
  delay (5000);
}

And that's it we have successfully setup the DS3231 Real Time Module. Just feel free to ask and clarify any doubts in the comment section below


Comments

Post a Comment

Popular posts from this blog

Rain Drop Sensor Module

Arduino Rain Drop Sensor Module Rainfall is an important factor for some advanced as well as some simple projects such as a automatic irrigation system, Rainfall intensity detection system, auto rain sensing wipers and various other projects. Rain drop sensor module has Nickel strips laid parallel to each other. Since water is a conductor it reduces the resistance and the voltage drop between two parallel Nickel strips. This principle is basically used to sense the presence of Water.   1 -  Outputs a analog voltage relative to the amount of rainfall   2 -  Digital output (HIGH or LOW)   3 - Ground pin   4 - 5V Power input Rain drop sensor  to Arduino Uno Connections           Analog Out ------------------------->Analog Pin A0 Of Arduino Uno           Digital Out-------------------------->Digital Pin 2 Of Arduino Uno           5V--------------------...