Atomic Clock Sync: ESP32 NTP Magic in Just 2 Lines of Code! @atomic14
Atomic Clock Sync: ESP32 NTP Magic in Just 2 Lines of Code!  @atomic14
Uploaded June 2022 | Updated November 2026, 20 hours ago
As always we're sponsored by PCBWay.com/?from=atomic. I've got some PCBs manufactured for the next video so don't forget to subscribe.

Time - what's it's all about - it's a mystery. How do we know what time it is? More importantly, how does our computer know what the time it is?

I've been messing around with time on the ESP32 and it's surprisingly easy to get it to talk to an NTP server. And if you're talking to an NTP server, it's more than likely that you are getting your time from an atomic clock - pretty amazing!

A few people have asked for clarification on the formulas.

Imagine NTP time is 0:30 and our local clock is 10seconds behind at 0:20

We send a request at 0:20 it takes 1second to reach the server and the server records the request received as 0:31.

The server takes 1 second to process the request so sends its reply at 0:32

It takes 1 second for the reply to reach us so we recorded the receive time as 0:23

If we now apply the formula for theta we have.

0.5 x ((0:31 - 0:21) + (0:32 - 0:23)) = 0.5 x (10+10) = 10

So we have 10 seconds as our offset from the server time.

Applying the formula for delta:

(0:23 - 0:20) - (0:32 - 0:31) = 2

We have a total network delay of 2 seconds.

My transparent OLED display came from DFRobot - dfrobot.com/product-2521.html You can drive it using the U8G2 library github.com/DFRobot/U8g2_Arduino

0:00 A transparent OLED display
0:41 Why is this interesting?
1:08 Are we really talking to an atomic clock?
1:50 The Network Time Protocol
3:51 Let's see it in action
4:21 Yes! We really are talking to an atomic clock!
4:44 How does it work?
5:24 Can time go backwards?
6:03 Two lines of code!
6:43 Some caveats

----
If you'd like to help support the channel then I have a Patreon and a KoFi page:

Patreon - patreon.com/atomic14
KoFi - ko-fi.com/atomic14

And if you're shopping on AliExpress or Amazon then if you click on these links I will get a little bit of affiliate money:

Aliexpress - https://s.click.aliexpress.com/e/_Ac05mF
Amazon - amazon.com/?tag=atomic14-20

You can also join us on Discord here: discord.gg/h2DDnDdjD2
Atomic Clock Sync: ESP32 NTP Magic in Just 2 Lines of Code!ESP32 Deep Sleep: Ultra-Low Power CoprocessorTaking KiCad Silk Screen to the Next Level!Creating an Animated Avatar with AI: Conquer Earth for Donuts!The PCBs are in production - what have I messed up?I Built My Own ESP32-S3 Board… And It Actually Works!ESP32 Audible Noise When Using WiFiESP32-S3 USB UAC Audio Device - does it work?ESP32 and GPSTest Arduino & ESP32 Codes in Your Browser: WokWi Simulator Unveiled!Hammer Time :)Forget the Arduino Serial Plotter - try this instead!
atomic14 |

Atomic Clock Sync: ESP32 NTP Magic in Just 2 Lines of Code!

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER