ESP8266 NodeMCU Tutorial | NTP Client & 0.96 OLED Display with Time Based Automation (Without RTC)

ESP8266 NodeMCU NTP client tutorial with 0.96-inch OLED display for real-time clock and time-based automation

Have you ever wanted to build a clock that’s always accurate to the second without the hassle of real-time clock modules? Or perhaps you’re intrigued by time-triggered DIY automations? Well, you’re in for a treat.

Hello and welcome back to Maisonup! Today, we’re diving into an exciting project that eliminates the need for RTC modules. We’ll be using the NodeMCU and NTP (Network Time Protocol) to create a real-time clock display.

In this tutorial, we’ll guide you through harnessing the power of the NodeMCU and NTP to fetch the precise time from the internet, display it on a small OLED screen, and trigger an example automation at a specific time of the day. Let’s jump in and discover how you can achieve this impressive feat!

Getting Started: Components You’ll Need

To embark on this journey, you’ll need the following components:

NodeMCU – ESP8266 module

0.96 OLED display

Small LED or buzzer for time-triggered automation

If you’re new to the world of ESP8266, we recommend watching our “Getting Started” video before proceeding. It will help lay the foundation with this powerful microcontroller.

Setting Up the Development Environment

Let’s start by setting up our development environment. You’ll need the trusted Arduino IDE and the ESP8266 board package. Don’t worry if you’re new to this—I’ll guide you through the installation process step by step.

1. Install Arduino IDE: If you don’t have the Arduino IDE installed, download it from the Arduino website and install it on your computer.

2. Install the ESP8266 Board:

• Open the Arduino IDE, go to “File” > “Preferences.”

• In the “Additional Board Manager URLs” field, paste the following link:

http://arduino.esp8266.com/stable/package_esp8266com_index.json

• Go to “Tools” > “Board” > “Boards Manager.” Search for ESP8266 and click Install.

3. Install Required Libraries:

• You’ll need to install the following libraries: ‘ESP8266WiFi,’ ‘NTPClient,’ ‘WiFiUdp,’ and ‘Adafruit_SSD1306’ for the OLED display.

• You can also install these as Zip libraries by downloading them from the above provided links.

Wiring and Hardware Connections

With the software side covered, let’s move on to the hardware. Follow the provided wiring diagram to make the connections:

• Connect your ESP8266 to the internet via WiFi.

• Hook up the OLED display to the ESP8266 to elegantly showcase the current time and date fetched from the NTP servers.

And the best part? No RTC modules required!

Diving Into the Code

Now, let’s dive into the code.

1. Include the Necessary Libraries:

• We start by including libraries like ESP8266WiFi for WiFi connectivity, NTPClient for accessing the NTP server, WiFiUdp for UDP communication, and Adafruit_SSD1306 for controlling the OLED display.

2. Setup Constants and Variables:

• Define your WiFi credentials, pin numbers for the LED or buzzer, activation and deactivation times, and arrays for days and months.

3. Initialize the OLED Display:

• Use the Adafruit_SSD1306 library to initialize the OLED display. This will be our window to show real-time information.

4. WiFi Connection Handling:

• The wifiConnect function handles connecting the ESP8266 to a WiFi network, with the OLED display updating the connection status.

5. Fetching and Displaying Time:

• The clockDisplay function fetches time from an NTP server using timeClient and displays it on the OLED screen in a 12-hour format.

6. Time-Triggered Automation:

• The deviceActivation function checks the current time against predefined activation and deactivation times. If the time falls within the range, the LED or buzzer is activated; otherwise, it’s deactivated.

7. Adding Creative Flair:

• Add an extra layer of creativity by making text scroll across the OLED display. The textScroll function controls the scrolling behavior, making it a fantastic way to display additional information, greetings, or messages in your projects.

8. Setup Function:

• In the setup function, initialize the display, configure pins for the LED and buzzer, connect to WiFi, start the NTPClient, and set the initial state of the LED based on the current time.

9. Loop Function:

• The loop function handles the core logic. It updates the clock, scrolls the text, and checks the device activation state. If the state changes, the buzzer briefly activates.

Uploading the Code

Now, it’s time to upload the code. Ensure that you’ve selected the correct board and port, and that the module is connected to your computer. Once uploaded, you’ll witness the LED and buzzer activation and deactivation as programmed.

Wrap Up

There you have it, fellow creators! With the ESP8266 and NTP by your side, you’ve learned how to craft a real-time clock display without the need for RTC modules. This opens doors to endless possibilities—from enhancing smart home automation to personalizing countdowns and event reminders. The complete code and resources are available for you in the section below:

Thanks for tuning in, and remember, the future is now—so let’s create something incredible!

Watch Complete Video on YouTube
Categories :
Share This :

Leave a Reply

Your email address will not be published. Required fields are marked *

Search Post

Recent Post