Get Real Time with NTP/RTC
Stamp data with accurate dates and times.
Get Real Time with NTP/RTC is a free Arduino & IoT Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Arduino & IoT Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why Time Matters
A reading like "24.3 C" is half a story. To make sense of logged data, every sample needs a timestamp telling you exactly when it happened. ⏰
Arduino Has No Clock
Your Arduino forgets the date the moment power drops. It only counts milliseconds since boot, so it has no idea what real-world wall-clock time it is.
Two Ways to Get Time
You can fetch the time from the internet with NTP, or keep it locally with a battery-backed RTC chip. Each fits a different situation.
What NTP Does
NTP (Network Time Protocol) asks a time server online for the current moment. It is accurate and free, but it needs an active WiFi connection to work.
Asking an NTP Server
On an ESP32 one line of setup points your board at a public time server and your timezone offset. Then the board syncs automatically.
configTime(0, 0, "pool.ntp.org");Reading the Synced Time
Once synced, you pull the current time into a struct and read its fields. This gives you year, month, day, hour, and minute to label data.
struct tm now;
getLocalTime(&now);What an RTC Does
An RTC module like the DS3231 keeps ticking on a tiny coin battery, even with the Arduino fully off. No network needed at all.
Wiring an RTC
Most RTC modules talk over I2C, so you connect just four wires: power, ground, SDA, and SCL. That keeps your build wonderfully simple.
Reading from an RTC
With the RTClib library you grab the current moment as a DateTime object, then read its fields just like the NTP version.
DateTime now = rtc.now();
int h = now.hour();NTP or RTC?
Pick NTP when your device is always online and you want zero extra parts. Pick an RTC for offline or battery nodes that still need the right time.
Best of Both
Many strong designs use both: an RTC keeps time offline, and NTP gently corrects its small drift whenever WiFi is available. 🌐
Quick Check
Which time source still works with no internet connection?
Recap
Arduino has no real clock, so add time with NTP online or an RTC offline. Now every reading you log can carry an accurate timestamp. ✅
Frequently asked questions
Is the “Get Real Time with NTP/RTC” lesson free?
Yes — the full text of “Get Real Time with NTP/RTC” is free to read here on the web, and the Arduino & IoT Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Arduino & IoT Academy course, upgrade to CoddyKit PRO.
What will I learn in “Get Real Time with NTP/RTC”?
Stamp data with accurate dates and times. You practise Arduino & IoT Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Arduino & IoT Academy?
No prior experience is required. Arduino & IoT Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Get Real Time with NTP/RTC” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Arduino & IoT Academy lesson?
Yes. Every Arduino & IoT Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Get Real Time with NTP/RTC
- Write CSV to an SD Card
- Buffer & Batch Uploads
- Visualize Logged Data