Do you need to set up based on the time data? Share public link
// Print date on the second row lcd.setCursor(0, 1); lcd.print("Date: "); if (myRTC.dayofmonth < 10) lcd.print("0"); lcd.print(myRTC.dayofmonth); lcd.print("/"); if (myRTC.month < 10) lcd.print("0"); lcd.print(myRTC.month); lcd.print("/"); lcd.print(myRTC.year);
lcd.clear();
virtuabotixRTC myRTC(7, 6, 5); int tempPin = A0; File dataFile; virtuabotixrtc.h arduino library
With this guide, you are now equipped to add the dimension of time to any Arduino project. Go build something that ticks.
// Verify the setting myRTC.updateTime(); Serial.println("Time has been set!");
Wiring issue or poor connection on CLK, DAT, or RST lines. Fix: Check all jumper wires. Use shorter wires. Add 10k pull-up resistors on DAT and CLK if the wires are long. Do you need to set up based on the time data
The virtuabotixRTC.h library uses a few critical functions for daily operation: Description virtuabotixRTC(clk, dat, rst)
This project logs temperature (from a TMP36 sensor) to an SD card alongside the current time.
Unlike some libraries that require complex initialization, you define your pins directly when creating the virtuabotixRTC object. // Verify the setting myRTC
The VirtuabotixRTC library is not available through the default Arduino Library Manager. You must manually install it from a ZIP file.
This is the most crucial function in the library. Before you can read any time data, you must call myRTC.updateTime() . This command fetches the latest time values from the DS1302 chip and stores them in the myRTC object's variables. You should call this function at the beginning of your loop() or whenever you need a fresh timestamp.
#include // Creation of the Real Time Clock Object (CLK, DAT, RST) virtuabotixRTC myRTC(6, 7, 8); void setup() Serial.begin(9600); // Set time only on the first run: sec, min, hr, dow, day, month, year myRTC.setDS1302Time(00, 30, 15, 4, 16, 4, 2026); void loop() myRTC.updateTime(); // Pull latest data from the chip 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.println(myRTC.minutes); delay(1000); Use code with caution. Copied to clipboard Installation and Availability