Arka Manna
Published © CC BY

Wi-Fi Clock & Message Board Using ESP8266 + LED Matrix

A Smart Clock & Message Display that switches between real-time and real talk — all controlled from your phone. No fancy App

BeginnerFull instructions provided1 hour241
Wi-Fi Clock & Message Board Using ESP8266 + LED Matrix

Things used in this project

Hardware components

max7219 dot matrix display
×1
Adafruit Feather HUZZAH with ESP8266 WiFi
Adafruit Feather HUZZAH with ESP8266 WiFi
×1
Jumper wires (generic)
Jumper wires (generic)
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1

Software apps and online services

Arduino Web Editor
Arduino Web Editor

Story

Read more

Code

CODE

Arduino
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <WiFiUdp.h>
#include <NTPClient.h>

// WiFi credentials
const char* ssid = "********************";
const char* password = "****************";

// LED Matrix setup
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CS_PIN 15

MD_Parola display = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

// Time client
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", 19800, 60000); // IST offset

// Web server
ESP8266WebServer server(80);

// Mode and message
enum Mode { MODE_CLOCK, MODE_CUSTOM };
Mode currentMode = MODE_CLOCK;
String customMessage = "Hello it's me ARKA";

// Function to show IP address on boot
void showIP(IPAddress ip) {
  char ipPart[6];
  for (int i = 0; i < 4; i++) {
    sprintf(ipPart, "%d", ip[i]);
    display.displayClear();
    display.displayText(ipPart, PA_CENTER, 100, 0, PA_PRINT, PA_NO_EFFECT);
    display.displayAnimate();
    delay(1500);
  }
}

// Webpage HTML
String htmlPage = R"rawliteral(
<!DOCTYPE html>
<html>
<head><title>LED Control</title></head>
<body>
  <h2>ESP8266 LED Matrix Control</h2>
  <form action="/setMessage">
    <label>Enter Message:</label><br>
    <input type="text" name="message"><br><br>
    <input type="submit" value="Set Message">
  </form><br>
  <a href="/clock"><button>Clock Mode</button></a>
  <a href="/custom"><button>Custom Message Mode</button></a>
</body>
</html>
)rawliteral";

// Routes
void handleRoot() {
  server.send(200, "text/html", htmlPage);
}

void handleSetMessage() {
  if (server.hasArg("message")) {
    customMessage = server.arg("message");
    currentMode = MODE_CUSTOM;
  }
  server.send(200, "text/html", htmlPage);
}

void handleClock() {
  currentMode = MODE_CLOCK;
  server.send(200, "text/html", htmlPage);
}

void handleCustom() {
  currentMode = MODE_CUSTOM;
  server.send(200, "text/html", htmlPage);
}

void setup() {
  display.begin();
  display.setIntensity(5);
  display.displayClear();

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    display.print("WiFi..");
    delay(500);
  }

  showIP(WiFi.localIP());

  timeClient.begin();

  server.on("/", handleRoot);
  server.on("/setMessage", handleSetMessage);
  server.on("/clock", handleClock);
  server.on("/custom", handleCustom);
  server.begin();
}

void loop() {
  static unsigned long lastColonToggle = 0;
  static bool colonVisible = true;

  server.handleClient();

  if (currentMode == MODE_CLOCK) {
    timeClient.update();
    int h = timeClient.getHours();
    int m = timeClient.getMinutes();

    if (millis() - lastColonToggle >= 1000) {
      lastColonToggle = millis();
      colonVisible = !colonVisible;

      char displayTime[6];
      sprintf(displayTime, "%02d%c%02d", h, colonVisible ? ':' : ' ', m);

      display.displayClear();
      display.displayText(displayTime, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
      display.displayAnimate();
    }
  } else if (currentMode == MODE_CUSTOM) {
    display.displayClear();
    display.displayScroll(customMessage.c_str(), PA_CENTER, PA_SCROLL_LEFT, 100);
    while (!display.displayAnimate()) delay(10);
  }

  delay(100);
}

Credits

Arka Manna
4 projects • 2 followers
Contact

Comments

Please log in or sign up to comment.