Real Time Clock
This project reads value of the current date and time from the RTC module and prints it to the serial monitor.
Components
Component Name | Purpose |
---|---|
Arduino Nano | This will be the microcontroller |
DS3231 RTC | The will the real time clock |
Circuit Diagram

Connections
Nano Pin | DS3231 RTC Pin |
---|---|
A4 | SDA |
A5 | SCL |
5V | VCC |
GND | GND |
Code
real_time_clock.ino
/*
Project: Real time clock.
Project Description:
This module maintains real time for circuits and has a battery to retain the time even when they are powered off.
Author: STEMVentor Educonsulting
This code is copyrighted. Please do not reuse or share for any purpose other than for learning with subscribed STEMVentor programs. This code is for educational purposes only and is not for production use.
*/
// LIBRARIES
// RTCLib by NeiroN
#include <RTClib.h>
// PIN DEFINTIONS
// CONSTANT DEFINITIONS
// GLOBAL VARIABLES
DS3231 rtc;
char dateString[32];
char timeString[32];
// INITIALIZE OBJECTS
// LOCAL FUNCTIONS
// THE setup FUNCTION RUNS ONCE WHEN YOU PRESS RESET OR POWER THE BOARD.
void setup() {
// Start the serial communication with baud rate suitable for your components.
Serial.begin(9600);
rtcSetup();
Serial.println("The RTC module is ready!");
}
void readRTCValue()
{
DateTime now = rtc.now();
sprintf(dateString, "%02d/%02d/%02d", now.day(), now.month(), now.year());
sprintf(timeString, "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
Serial.println(dateString);
Serial.println(timeeString);
}
// THE loop FUNCTION RUNS OVER AND OVER AGAIN FOREVER UNTIL THE BOARD IS POWERED OFF.
void loop() {
readRTCValue();
delay(1000);
}