WS2812 Ring LED Clock With NTP Server Using ESP32

Yeah, maybe you can consider it as a Hari Raya clock!

Introduction

Previously, I have shared on how to make NTP clock using dot matrix and ESP32. So, this time I would like to display on WS2812 ring LED. Maybe you can consider it as a Hari Raya clock! Before that, please read the following tutorial first.

Video

This video shows how to create ring LED clock with NTP server using ESP32.

Hardware Preparation

This is the list of items used in the video.

Sample Program

This is the sample program to create ring LED clock with NTP server using ESP32. Before that, you need to install 3 libraries:

  • NeoPixelBus by Micheal C. Miller V2.5.7 (Manager)
  • NTPClient by Fabrice Weinberg Version 3.1.0 (ZIP file)
/*
Project: WS2812 Ring LED clock with NTP server using ESP32
Board: ESP32 Dev Module (Node32 Lite)
Connections:
ESP32 | OLED Strip
RAW – VCC
GND – GND
25 – DIN
External libraries:
– NeoPixelBus by Micheal C. Miller V2.5.7 (Manager)
– NTPClient by Fabrice Weinberg V3.1.0 (Zip)
https://github.com/taranais/NTPClient/archive/master.zip
*/
#include <WiFi.h>
#include <WiFiClient.h>
const char ssid[] = "Your WiFi SSID"; // WiFi name
const char password[] = "Your WiFi Password"; // WiFi password
#include <NTPClient.h>
#include <WiFiUdp.h>
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
#include <NeoPixelBrightnessBus.h>
#define PIN 25
#define NUMPIXELS 60
NeoPixelBrightnessBus<NeoGrbFeature, Neo800KbpsMethod> strip(NUMPIXELS, PIN);
long currentMillis = 0;
long previousMillis = 0;
int interval = 1000;
String formattedDate;
int hour, minute, second;
int hour1, hour2, hour3;
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
strip.Begin();
strip.SetBrightness(5);
clockSegment();
strip.Show();
timeClient.begin();
timeClient.setTimeOffset(28800); // Set offset time in seconds, GMT+8 = 28800
}
void loop()
{
while (!timeClient.update()) {
timeClient.forceUpdate();
}
currentMillis = millis();
if (currentMillis – previousMillis > interval) {
previousMillis = millis();
// Clear all leds
strip.SetPixelColor(hour, RgbColor(0, 0, 0));
strip.SetPixelColor(hour+1, RgbColor(0, 0, 0));
strip.SetPixelColor(hour+2, RgbColor(0, 0, 0));
strip.SetPixelColor(hour+3, RgbColor(0, 0, 0));
strip.SetPixelColor(hour+4, RgbColor(0, 0, 0));
strip.SetPixelColor(minute, RgbColor(0, 0, 0));
strip.SetPixelColor(second, RgbColor(0, 0, 0));
strip.Show();
// The formattedDate comes with the following format:
// 2018-05-28T16:00:13Z
formattedDate = timeClient.getFormattedDate();
Serial.println(formattedDate);
// Extract time
hour = formattedDate.substring(11, 13).toInt();
minute = formattedDate.substring(14, 16).toInt();
second = formattedDate.substring(17, 19).toInt();
if (hour > 11) {
hour = hour – 12;
}
hour = (hour * 5) + (minute / 12);
hour1 = hour;
if (hour == 59) {
hour2 = hour – 1;
hour3 = 0;
}
else if (hour == 0) {
hour2 = 59;
hour3 = hour + 1;
}
else {
hour2 = hour – 1;
hour3 = hour + 1;
}
clockSegment();
strip.SetPixelColor(second, RgbColor(0, 0, 255));
strip.SetPixelColor(hour1, RgbColor(255, 0, 0));
strip.SetPixelColor(hour2, RgbColor(255, 0, 0));
strip.SetPixelColor(hour3, RgbColor(255, 0, 0));
strip.SetPixelColor(minute, RgbColor(0, 255, 0));
strip.Show();
}
}
RgbColor DimWhite(50, 50, 50);
void clockSegment()
{
strip.SetPixelColor(0, DimWhite);
strip.SetPixelColor(5, DimWhite);
strip.SetPixelColor(10, DimWhite);
strip.SetPixelColor(15, DimWhite);
strip.SetPixelColor(20, DimWhite);
strip.SetPixelColor(25, DimWhite);
strip.SetPixelColor(30, DimWhite);
strip.SetPixelColor(35, DimWhite);
strip.SetPixelColor(40, DimWhite);
strip.SetPixelColor(45, DimWhite);
strip.SetPixelColor(50, DimWhite);
strip.SetPixelColor(55, DimWhite);
}

Thank You

References:

Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.

Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for better application.

2 thoughts on “WS2812 Ring LED Clock With NTP Server Using ESP32”

  1. Daniel Fernandes

    I don’t know what’s wrong because I loaded the sketch correctly in an ESP32 NodeMCU and, when I turn on the circuit, they randomly turn on and off some LEDs. (the 60 LEDs on the strip do not light) I used an external 5v source for the LED strip and the ESP32 I plug in the USB. Any tips? I also left this comment on YouTube
    Thanks

  2. Whilst upload I get error

    Arduino: 1.8.12 (Windows 10), Board: “ESP32 Wrover Module, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), QIO, 80MHz, 921600, None”

    C:\Users\Surface\Documents\Arduino\Led60clock\Led60clock.ino: In function ‘void loop()’:

    Led60clock:87:32: error: ‘class NTPClient’ has no member named ‘getFormattedDate’

    formattedDate = timeClient.getFormattedDate();

    ^

    Multiple libraries were found for “WiFi.h”
    Used: C:\Users\Surface\AppData\Local\Arduino15\packages\esp32-husarnet\hardware\esp32\1.0.5\libraries\WiFi
    Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
    exit status 1
    ‘class NTPClient’ has no member named ‘getFormattedDate’

    Invalid library found in C:\Program Files (x86)\Arduino\libraries\MakeSpaceTitle_LEDMatrix: no headers files (.h) found in C:\Program Files (x86)\Arduino\libraries\MakeSpaceTitle_LEDMatrix
    Invalid library found in C:\Users\Surface\Documents\Arduino\libraries\LED_matrix: no headers files (.h) found in C:\Users\Surface\Documents\Arduino\libraries\LED_matrix
    Invalid library found in C:\Users\Surface\Documents\Arduino\libraries\Matrix_LED_12816_PK: no headers files (.h) found in C:\Users\Surface\Documents\Arduino\libraries\Matrix_LED_12816_PK
    Invalid library found in C:\Program Files (x86)\Arduino\libraries\MakeSpaceTitle_LEDMatrix: no headers files (.h) found in C:\Program Files (x86)\Arduino\libraries\MakeSpaceTitle_LEDMatrix
    Invalid library found in C:\Users\Surface\Documents\Arduino\libraries\LED_matrix: no headers files (.h) found in C:\Users\Surface\Documents\Arduino\libraries\LED_matrix
    Invalid library found in C:\Users\Surface\Documents\Arduino\libraries\Matrix_LED_12816_PK: no headers files (.h) found in C:\Users\Surface\Documents\Arduino\libraries\Matrix_LED_12816_PK

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

Design 3D Model Using TinkerCAD and Print
3D Print Lithophane for Hari Raya Aidilfitri
With Raspberry Pi Imager, you can write Raspberry Pi OS and remote SSH easier
3D Printing Pelita Raya
How to use MAKERDISK M.2 SSD on Raspberry Pi 4 Model B
Tutorials of Cytron Technologies Scroll to Top