myRTC.updateTime(); int currentHour = myRTC.hours; int currentMinute = myRTC.minutes; int currentSecond = myRTC.seconds;
While you could attempt to measure time using Arduino functions like millis() or delay() , these methods are highly inaccurate and will reset the moment your device loses power. An RTC ensures your project maintains indefinitely. Key Features of the VirtuabotixRTC Library
void loop() // This is the most important function: it updates the time from the RTC myRTC.updateTime();
: After calling updateTime() , the library makes the current time available through several public variables. You can access them directly in your code:
Checking for a specific minute rollover is trivial:
When logging sensor data every second, you don’t want to parse objects. This code is lean and fast:
In the world of embedded electronics, keeping accurate time is surprisingly difficult. While your Arduino runs flawlessly at 16MHz, its internal clock is a poor timekeeper—drifting by seconds per minute. The standard solution is a Real-Time Clock (RTC) module. But while the ubiquitous DS1307 and DS3231 RTCs have excellent hardware, their software ecosystem is fragmented.
The parameter ranges are as follows: