Make sure the RTC module is powered with 5V and has its backup battery installed, as this keeps the clock running when the main power is off.
void setup() Serial.begin(9600); Wire.begin(); myRTC.setTime(14, 30, 0); // 14:30:00 myRTC.setDate(3, 15, 4, 26); // Tuesday, 15 April 2026 (example format)
void loop() // Nothing here. Reset the Arduino after this. virtuabotixrtc.h arduino library
| Library | RTC Chip | Interface | Features | |---------|----------|-----------|----------| | VirtuabotixRTC.h | DS1302 | 3-wire bitbang | Simple, NV RAM | | RTClib (Adafruit) | DS1307, PCF8523, DS3231 | I2C | Leap year, temperature, alarms | | DS1302 (Arduino playground) | DS1302 | 3-wire | Lightweight, no RAM support |
If you are following a specific tutorial that uses this library, it works perfectly fine for basic timekeeping. However, for new projects, many experts recommend moving to the RTClib by NeiroN RtcDS1302 by Makuna Make sure the RTC module is powered with
#include // Creation of the Real Time Clock Object (CLK, IO, CE) virtuabotixRTC myRTC(6, 7, 8); void setup() Serial.begin(9600); // Set the time: (seconds, minutes, hours, day of week, day of month, month, year) myRTC.setDS1302Time(00, 59, 23, 6, 10, 1, 2024); void loop() // Update internal variables myRTC.updateTime(); // Access elements directly Serial.print(myRTC.hours); Serial.print(":"); Serial.println(myRTC.minutes); delay(1000); Use code with caution. Copied to clipboard
: The primary hardware target for this library. | Library | RTC Chip | Interface |
#include <virtuabotixRTC.h>
Once you have created an instance of the VirtuabotixRTC class, you can use its methods to set and get the date and time.
The VirtuabotixRTC.h Arduino library provides an easy-to-use interface for working with RTC modules, enabling accurate time-keeping and date-tracking capabilities in Arduino-based projects. With its simple and intuitive API, support for multiple RTC modules, and accurate time-keeping features, this library is a popular choice among Arduino developers. By following the examples and tutorials provided in this article, you can get started with using the VirtuabotixRTC.h library in your own Arduino projects.