Introduction: Network Time Syncronized Clock for Arduino

Picture of Network Time Syncronized Clock for Arduino

Here is an example how to build Arduino clock which is syncronized with the time of given HTTP server in the net. My plan was to build simplest possible internet time syncronized clock. I decided to synchronize my Arduino clock with my Wlan router's time, the router itself is synchronized to the network time (NTP) time. Instead of NTP protocol, I am using HTTP protocol date field (in HTTP header) of my Wlan router to syncronize this clock.

Component list

  • Arduino nano (any Arduino will do)
  • ESP8266 wlan chip (note that this chip requires 3.3V power and shouldn't be used with 5V)
  • 0.96" 128x64 pixel OLED display
  • level converter or voltage divider (with resistors) for converting Arduino 5v to 3.3V suitable for ESP8266
  • 3.3V power supply (Arduinos 3.3V power output isn't quite enough for Wlan chip)

Step 1: Connect Arduino and OLED Display

OLED  Arduino
-------------
SDA   D9
SCL   D10
RST   D13
D/C   D11
VCC   5V
GND   GND

Step 2: Connect ESP8266 Wlan Chip to Arduino

Note that this chip is using 3.3V and connecting it directly to 5V will most probably break it. Voltage level conversion for data lines is necessary, simple resistor voltage divider is sufficient for converting Arduino's 5V TX to ESP8266 RX, you probably don't need any level converter for ESP8266 TX (3.3V) to Arduino's RX, as 3.3V is enough to drive Arduino's input.

Remember that this chip requires lots of current (200-300mA?) , so you may need a separate power supply for 3.3 Volts.

ESP8266 Reset pin needs to be connected to 3.3V or you may use software to control reset line (remember max 3.3V 'high' and use level converter or voltage divider here too).

ESP8266 Arduino
---------------
VCC     3.3V      Don't use 5V for ESP8266
GND     GND
TX      D3        Software serial port receiver (configurable),
no level converter needed for input RX D4 Software serial port transmitter (configurable),
USE LEVEL CONVERTER (5v->3.3v) for example as shown below RESET 3.3V Connect directly to 3.3V or use Arduino output pin with
level converter to reset the WLAN when needed

Simple voltage divider (Arduino 5V D4 -> ESP8266 RX) for level conversion

Arduino D4 (0 to 5V data out)   
         |
        1k ohm resistor
         |
         +--------  ESP8266 RX (0 to 3.3V data in)
         |
        2k ohm resistor
         |
         |
        GND

Step 3: Modify and Upload Software to Arduino

  • Set the SSID of the router (SSID)
  • Set WLAN password (PASS)
  • Set IP address of the server (WLAN router) (DST_IP).
    HTTP 'GET' request will be sent to this address. HTTP header of the response contains 'Date' attribute with current time (GMT). For example: Date: Sat, 28 Mar 2015 13:53:38 GMT
    You should use your Wlan router at home as a 'time server' or any other server in the internet if you can't get correct time from your local router.
  • Set the local time zone and daylight savings time as the received date field is always in GMT (UTC) time
  • Translate local weekdays to your language and set the date format as you wish (Day, dd.mm.year)

Note that ESP8266 is controlled by serial line and serial line buffer size of Arduino is only 64 bytes and it will overflow very easily as there is no serial line flow control. Because of that, additional reset line to WLAN chip may be necessary as described in the original HTTP client code (link for reference).

The software is using Arduino SoftwareSerial library to and OLED code originally from How to use OLED.

Here is my code on GitHub

Comments

seanman3000 (author)2017-05-17

Would it be possible to display Two times of day at once?

I'd like to have a clock that shows ET and UTC, and their respective dates all at once.

thanks!

cesar_guevara (author)2016-01-22

Do you think it's possible to get the local time depending time zone from the http request?

kariaa (author)2015-08-27

You can find router NTP settings when searching with keywords like 'router NTP settings' for your router. For my WiFi router (D-Link DIR860L) NTP settings are found in Tools - Time - Automatic Time and Date configuration.

Time format for HTTP header is always in GMT (UTC).
For example: "Date: Sat, 28 Mar 2015 13:53:38 GMT"

donvukovic (author)2015-08-26

Do you have any links to configure a router with NTP ?

or at least a google string that gets the same.

PRO DR MR BOB (author)2015-04-15

do u have any code for only using the esp8266 without the arduino and it would probly be easyer to use a I2C oled insted of spi

kariaa (author)PRO DR MR BOB2015-04-16

Well .. this same project WITHOUT Arduino would PROBABLY be technically ALMOST possible, then you would need to flash new firmware to ESP8266 which would then control OLED directly. ESP8266 would then act as a controller and need a special firmware just for this purpose. I'm hoping to find more ESP8266 information how to do that, although I'm not sure how many ESP8266 I/O pins you can freely use..

OLED control is not very difficult, unfortunately SPI needs few more I/O pins than pure I2C. You could also use excellent https://code.google.com/p/u8glib/ library for OLED displays.

cybericius (author)kariaa2015-07-14

GPIO0 and 2 on an ESP-01.

kariaa (author)cybericius2015-07-17

Ok, only two general purpose IO pins available on ESP-01 ..
and four (sda,scl,rst,d/c) would be needed for this OLED.

I've seen pure I2C version OLED displays on eBay, for those two GPIO pins would probably be enough?