How Does Work RTC(Real Time Clock) Module With Arduino

by STEAM-DIY in Circuits > Arduino

48 Views, 0 Favorites, 0 Comments

How Does Work RTC(Real Time Clock) Module With Arduino

121212.jpg

Today we will learn about the RTC module. First, let’s see what the RTC module is.RTC is a real-time clock. It is also a time-consuming electronic device. The battery in this RTC module keeps the date and time updated even when there is no external power. So we can get the exact date and time when we need it.

Let’s see what are the applications that use this RTC technology.

  1. For Server Computers.
  2. For gaming.
  3. For robotics.
  4. For GPS.

Today we are going to talk about the RTC module called DS3231. This module is designed to include the DS3231 chip. Also through this module, we can get the temperature in addition to the date and time. Here we can see six main pins. We need four of these pins. Below is what happens with these pins.

  1. VCC —> Connected to the positive.
  2. GND —> Connected to the ground.
  3. SDA —> Serial data pin
  4. SCL —> Serial clock pin.
  5. SQW —> Square wave output pin.
  6. 32K —> 32K oscillator output.

Now let us see what are the features of this RTC module.

  1. We can get the Time, Date, and Temperature.
  2. Energy consumption is low.
  3. Easy to carry.
  4. Two Time-of-day alarms.
  5. Programmable square-wave output.
  6. 400Khz I2C interface.

Well, now we will see how to use the RTC 

Supplies

Well, now we will see how to use the RTC module with Arduino. The accessories required for this are given below.

  1. Arduino Nano board x 1 — 
  2. RTC module x 1 — 
  3. Jumper wires —  
  4. Breadboard x 1 —  

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Ok, let’s do this project step by step.

First, let’s identify these components.

Then connect these components. For that use the circuit diagram below. The I2C commutation method is used to connect this RTC module to the Arduino board. If you don’t know what I2C is, read this article.

How does work RTC(Real Time Clock) module with Arduino.

Now we have to make the necessary program for this. To do this, download the RTC Library and install it on your Arduino IDE.

  1. DS3231 library — 
  2. The complete program of this project –

First, we will add the date and time to the RTC module. For that, we can use the following program.


Code

/*RTC module with Arduino.
Read the code below and use it for any of your creation
*/
#include <DS3231.h>
DS3231 rtc(SDA, SCL);
void setup() {
rtc.begin();
rtc.setTime(0, 0, 0); //(12,00,00)
rtc.setDate(0, 0, 0); //(7,9,2020)
}
void loop() {
}


Code Explanation

First, include the library and the created object. It was named “rtc”.

#include <DS3231.h>
DS3231 rtc(SDA, SCL);

Next, the RTC module is started in the Void setup. Then enter the time and date as follows.

void setup() {
rtc.begin();
rtc.setTime(12,00,00);
rtc.setDate(7,9,2020);
}


Well, we have entered the date and time in the RTC module. Now let us see the date and time of the entry in the Serial monitor. For that, use the following program.

/*RTC module with Arduino.
Serial monitor readings.
created by the SriTu Tech team.
Read the code below and use it for any of your creation
*/
#include <DS3231.h>
DS3231 rtc(SDA, SCL);
void setup() {
Serial.begin(9600);
rtc.begin();
}
void loop() {
delay(1000);
Serial.print("TIME -- ");
Serial.print(rtc.getTimeStr());
Serial.print(" DATE -- ");
Serial.println(rtc.getDateStr());
}

Code explanation

First, include the library and the created object. It was named “rtc”.

#include <DS3231.h>
DS3231 rtc(SDA, SCL);

Next, the RTC module and the serial monitor are enabled in the Void setup.

void setup() {
Serial.begin(9600);
rtc.begin();
}

Finally, the time and date are displayed on the serial monitor.

void loop() {
delay(1000);
Serial.print(“TIME — “);
Serial.print(rtc.getTimeStr());
Serial.print(” DATE — “);
Serial.println(rtc.getDateStr());
}

OK, then select the correct board and port. After, Upload this code and open the serial monitor. Now you can watch the real date and time.



OK, enjoy this tutorial. The full video guide is below. So, we hope to see you in the next project or tutorial. Have a good day.