Skip To Main Content

Virtuabotixrtch Arduino Library Page

Virtuabotixrtch Arduino Library Page

#include // Create an instance of the class // Pins: CLK=6, DAT=7, RST=8 virtuabotixRTC myRTC(6, 7, 8); void setup() Serial.begin(9600); // Set the current time: 00:00:00, Monday, 1st Jan 2026 // setDS1302Time(seconds, minutes, hours, dayofweek, dayofmonth, month, year) // Uncomment the line below once, upload, then comment it out and re-upload. // myRTC.setDS1302Time(0, 0, 0, 1, 1, 1, 2026); void loop() // Update time from the module myRTC.updateTime(); // Print formatted time Serial.print(myRTC.gettime()); // Print individual components Serial.print(" -> Year: "); Serial.println(myRTC.year); delay(1000); // Wait one second Use code with caution. 6. Common Issues and Troubleshooting

#include <VirtuabotixRTCH.h>

If you have a DS1302 module (often the one with the vertical pins), this library offers a few distinct advantages: virtuabotixrtch arduino library

If you're building a weather station or a device that monitors sensors, it's essential to know when a measurement was taken. The VirtuabotixRTC library can be combined with an SD card module. Every time you take a reading from a sensor (like a temperature sensor), you can also record the precise time (e.g., myRTC.hours , myRTC.minutes ) to a file on the SD card. This creates a timestamped log of your data.

#include // Creation of the Real Time Clock Object (SCLK, 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 // Day of week: Sunday = 1, Monday = 2, etc. // Run this ONCE to set the clock, then comment it out and re-upload. myRTC.setDS1302Time(00, 30, 15, 2, 21, 4, 2026); void loop() // Always update the time before reading elements myRTC.updateTime(); // Access individual elements Serial.print("Current Time: "); Serial.print(myRTC.hours); Serial.print(":"); Serial.print(myRTC.minutes); Serial.print(":"); Serial.println(myRTC.seconds); delay(1000); Use code with caution. Copied to clipboard IoT cloud rtc problem - Arduino Forum #include // Create an instance of the class

delay(1000); // Wait one second before reading again

virtuabotixRTC library is a widely used Arduino library specifically designed to interface with the DS1302 Real-Time Clock (RTC) This creates a timestamped log of your data

Ensure a CR2032 battery is installed in the module to keep time when the Arduino is unplugged. Installing Libraries | Arduino Documentation

This is almost always because you have not removed or commented out the myRTC.setDS1302Time() function from your code. The DS1302 has its own backup battery. Your sketch should not set the time on every power-up. Use the setDS1302Time function once to set the correct time, then comment it out, re-upload the sketch, and the module will maintain the time from its backup battery.

– You must set the weekday (1=Monday through 7=Sunday) manually. This trips up beginners expecting "March 15, 2025" to auto-map to "Saturday."

void setup() Serial.begin(9600);