Obtener la hora real con NTP/RTC
Añada fechas y horas precisas a los datos.
Obtener la hora real con NTP/RTC es una lección gratuita de Arduino & IoT Academy en CoddyKit. Esta es la lección 1 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Arduino & IoT Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Arduino & IoT Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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. ✅
Preguntas frecuentes
¿La lección «Obtener la hora real con NTP/RTC» es gratis?
Sí — el texto completo de «Obtener la hora real con NTP/RTC» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Arduino & IoT Academy, actualiza a CoddyKit PRO. El curso de Arduino & IoT Academy incluye 4 lecciones en total.
¿Qué aprenderé en «Obtener la hora real con NTP/RTC»?
Añada fechas y horas precisas a los datos. Practicas Arduino & IoT Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Arduino & IoT Academy?
No se requiere experiencia previa. Arduino & IoT Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 1 de 4.
¿Cuánto tiempo toma la lección «Obtener la hora real con NTP/RTC»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Arduino & IoT Academy?
Sí. Cada lección de Arduino & IoT Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Obtener la hora real con NTP/RTC
- Escribir CSV en una tarjeta SD
- Almacenar y agrupar cargas
- Visualizar datos registrados