Home > Projects > Internet – Ethernet – LAN Projects > Network Time Protocol (NTP) Client using Arduino

Network Time Protocol (NTP) Client using Arduino

Summary of Network Time Protocol (NTP) Client using Arduino


This article demonstrates how to use an Arduino with an Ethernet Shield to query a Network Time Protocol (NTP) server for accurate internet time. The project connects the shield to the Arduino via SPI pins and requires an Ethernet cable for network access. Users must configure the code's network settings to match their local environment, noting that NTP servers may occasionally change IP addresses or fail temporarily.

Parts used in the NTP Client Project:

  • Arduino Ethernet Shield
  • Shield-compatible Arduino board
  • WizNet Ethernet controller
  • Ethernet cable
  • SD Card (on later models of the shield)

In this example, you will use your Ethernet Shield and your Arduino to query a Network Time Protocol (NTP) server. This way, your Arduino can get the time from the Internet.

Arduino Network Time Protocol

Circuit

The Ethernet shield allows you to connect a WizNet Ethernet controller to the Arduino via the SPI bus. It uses pins 10, 11, 12, and 13 for the SPI connection to the WizNet. Later models of the Ethernet shield also have an SD Card on board. Digital pin 4 is used to control the slave select pin on the SD card.

The shield should be connected to a network with an ethernet cable. You will need to change the network settings in the program to correspond to your network.

image developed using Fritzing. For more circuit examples, see the Fritzing project page

In the above image, your Arduino would be stacked below the Ethernet shield.

Schematic

Arduino Network Time Protocol Schematic

Code

/*

Udp NTP Client

Get the time from a Network Time Protocol (NTP) time server
Demonstrates use of UDP sendPacket and ReceivePacket
For more on NTP time servers and the messages needed to communicate with them,
see http://en.wikipedia.org/wiki/Network_Time_Protocol

Warning: NTP Servers are subject to temporary failure or IP address change.
Plese check

http://tf.nist.gov/tf-cgi/servers.cgi

if the time server used in the example didn't work.

created 4 Sep 2010
by Michael Margolis
modified 9 Apr 2012
by Tom Igoe

This code is in the public domain.

*/
Major Components in Project

Hardware Required

  • Arduino Ethernet Shield
  • Shield-compatible Arduino board

For more detail: Network Time Protocol (NTP) Client using Arduino

Quick Solutions to Questions related to NTP Client Project:

  • How does the Ethernet shield connect to the Arduino?
    The shield connects via the SPI bus using pins 10, 11, 12, and 13.
  • What is the function of digital pin 4 on the Ethernet shield?
    Digital pin 4 controls the slave select pin on the onboard SD card found on later models.
  • Can I get time from the Internet using this setup?
    Yes, the Arduino can query a Network Time Protocol server to get the time from the Internet.
  • Do I need to modify the program settings?
    Yes, you must change the network settings in the program to correspond to your specific network.
  • What happens if the NTP server fails?
    NTP servers are subject to temporary failure or IP address changes, so users should check the provided link for alternatives.
  • Which protocol messages are demonstrated in the code?
    The code demonstrates the use of UDP sendPacket and ReceivePacket.
  • Where can I find more circuit examples like this one?
    More circuit examples are available on the Fritzing project page.
  • Is the source code for this project proprietary?
    No, this code is in the public domain.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top