Virtuabotixrtch Arduino Library Link

The Virtuabotix RTC Library is a software wrapper designed to interface Arduino microcontrollers with Real-Time Clock (RTC) modules, specifically the popular DS1302, DS1307, and DS3231 chips often sold under the Virtuabotix brand.

While many modern RTC libraries focus solely on the high-precision DS3231, the Virtuabotix library gained popularity for its ease of use with the older, less expensive DS1302 module. It provides a simplified syntax for setting and retrieving time data without requiring the user to manipulate raw binary-coded decimal (BCD) data manually.

Let's build a practical project: an I2C LCD displaying the time and date from your RTC. virtuabotixrtch arduino library

Below is a standard implementation using the Virtuabotix library.

1. The Setup (Setting the Time) You usually only need to run the "set time" code once, or whenever the battery dies. The Virtuabotix RTC Library is a software wrapper

#include <VirtuabotixRTC.h>
// Define the connection pins: CLK, DAT, RST
// MyRTC(ClockPin, DataPin, ResetPin)
VirtuabotixRTC myRTC(6, 7, 8);
void setup() 
  Serial.begin(9600);
// Format: seconds, minutes, hours, day of week, day of month, month, year
  // Note: Day of week is usually 1-7 (e.g., 1=Monday, 7=Sunday)
// Example: Setting time to January 15, 2024, Monday, at 14:30:00
  // REMOVE THIS LINE AFTER SETTING THE TIME ONCE TO AVOID RESETTING ON REBOOT
  myRTC.setDS1302Time(00, 30, 14, 2, 15, 1, 2024);
Serial.println("Time has been set. Comment out the setDS1302Time line and re-upload.");
void loop() 
  // Nothing to do here during the setup phase

2. The Main Program (Reading the Time) Once the time is set, you upload the final code to read the time continuously.

#include <VirtuabotixRTC.h>
// Define pins
VirtuabotixRTC myRTC(6, 7, 8);
void setup() 
  Serial.begin(9600);
void loop() 
  // This function reads the current time from the module
  myRTC.updateTime();
// Print the time in a readable format
  Serial.print("Current Date/Time: ");
  Serial.print(myRTC.dayofmonth); 
  Serial.print("/");
  Serial.print(myRTC.month);
  Serial.print("/");
  Serial.print(myRTC.year);
  Serial.print(" ");
Serial.print(myRTC.hours);
  Serial.print(":");
  Serial.print(myRTC.minutes);
  Serial.print(":");
  Serial.println(myRTC.seconds);
// Wait 1 second before reading again
  delay(1000);
#include <RtcDS1302.h>
RtcDS1302<ThreeWire> Rtc(ioPin, sclkPin, cePin);

Fix: The library stores years as two-digit (0 to 99). You must manually add 2000 in your print statement: #include &lt;RtcDS1302

Serial.print(2000 + myRTC.year);

The entire library avoids malloc() and new. Every variable is statically allocated. For hardcore embedded developers, this means predictable memory usage and zero fragmentation risk—even after months of runtime.

Notice the myRTC.setDS1302Time line in the setup. You should only run this once to set the correct current time. If you leave it in your code, every time the Arduino resets (or loses power), it will reset the clock back to the hard-coded time you wrote.

The workflow is:

Now your RTC will keep ticking thanks to its battery backup!