Arduino Library | Virtuabotixrtch
Your RTC module’s battery is not connected, or the module does not have a battery holder. Fix: Most cheap modules have a diode that prevents charging. Ensure a 3V coin cell is installed.
myRTC.updateTime(); logFile.print(myRTC.hours); logFile.print(":"); logFile.print(myRTC.minutes); logFile.print(":"); logFile.println(myRTC.seconds);
| Library | RTC Chip | Advantages | |---------|----------|------------| | (Adafruit) | DS1307, DS3231, PCF8523 | Actively maintained, alarms, temperature | | DS1302 (by Matthias Hertel) | DS1302 | More robust, works on ESP32 | | RtcDS1302 (by Makuna) | DS1302 | Efficient, supports all MCUs, burst mode | | TinyRTC | DS1307 | For older TinyRTC modules |
That’s where modules come in, and the virtuabotixRTC library is one of the easiest ways to get them running. Why Use the VirtuabotixRTC Library? virtuabotixrtch arduino library
In the world of Arduino projects, keeping track of time is essential for everything from simple data loggers to complex automation systems. While the Arduino has internal timers, they are not suited for maintaining accurate, real-world time, especially when the power is turned off. This is where Real-Time Clock (RTC) modules come in, and to interact with them, we need reliable software.
// 3. Print to LCD lcd.setCursor(0, 0); lcd.print("Time: "); if(myRTC.hours < 10) lcd.print("0"); lcd.print(myRTC.hours); lcd.print(":"); if(myRTC.minutes < 10) lcd.print("0"); lcd.print(myRTC.minutes);
#include <VirtuabotixRTC.h>
VirtuabotixRTC(int cePin, int ioPin, int sclkPin);
virtuabotixRTC library is a popular choice for interfacing Arduino boards with the DS1302 Real-Time Clock (RTC)
Keeping Perfect Time: A Guide to the VirtuabotixRTC Arduino Library Your RTC module’s battery is not connected, or
#include // Include the Virtuabotix library file // Creation of the Real Time Clock Object // Pin layout: SCLK (Pin 6), IO (Pin 7), CE/Reset (Pin 8) virtuabotixRTC myRTC(6, 7, 8); void setup() Serial.begin(9600); // Open the serial port for debugging // Set the clock to a specific date and time. // Format: seconds, minutes, hours, day of the week, day of the month, month, year // Example below: 00 seconds, 30 minutes, 10 AM, Tuesday (3rd day), June 2nd, 2026 // WARNING: Uncomment the line below ONLY the first time you upload the code. // myRTC.setDS1302Time(00, 30, 10, 3, 02, 6, 2026); void loop() // Pull the latest timestamp array from the DS1302 hardware registers myRTC.updateTime(); // Print the current date variables to the Serial Monitor Serial.print("Current Date/Time: "); Serial.print(myRTC.dayofmonth); Serial.print("/"); Serial.print(myRTC.month); Serial.print("/"); Serial.print(myRTC.year); Serial.print(" "); // Format the time printing layout Serial.print(myRTC.hours); Serial.print(":"); Serial.print(myRTC.minutes); Serial.print(":"); Serial.println(myRTC.seconds); // Delay for 1 second to avoid spamming the Serial console delay(1000); Use code with caution. Critical Troubleshooting: The Reset Loop Trap
While you could attempt to measure time using Arduino functions like millis() or delay() , these methods are highly inaccurate and will reset the moment your device loses power. An RTC ensures your project maintains indefinitely. Key Features of the VirtuabotixRTC Library
: Obtain the library as a ZIP file from the ArduinoRTClibrary GitHub. While the Arduino has internal timers, they are
