Introduction: IP Time Clock Part 1

About: Lazy Old Geek

REQUIREMENT: WiFi Access with SSID and password if necessary

So this Lazy Old Geek (LOG) has a couple of clocks in my bedroom. One of them loses time when the power is lost. The other is semi smart and automatically adjusts for Daylight Savings Time. Unfortunately, it does this using the old standard so I have to re-set the time four times a year. Well, I’m LAZY so I decided to make my own Clock. At first I was thinking Atomic clock as I have three in my living room (I’m a GEEK, remember?).

Then I thought, I’ve been looking into these ESP8266s which are microcontrollers with WiFi access. Well, the Internet should know what time it is. Windows computers usually use the Internet to adjust their clocks.

So after surfing the Web, I found NTP(Network Time Protocol) which should work for me.

https://en.wikipedia.org/wiki/Network_Time_Protoco...

and to make it even easier the ESP8266 as Arduino already has an NTP example program

https://github.com/esp8266/arduino

Step 1: Hardware Design

So I planned to use the ESP8266, specifically, the ESP-03 as the brains of the clock. I decided on using a four digit, seven segment display. To drive the display, I would use a MAX 7219 IC. See picture.

PROBLEM: So the ESP8266 specification for voltage is 3.0 to 3.6Vdc.

The MAX7219 is 4.0 to 5.5Vdc.

Maxim does make a 3.3V IC MAX6950/1 but it is an SMD package and about five times the cost.

SOLUTION: Well, I had some MAX7219s and tried them at 3.3Vdc and they worked.

Here is the way I look at it. When an IC manufacturer writes specifications for a part, they’re essentially guaranteeing that all parts will meet them. Now in order for them to meet them, the design specification has to be much wider than the specification.

WARNING: So for the purists and perfectionist out there, this design is using the part outside of specifications. If I was designing for a commercial product, I wouldn’t do this. But as a hobbyist, I would.

When buying 7 segment displays for the MAX7219, make sure they are common cathode. Some of them come with the two dots like most digital clocks. The ones I have use the 12 pin interface. They come in different sizes and colors.

Major costs

ESP-03 $2.50

MAX7219 $1.00

4 digit 7 segment display $0.50

L4931cz33 voltage regulator $1.50

Prices on ebay/aliexpress.com

I have a lot of 5V wall wart power supplies. I just spliced in a JST2.0 connector.

So the total cost is about $7 USD.

Attached is the schematic.

COMMENTS:

R4 is the RSET resistor for the MAX7219. It helps limit the current for the display. Minimum is about 10K but I wanted a dimmer display for my bedroom so I set it to 27K.

I have the software set for 12 hour display. LED1 is on when it is AM.

Flash and Reset are two pin headers that can be used to set the ESP-03 into program mode to load a different sketch.

JST2.0 connector is the 5Vdc supply connector.

The USB-BUB connector is my standard USB-BUB. It requires a USB serial adapter such as a CP2102 to reload sketch but requires nothing when just running.

I had some problems when I made this PCB. I think the problem is that I just switched to a generic toner for my laser printer and it did not adhere like the original. I couldn’t get the silk screen to transfer at all as you can see in the picture.

But with a lot of work and some extra jumpers, I did get it to work.

NOTE: The display is resting on the MAX7291. I trimmed off the tabs so it fit a little better.

Eagle Cadsoft files attached.

Step 2: Daylight Savings Time

So this STEP is pretty technical and can be skipped if you’re not interested:

Okay, so there is an Arduino library written to handle Daylight Savings Time changes:

https://github.com/JChristensen/Timezone

However, it wouldn’t compile when using the ESP8266 library. (Something to do with EEPROM.) So I wrote my own code.

Here’s the current US rules for Daylight Savings Time:

https://en.wikipedia.org/wiki/Daylight_saving_time_in_the_United_States

