Virtuabotixrtch Arduino Library -
// 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?
VirtuabotixRTC is a simple Arduino library for communicating with the DS1307/DS3231-style RTC modules (I2C) to read/set date and time.
// --- SETTING THE TIME (Do this only once) --- // The function: myRTC.setDS1302Time(seconds, minutes, hours, dayOfWeek, dayOfMonth, month, year) // Note: The year is a full 4-digit integer (e.g., 2026). // This line sets the time to January 1, 2026, 12:00:00 on a Thursday. myRTC.setDS1302Time(00, 00, 12, 5, 1, 1, 2026); virtuabotixrtch arduino library
# include // Creation of the RTC Object (CLK, DAT, RST) virtuabotixRTC myRTC( 6 , 7 , 8 ); void setup() Serial.begin( 9600 ); // Set time format: seconds, minutes, hours, day of week, day of month, month, year // Example: 11:30:45 on Monday, Nov 6, 2023 myRTC.setDS1302Time( 45 , 30 , 11 , 1 , 6 , 11 , 2023 ); Use code with caution. Copied to clipboard Reading and Displaying Time
void writeRAM(int address, byte data); byte readRAM(int address); void burstWriteRAM(byte* data, int len); void burstReadRAM(byte* data, int len); // Set current time: seconds, minutes, hours, day
This article provides a detailed guide to installing, utilizing, and maximizing the virtuabotixRTC library in your Arduino projects. 1. What is the virtuaBotixRTC Library?
The library typically uses three digital pins. A common configuration is: Problem with code for Arduino using an RTC - Programming // --- SETTING THE TIME (Do this only
The is a lightweight, easy-to-use software library designed to interface Arduino microcontrollers with the DS1302 Real-Time Clock (RTC) module . Originally adapted by Virtuabotix, LLC from public-domain code contributed by an Arduino community member named "Kodal," this library simplifies clock configuration, time tracking, and data extraction into a few straightforward functions.
Before programming, you must connect the five physical pins of the DS1302 breakout board to your Arduino. While you can use almost any digital pins, the standard layout used in community examples is outlined below: DS1302 Pin Arduino Pin Description 5V or 3.3V Primary Power Supply GND Ground Reference CLK / SCLK Digital Pin 6 Serial Clock Line DAT / IO Digital Pin 7 Bi-directional Data Line RST / CE Digital Pin 8 Chip Enable / Reset Pin Step-by-Step Code Implementation
// Set the current date and time myRTC.setDS1302Time(0, 0, 0, 1, 1, 2023, 0);