How does work RTC(Real Time Clock) module with Arduino.
Hello guys, welcome back to my “SriTu Hobby” blog. 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.
- For Server Computers.
- For gaming.
- For robotics.
- 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.
- VCC —> Connected to the positive.
- GND —> Connected to the ground.
- SDA —> Serial data pin
- SCL —> Serial clock pin.
- SQW —> Square wave output pin.
- 32K —> 32K oscillator output.
Now let us see what are the features of this RTC module.
- We can get the Time, Date, and Temperature.
- Energy consumption is low.
- Easy to carry.
- Two Time-of-day alarms.
- Programmable square-wave output.
- 400Khz I2C interface.
Well, now we will see how to use the RTC module with Arduino. The accessories required for this are given below.
- Arduino Nano board x 1 — Our Store / Amazon
- RTC module x 1 — Our Store / Amazon
- Jumper wires — Our Store / Amazon
- Breadboard x 1 — Our Store / Amazon
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.
Step 1
First, let’s identify these components.
Step 2
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.
Step 3
Now we have to make the necessary program for this. To do this, download the RTC Library and install it on your Arduino IDE.
First, we will add the date and time to the RTC module. For that, we can use the following program.
/*RTC module with Arduino.
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() {
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);
}
Now let us Upload this program to the Arduino Board.
Step 4
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.
(adsbygoogle = window.adsbygoogle || []).push({});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.
How does work RTC(Real Time Clock) module with Arduino.