Once updated, you can access the time through the following integer variables: myRTC.seconds myRTC.minutes myRTC.hours myRTC.dayofweek myRTC.dayofmonth myRTC.month myRTC.year 📜 Complete Example Sketch
DateTime now = myRTC.getDateTime(); Serial.print("Current date and time: "); Serial.print(now.year); Serial.print("-"); Serial.print(now.month); Serial.print("-"); Serial.print(now.day); Serial.print(" "); Serial.print(now.hour); Serial.print(":"); Serial.print(now.minute); Serial.print(":"); Serial.println(now.second);
virtuobabotixRTC myRTC(7, 6, 5);
Before you download the library, you need the right hardware. The virtuabotixrtc.h library is tailor-made for the RTC chip. You will commonly find this chip on breakout boards that look like small PCBs with: virtuabotixrtc.h arduino library
// Create an instance of the VirtuabotixRTC class VirtuabotixRTC myRTC(rtcClockPin, rtcDataPin, rtcCsPin);
This project logs temperature (from a TMP36 sensor) to an SD card alongside the current time.
The virtuabotixRTC library is not included in the default Arduino IDE installation, so you will need to install it manually. While the library may not be readily available in the Library Manager, you can find its download on various Arduino tutorial websites. Once updated, you can access the time through
Includes a backup battery slot (usually for a CR2032 or CR1220 battery) to maintain timekeeping when the main Arduino power is disconnected. Wiring the DS1302 RTC to an Arduino
Setting and fetching time requires just a few intuitive function calls.
Here is an example of how to create an instance of the VirtuabotixRTC class: The virtuabotixRTC library is not included in the
While you can connect these to almost any digital pins on your Arduino, the following table shows a standard configuration: DS1302 Pin Arduino Pin Description Main power supply GND Ground connection CLK (SCLK) Serial Clock DAT (I/O) Serial Data RST (CE) Reset / Chip Enable Installing the library
The library acts as a wrapper for the raw code originally developed for the Arduino Playground. It provides high-level functions to manage: