Virtuabotixrtc.h Arduino Library
Let's tie everything together with a practical project. This code will turn on an LED (or relay) at a specific time.
#include <virtuabotixRTC.h>virtuabotixRTC myRTC(7, 6, 5); int alarmPin = 13; // Built-in LED bool alarmTriggered = false;
int alarmHour = 7; int alarmMinute = 0;
void setup() pinMode(alarmPin, OUTPUT); digitalWrite(alarmPin, LOW); Serial.begin(9600);
void loop() myRTC.updateTime();
// Check if current time matches alarm time if (!alarmTriggered && myRTC.hours == alarmHour && myRTC.minutes == alarmMinute && myRTC.seconds == 0)
digitalWrite(alarmPin, HIGH); alarmTriggered = true; Serial.println("ALARM! Time to wake up!");// Reset alarm at midnight (optional) if (myRTC.hours == 0 && myRTC.minutes == 0 && myRTC.seconds == 0) alarmTriggered = false; digitalWrite(alarmPin, LOW);
delay(500);
Once upon a time in the digital world of Arduino, there was a tiny, ticking heartbeat known as the DS1302 Real-Time Clock
. For a long time, this little chip felt misunderstood; it spoke in complex pulses and data shifts that many beginner makers found difficult to decode. Then came a specialized "translator" named virtuabotixRTC.h The Arrival of the Translator virtuabotixRTC.h
library was created to act as the ultimate bridge. Before it arrived, programmers had to manually toggle pins and calculate binary codes just to find out if it was Tuesday. But with this library, everything changed. All a maker had to do was call its name at the start of their code: #include
The library gave the DS1302 a set of clear instructions. It mapped out the three vital connections—CLK, DAT, and RST—usually to digital pins 6, 7, and 8. Problem with code for Arduino using an RTC - Programming
This tiny board usually has 5 pins:
Behind these pins lies the DS1302 chip, a 32.768 kHz crystal, and a small battery (usually a CR2032). This battery keeps the clock running when the main Arduino power is off.
The VirtuabotixRTC library is a fit-for-purpose, minimalist solution for using the DS1302 RTC with Arduino. It is recommended for:
It is not recommended for:
For projects needing better accuracy, the RTClib with a DS3231 is vastly superior. However, for simplicity and cost, virtuabotixrtc.h remains a valid choice for the DS1302. Let's tie everything together with a practical project
Report compiled: April 11, 2026
Library version referenced: 1.0.0 (as available in Arduino Library Manager)
If you are looking to add real-time clock (RTC) functionality to your Arduino project without the headache of complex I2C communication, the VirtuabotixRTC.h library is a fantastic, lightweight solution.
Designed primarily to interface with the common DS1302 RTC module, this library uses a simple 3-wire interface, making it incredibly easy to track time, log data, and schedule events.
The library includes private methods like readByte(), writeByte(), readRegister(), and writeRegister() that implement the DS1302’s bit-level protocol:
This bit-banging approach makes the library work on any pin, but also makes it slower than hardware-accelerated protocols.
Instead of reading the RTC every 1000ms (which uses updateTime() many times), read changes only when the second changes. void loop()
myRTC
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);