Skip to Content
This is the Beta version of our new Learning Paths approach. Please email feedback.

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 NamePurpose
Arduino NanoThis will be the microcontroller
DS3231 RTCThe will the real time clock

Circuit Diagram

Nano RTC Fritzing

Connections

Nano PinDS3231 RTC Pin
A4SDA
A5SCL
5VVCC
GNDGND

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); }