Summary of Network Time Protocol (NTP) Client using Arduino
This project demonstrates how to use an Arduino with an Ethernet Shield to query a Network Time Protocol (NTP) server and obtain the current time from the Internet. The Ethernet Shield, equipped with a WizNet Ethernet controller and optionally an SD card, connects via the SPI bus to the Arduino. This setup requires configuration of network settings and uses UDP communication to send and receive time data. The example code facilitates interaction with NTP servers to retrieve accurate network time.
Parts used in the Network Time Protocol (NTP) Client using Arduino:
- Arduino board (shield-compatible)
- Arduino Ethernet Shield (WizNet Ethernet controller)
- Ethernet cable
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.
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
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. */
Hardware Required
- Arduino Ethernet Shield
- Shield-compatible Arduino board
For more detail: Network Time Protocol (NTP) Client using Arduino