Simplest ESP8266 Local Time Internet Clock With OLED

75,357

320

59

Introduction: Simplest ESP8266 Local Time Internet Clock With OLED

I was looking for a straightforward clock to use with a 128x64 OLED I got from Adafruit but found that a lot of the implementations were too cumbersome, involved a ton of code, weren't clear on what NTP servers to use and how, and basically offered very little in terms of making a clock with the LOCAL time (not UTC, which is easy enough to get). So I set about doing my own research and ended up with this simple clock that leverages already made libraries to minimize the code footprint, while offering some interesting tweaks in displaying the time (like AM/PM, 12-hour format, names for months, days, etc). This instructable assumes you have some experience programming ESP-01s but if not, there are a ton of wonderful tutorials available on Instructables! Enjoy!

Step 1: Components

For this instructable you will need:

  • ESP8266-01 module
  • 128x64 OLED with I2C interface
  • 3.3V power supply
  • A way to program the ESP-01

Step 2: Wire It Up!

The wiring is simple. Just follow the diagram above and connect the wires. Then get a 3.3V power supply (I used a step-down module to go from 12V to 3.3 but you can use whatever you have in your arsenal as long as it outputs 3.3V and at least 0.5 A).

Step 3: Program the ESP-01

This step can be frustrating if you haven't done it before, but once you get the hang of how the ESP boards work and have the correct drivers and libraries installed in Arduino, you can go ahead and use the following code. But first, you will need to download and install the following libraries:

You may need to modify some of the code according to what OLED you're using (as long as it's SSD1306 it'll work but you may need to update the hex I2C address) and then you may have to change some of the Timezone rules depending on your timezone and daylight savings time rules. Then upload the code attached and you should be done!

Step 4: See It Go!

Once you have programmed the ESP, plugged everything in, make sure you have 3.3V going into the setup and then power it on and see your correct time on the tiny display!

8 People Made This Project!

Recommendations

  • Make it Glow Contest

    Make it Glow Contest
  • First Time Author Contest

    First Time Author Contest
  • PCB Challenge

    PCB Challenge

59 Discussions

0
timg11
timg11

Question 2 years ago on Step 3

Compiler gives: "WARNING: library Timezone claims to run on (avr) architecture(s) and may be incompatible with your current board which runs on (esp8266) architecture(s)."

Does this mean anything?

0
michail1
michail1

Answer 6 months ago

The reason is the author only works exclusively with AVR even though the library works with ESP8266 and ESP32 just fine. You can ignore the error, or you can modify a file in the library directory to have it know that it will work correctly.

Look for a file in the library directory in the Timezone folder called...
library.properties
open as a text file and change...
architectures=avr
to
architectures=avr,esp8266,esp32

0
DaniilZ
DaniilZ

Answer 2 years ago

No

0
Edward_
Edward_

Question 1 year ago on Step 3

Can you please suggest what changes would be necessary for 24 Hour time format?
Or do you have a 24 Hr version?

0
yoavaba1
yoavaba1

Answer 1 year ago

change:
// format the time to 12-hour format with AM/PM and no seconds t += hourFormat12(local);
t += ":";
if(minute(local) < 10) // add a zero if minute is under 10
t += "0";
t += minute(local);
t += " ";
t += ampm[isPM(local)];

to:
t += hour(local);
t += ":";
if(minute(local) < 10) // add a zero if minute is under 10
t += "0";
t += minute(local);
t += ":";
if(second(local) < 10) // add a zero if minute is under 10
t += "0";
t += second(local);

you can delete the seconds

0
Scotthus2
Scotthus2

1 year ago

so this code works great only issue i am having is the clock is a hour fast.. I changed the timezone code to central with no change. anyone help with what to do to change the hour its ahead.. my guess is daylight savings change is the issue.