“Currently, daylight saving time starts on the second Sunday in March and ends on the first Sunday in November, with the time changes taking place at 2:00 a.m. local time. With a mnemonic word play referring to seasons, clocks "spring forward and fall back"—that is, in spring (technically late winter) the clocks are moved forward from 2:00 a.m. to 3:00 a.m., and in fall they are moved back from 2:00 am to 1:00 am.”

Well, if you done some programming, this gets pretty complicated. Here’s what I did.

The Arduino time library, like many computers uses something called Unix Time:

https://en.wikipedia.org/wiki/Unix_time

Unix time (also known as POSIX time or Epoch time) is a system for describing instants in time, defined as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970

Now, NTP and GPS use UTC. UTC is not a timezone but it is based on the time in England so you have to convert it to local time and adjust for Daylight Savings time.

So I created two variables called SpringChange and FallChange in Unix time format.

Then using NTP, I found the current year.

From the year, I then calculated the two unix times for the two variables. This is tricky as the second Sunday in March and the first Sunday in November are not the same day from year to year. But one thing the Time library can tell is given a Unix time, it can determine the weekday. So using the month, the day and the weekday, I was able to figure out the Change days for the year.

So when the program gets a new UTC time, if it is greater than or equal to (>=) SpringChange and less than (<) FallChange than it is Daylight Saving Time (DST). Otherwise it’s not DST. Now to get current local time, I adjust for (in my case) Mountain Time and Daylight savings time.

Step 3: SKETCH

REQUIREMENT: WiFi Access with SSID and password if necessary

NOTE: The sketch adjusts for Daylight Savings according to US rules as of October 2015. Places that do not use Daylight Savings and other countries probably won't work.

So loading the sketch onto the ESP-03 is fairly complicated.

My ESP8266 Instructable may help:

https://www.instructables.com/id/ESP8266-as-Arduino...

The ESP8266 library I use is at:

https://github.com/esp8266/arduino

The library for the MAX7219 is at:

https://github.com/wayoda/LedControl

The latest(I think) Time library is this one:

http://www.pjrc.com/teensy/td_libs_Time.html

First you have to edit the Sketch for your situation.

You need to know the SSID name for your local access point or hotspot and Password if used. Open the sketch for editing and put them into these two lines:

char ssid[] = "yourSSID"; // network SSID (name)

char pass[] = "yourPassword"; // network password

Under // NTP Servers, I listed several. The one I’m using I think is Salt Lake City. You can uncomment any one that you want.

If your timeZone is not Mountain, change the following line:

const int timeZone = -7; // Mountain Standard Time (USA)

You want your local standard time offset

Eastern -5

Central -6

Mountain -7

Pacific -8

Hawaii -10

Under setup(){ there is a line of code:

lc.setIntensity(0,1); // Set the brightness to a low value

The second parameter (1) can be set anywhere from 0 to 15. This (along with the Rset resistor determines the brightness of the display). Since I use mine at night, I have it set pretty low.

NOTE: If you want the display to show 24hr clock instead of 12, under

void digitalClockDisplay(), change the following two lines:

lc.setDigit(0,0,int(hourFormat12()/10),false);

lc.setDigit(0,1,(hourFormat12() % 10),true);

to:

lc.setDigit(0,0,int(hour()/10),false);

lc.setDigit(0,1,(hour() % 10),true);

NOTE: This code is designed to work with a four digit or a six digit display. One little problem is with a four digit display, there is a dot after the minutes. If you want to turn it off, change the following line:

lc.setDigit(0,3,(minute() % 10),true);

to:

lc.setDigit(0,3,(minute() % 10),false);

The following lines:

lc.setDigit(0,4,int(second()/10),false);

lc.setDigit(0,5,(second() % 10),false);

can be deleted as they’re only used by a six digit display.

To load the sketch, put the ESP-03 in programming mode. Start Arduino environment. Select the correct USB port. Under Board, select Generic ESP8266 module. Upload the sketch.

So this Clock seems to work pretty good for me.

Time Contest

Participated in the
Time Contest