Library - Virtuabotixrtc.h Arduino
if (myRTC.hours > 12) displayHour = myRTC.hours - 12; ampm = "PM"; else if (myRTC.hours == 0) displayHour = 12; ampm = "AM"; else if (myRTC.hours == 12) ampm = "PM";
The DS1302 RTC module typically has 5 pins. Because the library allows you to define your pins in the code, you can use almost any digital pins on your Arduino Uno, Nano, or Mega. Here is the standard wiring schematic: DS1302 Pin Description Arduino Pin (Example) Power Supply (3.3V or 5V) GND CLK / SCLK Serial Clock Digital Pin 6 DAT / I/O Serial Data Digital Pin 7 RST / CE Reset / Chip Enable Digital Pin 8
: Typically includes VCC, GND, CLK (Clock), DAT (Data), and RST (Reset) pins. virtuabotixrtc.h arduino library
#include <virtuabotixRTC.h>
This tiny board usually has 5 pins:
If you are using a bare DS1302 chip rather than a pre-assembled module, ensure you have the required 32.768 kHz crystal oscillator and a backup battery (typically a CR2032) installed. The backup battery is crucial for maintaining timekeeping when the main Arduino power is disconnected.
delay(500); // Update display twice a second if (myRTC
VirtuabotixRTC(int clk, int dat, int rst);
The library was written by an entity known as , a brand associated with DIY electronics kits and tutorials. Unlike the more ubiquitous DS1307 or DS3231 chips, which communicate via I2C, the DS1302 uses a 3-wire synchronous serial interface . This means it requires three dedicated I/O pins (CE/Enable, I/O Data, and SCLK) instead of the shared SDA/SCL lines of I2C. The VirtuabotixRTC.h library abstracts away the low-level bit-banging and timing requirements of this 3-wire protocol, allowing developers to focus on reading and writing time rather than managing serial communication details. #include <virtuabotixRTC
// UNCOMMENT THE NEXT LINE TO SET TIME, THEN COMMENT IT BACK AND RE-UPLOAD // myRTC.setDS1302Time(00, 30, 14, 4, 25, 10, 2023);
#include // Creation of the Real Time Clock Object // Pins: CLK, DAT, RST virtuabotixRTC myRTC(6, 7, 8); void setup() Serial.begin(9600); // Set the initial time. // Format: seconds, minutes, hours, day of the week, day of the month, month, year // Example below: 12:30:00 PM on a Friday (6th day), May 29th, 2026 myRTC.setDS1302Time(00, 30, 12, 6, 29, 5, 2026); void loop() // Read the current time variables from the hardware module myRTC.updateTime(); // Print results 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(" "); Serial.print(myRTC.hours); Serial.print(":"); Serial.print(myRTC.minutes); Serial.print(":"); Serial.println(myRTC.seconds); // Wait one second before repeating delay(1000); Use code with caution. ⚠️ Troubleshooting Common Pitfalls