TimeChangeRule usCDT = {"CDT", Second, Sun, Mar, 2, -300}; //UTC - 5 hours - change this as needed
TimeChangeRule usCST = {"CST", First, Sun, Nov, 2, -360}; //UTC - 6 hours - change this as needed
Timezone usCentral(usCDT, usCST);
local = usCentral.toLocal(utc);

0
MichaelB247
MichaelB247

Reply 1 year ago

It's because you didn't change the values of the last numbers in the function. -300 is 5 hours (5*60) but you actually need 360 there and 420 in the second row, because you're an extra hour behind the Prime meridian. So if you change the first line to -360 and second to -420 you should be good to go.

0
Scotthus2
Scotthus2

Reply 1 year ago

It worked.. I thank you sir.. I like this format of the clock and date.. Nice work

0
nanoprof
nanoprof

Question 1 year ago

Pourquoi les projets sur instructable ne fonctionne jamais!

0
parisa2000
parisa2000

1 year ago

hi, can you launched sensor fluxgate flc100 magnetometr with ardunio and conected to pc wiht bleuthos? thack you very much

0
leonardtsai22
leonardtsai22

1 year ago

Great project for simple clock. I am trying to change timezone with following modifications:

TimeChangeRule usPDT = {"PDT", Second, Sun, Mar, 2, -420}; //UTC - 7 hours - change this as needed
TimeChangeRule usPST = {"PST", First, Sun, Nov, 2, -480}; //UTC - 8 hours - change this as needed
Timezone usPacific(usPST, usPDT);
local = usPacific.toLocal(utc);

However, it seems that the time is showing PST instead of PDT (currently it is June so should be daylight saving PDT time instead).

Where may I have missed it?

Thanks in advance.


0
MichaelB247
MichaelB247

Reply 1 year ago

Looks like you have usPST and usPDT reversed. Your third line should read:
Timezone usPacific(usPDT, usPST);

0
BohuslavK1
BohuslavK1

1 year ago

Please help. Compiler writes:
C:\Users\xxxx\Documents\Arduino\libraries\Time-master\DateStrings.cpp:
In function 'char* monthStr(uint8_t)':



C:\Users\xxxx\Documents\Arduino\libraries\Time-master\DateStrings.cpp:76:66:
error: 'strcpy_P' was not declared in this scope




strcpy_P(buffer, (PGM_P)pgm_read_word(&(monthNames_P[month])));



^


C:\Users\xxxx\Documents\Arduino\libraries\Time-master\DateStrings.cpp:
In function 'char* dayStr(uint8_t)':



C:\Users\xxxx\Documents\Arduino\libraries\Time-master\DateStrings.cpp:90:61:
error: 'strcpy_P' was not declared in this scope




strcpy_P(buffer, (PGM_P)pgm_read_word(&(dayNames_P[day])));
What is wrong !!!!

0
gig68
gig68

Question 1 year ago

Buon giorno
volevo realizzare questo progetto ma aprendo il file . ino scaricato sull ide di arduino mi da errore
mi potete aiutare
grazie

0
giecuk
giecuk

Question 2 years ago on Step 3

please help me, my oled won't show screen, it's not broken oled... because if i have another sketch the oled works...

2
Xuan TruongH
Xuan TruongH

Answer 2 years ago

bạn tìm dòng code này SSD1306 display(0x3c, 0, 2); //0x3d for the Adafruit 1.3" OLED, 0x3C being the usual address of the OLED 0.96" thay 0x3d thành 0x3c dùng cho loại LCD 0.96 Inch

0
meahdi
meahdi

3 years ago

Hi

I like this project

How can i change time zone to my local time

0
karsten2
karsten2

Reply 2 years ago

hey, you have to edit the line 94 and 95 to deposit your own difference to the utc-time.

0
wangzhen
wangzhen

Reply 3 years ago

youcan do that: setTime(nettime + x * 3600);

Im in china so x = 8 setTime(nettime + 8 * 3600);

0
meahdi
meahdi

Reply 3 years ago

Thanks for your help