void setup() Serial.begin(9600); Wire.begin(); // Optionally set time once: // myRTC.setTime(14, 30, 0); // hh, mm, ss // myRTC.setDate(9, 4, 2026); // dd, mm, yyyy or yy depending on library version
A more complex usage was in an Arduino-based biometric attendance system using a fingerprint sensor. The virtuabotixRTC library provided the essential timestamping capability, marking the exact time a user's fingerprint was scanned for attendance records.
void setup() Serial.begin(9600); lcd.init(); lcd.backlight();
#include // Construct: virtuabotixRTC(CLK, DATA, RST) virtuabotixRTC myRTC(6, 7, 8); Use code with caution. 2. Setting the Time (Once) virtuabotixrtch arduino library
While there are multiple RTC libraries available in the Arduino ecosystem, stands out for a few major reasons:
#include <VirtuabotixRTC.h>
void setup() Serial.begin(9600); // Initialize serial communication void setup() Serial
myRTC.updateTime(); // Crucial: Call this before reading any time values // Access variables directly Serial.print(myRTC.hours); Serial.print(":"); Serial.println(myRTC.minutes); // Or get a formatted string Serial.println(myRTC.gettime()); Use code with caution. 5. Practical Example: Serial Clock
// Set current time: seconds, minutes, hours, day of week, day of month, month, year // myRTC.setDS1302Time(00, 30, 10, 2, 14, 4, 2026); loop() { myRTC.updateTime(); Serial.print( "Current Time: " ); Serial.print(myRTC.hours); Serial.print( ); Serial.print(myRTC.minutes); Serial.print( ); Serial.println(myRTC.seconds); delay( Use code with caution. Copied to clipboard or a code for a custom alarm system using this library?
To keep the RTC running without Arduino power. 📥 How to Install the VirtuabotixRTC Library Practical Example: Serial Clock // Set current time:
The core of the library is the setDS1302Time function. For your reference, here are the specifics of its parameters:
: Providing direct access to individual time variables (e.g., myRTC.hours myRTC.seconds ) for display or logic. Basic Wiring Setup
// Wait 1 second before reading again delay(1000);
| Feature | VirtuabotixRTC | Adafruit RTClib | | :--- | :--- | :--- | | | ~3KB Flash, low RAM | ~7KB+ Flash | | Ease of Use | Very easy (Int variables) | Moderate (DateTime object) | | Timestamp support | No (manual conversion) | Yes (unixtime) | | Alarm features (DS3231) | No | Yes | | Temperature reading | No | Yes (DS3231 only) | | Best for | Beginners, small MCUs | Complex dataloggers |
// *** IMPORTANT: Uncomment the line below to initially set the time *** // Format: seconds, minutes, hours, dayOfWeek, dayOfMonth, month, year // myRTC.setDS1302Time(0, 15, 14, 4, 13, 10, 2023); // *** After uploading this sketch, comment out the above line and upload again ***