A lightweight, software-based real-time clock (RTC) library for Arduino and compatible microcontrollers. This library allows you to maintain date and time (hours, minutes, seconds, day, month, year) without needing dedicated RTC hardware modules. It supports both 12-hour (AM/PM) and 24-hour modes, calculates weekdays, and offers a straightforward API for time manipulation.
- Software RTC: Maintains date/time using
millis()– no additional hardware required. - 12-Hour / 24-Hour Modes: Easily switch between standard (AM/PM) or 24-hour (military) time.
- Weekday Calculation: Automatically determines the weekday (Sun–Sat).
- Serial Output: Built-in
print()function for quick debugging or logging. - Minimal Footprint: Designed to be lightweight for memory-constrained devices.
- Click the green “Code” button on this GitHub repository and select Download ZIP.
- Extract the ZIP file on your computer.
- Rename the extracted folder to
softRTC(if it isn’t already). - Move the
softRTCfolder into your Arduino libraries directory:- Windows:
Documents\Arduino\libraries\ - macOS:
~/Documents/Arduino/libraries/ - Linux:
~/Arduino/libraries/
- Windows:
- Restart the Arduino IDE if it was open.
-
Include the Library
#include <softRTC.h>
-
Create an RTC Object
softRTC myRTC;
-
Set the Time
// write(day, month, year, hour, minute, second, isPM, is12HMode) // Example: set 10:15:30 AM, 21 March 2025 in 24-hour mode myRTC.write(21, 3, 2025, 10, 15, 30, false, MODE_24H);
-
Read the Time
uint8_t d, m, h, min, s, weekday; uint16_t y; bool pm, is12; myRTC.read(d, m, y, h, min, s, pm, is12, weekday); // Now you can use these variables in your code...
-
Print the Time
myRTC.print(); // e.g., "21-3-2025 10:15:30 24H Fri" -
Check Sync Status
if (!myRTC.syncStatus()) { // If false, the clock isn't set or has invalid data }
#include <softRTC.h>
softRTC myRTC;
void setup() {
Serial.begin(9600);
// Set the time to 9:30:45 PM, 21 March 2025 in 12-hour mode
myRTC.write(21, 3, 2025, 9, 30, 45, true, MODE_12H);
}
void loop() {
// Print the current time every second
static unsigned long lastUpdate = 0;
if (millis() - lastUpdate >= 1000) {
lastUpdate = millis();
myRTC.print();
}
}Issues / Feature Requests
If you run into any problems or have ideas for improvements, please open an issue on GitHub.
Pull Requests
- Fork the repository and create a branch for your changes.
- Make commits with clear and descriptive messages.
- Submit a pull request explaining what you changed and why.
Code Style
Follow the existing code structure. If you add a feature, include an example or documentation update.
This library is released under the MIT License.
See the LICENSE file for details.
Manzar E Hassin
- GitHub: manzarehassin
- Email: mnz247@hotmail.com
Feel free to reach out with questions, feedback, or to share any projects using softRTC!