0Pricing
Arduino & IoT Academy · レッスン

NTP/RTCで正確な時刻を取得する

正確な日付と時刻をデータに記録します。

「NTP/RTCで正確な時刻を取得する」はCoddyKit上の無料Arduino & IoT Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはArduino & IoT Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Arduino & IoT Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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. ✅

よくある質問

「NTP/RTCで正確な時刻を取得する」レッスンは無料ですか?

はい。「NTP/RTCで正確な時刻を取得する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Arduino & IoT Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Arduino & IoT Academyコースには全4レッスンが含まれています。

「NTP/RTCで正確な時刻を取得する」で何を学びますか?

正確な日付と時刻をデータに記録します。 ブラウザで直接実行するハンズオンコードでArduino & IoT Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Arduino & IoT Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのArduino & IoT Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「NTP/RTCで正確な時刻を取得する」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このArduino & IoT Academyレッスンでコードを書いて実行できますか?

はい。すべてのArduino & IoT Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. NTP/RTCで正確な時刻を取得する
  2. SDカードにCSVを書き込む
  3. アップロードをバッファリング・一括処理する
  4. 記録データを可視化する
← Arduino & IoT Academyに戻る