Virtuabotixrtc.h Arduino Library Patched Info
This library natively reads and writes in 24-hour format. If you want to display 12-hour time (AM/PM), you will need to write a simple if (hours > 12) statement in your code to convert it.
For developers pushing this library further, consider forking it to add trickle charger configuration, 12-hour mode support, or hardware SPI acceleration. The simplicity of the codebase invites modification—a testament to good open-source design.
The DS1302 chip, which this library primarily supports, counts seconds, minutes, hours, date of the month, month, day of the week, and year with leap-year compensation valid up to the year 2100. It communicates via a simple 3-wire serial interface: I/O (Data Line) SCLK (Serial Clock) How to Install the virtuabotixRTC Library
An RTC is an electronic device that keeps track of the current time even when the main microcontroller (like an Arduino) is powered off. It achieves this by utilizing a small backup battery (usually a CR2032 coin cell). virtuabotixrtc.h arduino library
// Example: April 30, 2026, 14:30:00, Wednesday (dayOfWeek = 4) myRTC.setDS1302Time(00, 30, 14, 30, 4, 4, 26);
Enter the library. For many hobbyists, this is the go-to, lightweight solution for interfacing with the popular DS1302 and DS1307 RTC chips. In this comprehensive guide, we will dissect everything you need to know about this library—from installation and basic wiring to advanced coding and troubleshooting.
The library was originally in the public domain and is now primarily maintained on platforms like GitHub (chrisfryer78/ArduinoRTClibrary) . It is not always available in the built-in Arduino Library Manager, so manual installation via is often required. This library natively reads and writes in 24-hour format
: Manages seconds, minutes, and hours (including 24-hour or AM/PM formats).
Because VirtuabotixRTC.h bit-bangs the protocol, its timing is critical. The DS1302 expects SCLK periods as fast as 2.5 MHz, but bit-banging on an Arduino Uno (16 MHz) typically yields a few hundred kHz. This is sufficient for occasional reads/writes but too slow for high-frequency polling.
Once you have created an instance of the VirtuabotixRTC class, you can use its methods to set and get the date and time. It achieves this by utilizing a small backup
Here is a complete, ready-to-run sketch that displays the current date and time in the Arduino Serial Monitor:
The DS1302 module is a trickle-charge timekeeping chip containing a real-time clock/calendar and 31 bytes of static RAM. Because standard Arduino libraries like Wire.h (I2C) do not natively communicate with the DS1302's unique 3-wire synchronous serial interface, the virtuabotixRTC library was created to bridge this gap. Key Features
int lastSecond = 0; void loop() myRTC.updateTime(); if (myRTC.second != lastSecond) lastSecond = myRTC.second; // Print or process time only once per second Serial.println(myRTC.second);
