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!

<p>Easy to build, I used an ESP-01, 128x64 Display and a regulator for 3.3 V. Yes, I changed language and time display to 24hour.</p>
<p>Hi,</p><p>Can you let me know what regulator you used? I'm having trouble finding something that will handle the 0.5A pull. </p>
<p>I used a part from Aliexpress &quot;5V To 3.3V DC-DC Step-Down Power Supply Buck Module AMS1117 800MA&quot;,</p><p>10 pcs for 3.43 $.</p><br>
<p>You should look at AMS1117 for a good, cheap regulator that's also quite small. That, plus a USB port or charger and a decoupling 10 uF capacitor and you should be good to go. Takes some soldering but it ends up being cheaper and smaller than off-the-shelf stuff.</p>
<p>Very nice! I like the idea of using a rechargeable Li-ion battery and making the whole thing portable!</p>
<p>Finally, something that will convert time for me. I dreaded having to write the code myself. A good source for time, instead of say a timezone server would be Google.com, you can connect to the HTTP, pull the HTML on a simple search, and look for &quot;Date:&quot; and it returns the date time in GMT at +1 character. You should be able to use this for local time then in combination with the libraries he has here. Google.com seems to be much faster than connecting to servers that have the time exposed for some reason - guessing bandwidth they use.</p>
<p>Yes, using the HTML headers from the GET request will give you the same UTC time. I did try going that route too, but it wasn't quite as simple as using the NTP library. I did also notice the ntp servers being a bit laggy but oh well..</p>
When I swing back around to that project I will post the interface if needed. I was going to use it for a temperature alert that emailed to GMAIL every couple hours when required. I got sidelined when I realized that the deepsleep mode on the 8266 really only had a 15 minute (roughly) usability. So, I'm working on both the wake-up circuit and using the non-volatile memory for a count down in 15 min intervals. When I'm done with that I will get back to the GMT conversion. It can't be that hard. The server response time thing can cause real problems with timeouts if your project is say a PIR detector for intrusion that needs to function quickly. So, the google thing was pretty useful, but only until GMT can be converted to local. But I still need to look at these in any case. THX
<p>Great and simple project. Also works fine with NodeMCU.</p><p>==&gt; Data to I2C SDA (GPIO 0 ==&gt; NodeMCU D3)</p><p>==&gt; Clock to I2C SCL (GPIO 2 ==&gt;NodeMCU D4)</p><p>// Clk to I2C SCL (GPIO 2 ==&gt;D4)</p>
<p>Nice, thank you for searing with us...</p>
<p>Very nice work and simple!!!!</p><p>It would be nice if you could add some simple things like: dim the display according to ambient light (at night display could be too bright) and turn on the display only when needed (e.g. to save battery life). </p><p>That would ad just a few components (a LDR, a simple momentary switch, an IR sensor for distance -sensing the waive of hand or a mic -make a noise awaken the display). </p><p>The clock will still be simple and compact. </p><p>Anyway, very nice work!</p>
<p>Dimming those OLEDs is possible but the effect almost unnoticeable. A bigger issue is the digits burning into it like we had with the CRT monitors in the olden days.<br>Turning off the wifi after getting the date, that's something to consider, also reducing how often the time is pulled (currently every minute, that's far too often)</p>
<p>Turning off the display when not needed (avoiding &quot;CRT like effect&quot;) and turning off wifi would be nice to be implemented. </p><p>Maibe in an upgrade or future project?</p>
<p>Yes, the 'improved' version would have a proper clock object to count seconds/minutes/hours using the internal microcontroller and then only sync the time with the server every few hours (or less?) But while the current code is not as efficient as it's constantly connected, it is simpler. But yes, in the future I want to add the 'offline' functionality somehow. I'll have to look into OLED burn-in effects as I haven't had much experience on that front</p>
<p>Maybe move the data around on the screen to avoid burn in.</p>
<p>Michael, it already has a &quot;proper clock object&quot;, that's why you are calling timeClient.update() which keeps time according to the accuracy of the micro and only refreshens from the ntp server every NTP_INTERVAL seconds.</p>
<p>Right! I've been playing with it and yes, I will be changing the sync interval to a lot longer so the connection doesn't get used so much</p>
<p>Correct me if I am wrong, but this looks like it requires a constant Internet connection to get the time to display, right?</p>
<p>Yes. You could change it and only connect it as you like but currently it pulls the time through the UDP connection every 10 seconds.</p>
<p>So correction: it keeps the UDP port open for syncing but you can set sync interval to be way more than 10 seconds - the time client object keeps track of time between syncs</p>
<p>That said, you would have to change the code somewhat since currently it checks whether the connection is open every 10 seconds and only displays time if it is</p>
<p>Suggestion. Maybe add a I2C - RTC $1 on eBay. Change the code to read the RTC and update display. and then hit NTP server and update RTC every 6 hours over the inet.<br>Just a suggestion.</p><p>Jeff</p>
<p>Thank you for sharing!<br>You may be interested to have a look in my project concerning timezones as it was a nightmare for me :)<a href="" rel="nofollow"> https://github.com/gabrielklein/SensorNode<br></a></p><p>src/core/ITime and src/core/TZTime are two functions you may be interested in.<br>I have moved to PlatformIO instead of Arduino IDE (easier to develop).</p><p></p>
<p>I bought these NodeMCU V3 that simplify the development on the ESP8266 :)</p><p>https://www.aliexpress.com/item/1PCS-Wireless-module-CH340-NodeMcu-V3-Lua-WIFI-Internet-of-Things-development-board-based-ESP8266/32665100123.html</p>
<p>Very nice and simple project.<br>Could you add sketch for 24-hour format?</p>
<p>It's just a few simple changes as you can see here: <a href="https://gist.github.com/TomK32/1fcdd03d0eb08fddf024ff257a11bb52/revisions" rel="nofollow">https://gist.github.com/TomK32/1fcdd03d0eb08fddf02...</a><br><br>This is the file you can copy and try out. https://gist.github.com/TomK32/1fcdd03d0eb08fddf024ff257a11bb52/46227eb68c22a4fba30f7bab59b20eb5510b5ed3</p>
<p>Thanks, time is now displayed in a 24-hour format.</p>

About This Instructable




More by MichaelB247:Simplest ESP8266 Local Time Internet Clock With OLED ESP8266 ESP-01 Programming Jig Adding Daylight Savings Time to Your RTC 
Add instructable to: