Main Menu

Secondary Menu

IP Time Clock Part 1

Introduction: IP Time Clock Part 1

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.

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.

“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:

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.

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:

They are SMD parts but large enough that are easy to solder. AMS does samples too so that is an option.

I haven't taken a look to see what it would take yet. Hmm maybe I can just serve up the time to a Linux VM and let it be the NTP service. Wouldn't be as streamlined but would be easier. Except couldn't be able to get exactly down to the second hence what NTP takes care of.

interesting. I had not considered using the ESP8266 simply for a clock. Where did u get yr 4 digit display? it is unbelievably cheap.Currently I use a simple piece of code for all my arduino's that keep time from an RTC to set and reset DaylightSavingTime, but I may try yr approach as well some day if I have time (too many projects)

aliexpress, I knew it. My favorite store :-)The DS3231 is fairly accurate. The DS1307 is not that accurate unless you make sure you have a good crystal and keep that close to the chip and ground it very well. Something that can vary per module as self built is hardly worth it considering the price. Though the DS3231 has my preference I just bought a bunch of DS1307's coz they were dirt cheap.

Have to admit that until a few days ago, I had a very complicated way of changing back and forth to DST till I thought that was crazy and took a deeper look. That s also how I came up with the Sakamoto Algorithm. Mind you though it only works for Gregorian calendars :-)As far as my own algorihm goes, yes you are right. You do not need a check for <=31, but I am an anal retentive controlfreak so I put it in anyway :-) But yes, d will never be greater than 31 on the RTC's that I know

Newsletter

Let your inbox help you discover our best projects, classes, and contests. Instructables will help you learn how to make anything!