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.
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.
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
Welldone..brother
ReplyDeleteKeep it up......
Thank Youπ
DeleteEpic documentation...keep it up
ReplyDeleteThank u brother π
DeleteReally great and helpful. Keep it up...
ReplyDeleteThanq brother await for more contentπ
Deleteππͺ
ReplyDeleteππππ
DeleteNice aiye..keep it up
ReplyDelete