Arduino Library High Quality — Virtuabotixrtch
The ability to have accurate time opens up a world of project possibilities. Here are just a few examples of what you can build with the VirtuabotixRTC library:
The virtuabotixRTC library abstracts away the low-level bit-shifting and SPI-like register adjustments required to communicate with the DS1302. Instead, it exposes an object-oriented class structure with readable parameters.
The DS1302 module has 5 pins. Use the following typical connection for an Arduino Uno: DS1302 Pin Arduino Pin (Example) Description Power supply GND CLK / SCLK Serial Clock DAT / I/O Bidirectional Data RST / CE Reset / Chip Enable 3. Basic Code Guide
Uses a 3-wire connection (SCLK, I/O, and CE/RST) rather than standard I2C or SPI. Individual Data Access: Allows users to easily access specific time elements like dayofmonth as individual variables. Persistent Timekeeping: virtuabotixrtch arduino library
– Works beautifully with DS1307 and DS3231. Not tested with newer PCF8523 or RV-3028.
The VirtuabotixRTCH library offers a range of features that make it an ideal choice for Arduino users. Some of the key features include:
// Print the current time and date Serial.print("Current Time: "); Serial.print(hours); Serial.print(":"); Serial.print(minutes); Serial.print(":"); Serial.println(seconds); Serial.print("Current Date: "); Serial.print(month); Serial.print("/"); Serial.print(day); Serial.print("/"); Serial.println(year); The ability to have accurate time opens up
The VirtuabotixRTC library is an Arduino library created to interface with the . It handles the unique 3-wire communication protocol, allowing you to set, read, and write time/date data to the chip.
#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
Serial.println("--------"); delay(1000); The DS1302 module has 5 pins
// Create an instance of the VirtuabotixRTC class VirtuabotixRTC myRTC(rtcClockPin, rtcDataPin, rtcRstPin);
Call updateTime() inside loop() to sync variables with the chip. Problem with code for Arduino using an RTC - Programming
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