Community project

Weather Display Clock

Photo of Weather Display Clock

Rob

Published December 5, 2026

This project builds a networked weather display clock using an ESP32 microcontroller and a 4-inch display. The device connects to WiFi, fetches real-time weather data from Open-Meteo, and shows the current time, temperature, and weather conditions. It automatically adjusts for local time zones and daylight saving time based on the user's geographic location.

The guide provides a complete parts list, wiring diagram for connecting the display to the ESP32, and ready-to-deploy firmware. Setup takes just a few minutes: position the 4-inch display, connect the components, upload the code, and configure WiFi credentials and location coordinates through a simple web interface.

Wiring diagram

Wiring diagram for Weather Display Clock
Loading diagram…

Assemble it in 2 steps

1. Position the 4-inch display

Use the Hosyond 4.0-inch ESP32 resistive touchscreen board. Place it screen-up on a non-conductive surface. No external wiring is needed.

2. Connect and deploy

Connect the board to your computer with a data-capable USB cable and press Deploy. Join CYD-Clock with password clocksetup, then open http://192.168.4.1 to set Wi-Fi and location.

Deploy the firmware

#include <Arduino.h>
#include <Arduino_GFX_Library.h>
#include <ArduinoJson.h>
#include <WiFi.h>
#include <WebServer.h>
#include <HTTPClient.h>
#include <Preferences.h>
#include <time.h>
Preferences prefs;
WebServer server(80);
Arduino_DataBus *bus;
Arduino_GFX *gfx;
String ssid, pass, lat, lon;
String weather="Waiting for weather", status="", previous;
String forecast[3];
long utcOffset=0;
bool validWeather=false;
uint32_t lastFetch=0, lastRetry=0, rebootAt=0;
const char PAGE[] PROGMEM=R"HTML(<!doctype html><meta name="viewport" content="width=device-width"><title>CYD Clock</title><h2>Clock setup</h2><p>Outdoor weather from Open-Meteo. Use your location's latitude and longitude (from a map). Local time and daylight saving follow weather updates.</p><form method="post" action="/save">Wi-Fi name<br><input name="ssid" required maxlength="32"><br>Wi-Fi password<br><input name="pass" type="password" maxlength="64"><br>Latitude (-90 to 90)<br><input name="lat" type="number" step="any" min="-90" max="90" required><br>Longitude (-180 to 180)<br><input name="lon" type="number" step="any" min="-180" max="180" required><br><button>Save and restart</button></form><p>Setup network password: clocksetup</p>)HTML";
String conditions(int code){
 if(code==0)return "Clear sky";
 if(code<=3)return "Cloudy";
 if(code<=48)return "Fog";
 if(code<=57)return "Drizzle";
 if(code<=67)return "Rain";
 if(code<=77)return "Snow";
 if(code<=82)return "Rain showers";
 if(code<=86)return "Snow showers";
 return "Thunderstorms";
}
void fetchWeather(){
 lastFetch=millis();
 if(WiFi.status()!=WL_CONNECTED){status="Wi-Fi offline";return;}
 HTTPClient http;
 // Public, non-sensitive weather data; HTTP avoids an unverified TLS connection.
 String url="http://api.open-meteo.com/v1/forecast?latitude="+lat+"&longitude="+lon+"&current=temperature_2m,relative_humidity_2m,apparent_temperature,weather_code&daily=weather_code,temperature_2m_max,temperature_2m_min&forecast_days=4&timezone=auto&temperature_unit=fahrenheit";
 http.setTimeout(5000);http.begin(url);
 int result=http.GET();
 if(result==200){
 JsonDocument doc;
 auto err=deserializeJson(doc,http.getString());
 if(!err && doc["current"]["temperature_2m"].is<float>()){
 utcOffset=doc["utc_offset_seconds"] | 0L;
 auto c=doc["current"];
 weather=conditions(c["weather_code"] | 0)+"\n";
 weather+="Temp "+String(c["temperature_2m"].as<float>(),1)+" F  RH "+String(c["relative_humidity_2m"].as<int>())+"%\n";
 weather+="Feels "+String(c["apparent_temperature"].as<float>(),1)+" F\n";
 auto d=doc["daily"];
 for(int i=0;i<3;i++){
  int day=i+1; // Skip today: the current conditions are already on screen.
  const char *date=d["time"][day] | "";
  auto hi=d["temperature_2m_max"][day];
  auto lo=d["temperature_2m_min"][day];
  auto code=d["weather_code"][day];
  if(strlen(date)==10 && hi.is<float>() && lo.is<float>() && code.is<int>()){
   forecast[i]=String(date+5)+"  "+String(hi.as<float>(),0)+"/"+String(lo.as<float>(),0)+" F  "+conditions(code.as<int>());
  }else forecast[i]="Forecast unavailable";
 }
 validWeather=true;status="Weather updated";
 }else status="Weather error / old data";
 }else status="Weather unavailable / old data";
 http.end();
}
// The onboard 100k/100k divider feeds half the cell voltage to GPIO34.
int batteryBars=-1;
bool batteryHigh=false;
bool showBatteryBolt=false;
void sampleBattery(){
 static uint32_t last=0;
 if(last && millis()-last<5000)return;
 last=millis();
 uint32_t sum=0;
 for(int i=0;i<16;i++)sum+=analogReadMilliVolts(34);
 const uint32_t mv=sum/8;
 // Rough voltage bands, not a fuel gauge or charge-complete detector.
 const bool valid=mv>=2800 && mv<=4350;
 if(valid){
  if(mv>=4000)batteryHigh=true;
  else if(mv<=3500)batteryHigh=false;
 }
 showBatteryBolt=valid && !batteryHigh;
 digitalWrite(22, showBatteryBolt ? LOW : HIGH);
 digitalWrite(17, valid && batteryHigh ? LOW : HIGH);
 batteryBars=!valid ? -1 : mv>=4000 ? 4 : mv>=3850 ? 3 : mv>=3700 ? 2 : mv>=3500 ? 1 : 0;
}
void render(){
 time_t now=time(nullptr);
 String clock="--:--", date="Waiting for internet time";
 if(now>1700000000 && validWeather){
 now+=utcOffset; struct tm local;gmtime_r(&now,&local);
 char buf[40];strftime(buf,sizeof(buf),"%H:%M",&local);clock=buf;
 strftime(buf,sizeof(buf),"%a %d %b %Y",&local);date=buf;
 }
 sampleBattery();
 String state=String(batteryBars)+":"+String(showBatteryBolt)+":"+clock+date+weather+status+String(WiFi.status());
 for(const auto &row:forecast)state+="\n"+row;
 if(state==previous)return;previous=state;
 gfx->fillScreen(0x0841);gfx->setTextColor(0x07FF);gfx->setTextWrap(false);
 gfx->setTextSize(10);gfx->setCursor(90,12);gfx->print(clock);
 gfx->setTextColor(0xFFFF);gfx->setTextSize(2);gfx->setCursor((480-date.length()*12)/2,98);gfx->print(date);
 gfx->setTextColor(0xFFE0);gfx->setTextSize(3);gfx->setCursor(55,125);gfx->print(weather);
 if(validWeather){
  gfx->setTextColor(0xA7F4);gfx->setTextSize(2);
  for(int i=0;i<3;i++){gfx->setCursor(12,201+22*i);gfx->print(forecast[i]);}
 }
 gfx->setTextColor(0xA7F4);gfx->setTextSize(2);gfx->setCursor((480-status.length()*12)/2,274);gfx->print(status);
 gfx->setTextColor(0xC65F);gfx->setCursor(66,300);gfx->print("Setup: CYD-Clock / 192.168.4.1");
 if(batteryBars>=0){
  gfx->drawRect(438,8,30,14,0xC65F);
  gfx->fillRect(468,12,3,6,0xC65F);
  for(int i=0;i<batteryBars;i++)gfx->fillRect(441+6*i,11,5,8,0xA7F4);
 }
 if(showBatteryBolt){
  gfx->fillTriangle(429,7,420,16,427,16,0xFFE0);
  gfx->fillTriangle(424,23,433,14,426,14,0xFFE0);
 }
 gfx->flush();
}
void setup(){
 // Common-anode RGB: HIGH turns a channel off.
 pinMode(16, OUTPUT);
 digitalWrite(16, HIGH);
 pinMode(17, OUTPUT);
 digitalWrite(17, HIGH);
 pinMode(22, OUTPUT);
 digitalWrite(22, HIGH); // Wait for a valid voltage reading.
 Serial.begin(115200);prefs.begin("clock",false);
 ssid=prefs.getString("ssid","");pass=prefs.getString("pass","");lat=prefs.getString("lat","");lon=prefs.getString("lon","");
 // Deselect touch before using the shared SPI bus. LCD reset shares ESP32 EN.
 pinMode(33,OUTPUT);digitalWrite(33,HIGH);
 pinMode(27,OUTPUT);digitalWrite(27,LOW);
 bus=new Arduino_ESP32SPI(2,15,14,13,12);
 auto display=new Arduino_ST7796(bus,-1,1);
 if(!display->begin(27000000)){Serial.println("Display initialization failed");return;}
 gfx=display;
 WiFi.mode(WIFI_AP_STA);WiFi.softAP("CYD-Clock","clocksetup");
 if(ssid.length())WiFi.begin(ssid.c_str(),pass.c_str());
 server.on("/",[]{server.send_P(200,"text/html",PAGE);});
 server.on("/save",HTTP_POST,[]{
 String a=server.arg("lat"),b=server.arg("lon");
 if(!server.arg("ssid").length() || !a.length() || !b.length() || a.toFloat() < -90 || a.toFloat()>90 || b.toFloat() < -180 || b.toFloat()>180){server.send(400,"text/plain","Check Wi-Fi name and coordinates.");return;}
 prefs.putString("ssid",server.arg("ssid"));prefs.putString("pass",server.arg("pass"));prefs.putString("lat",a);prefs.putString("lon",b);
 server.send(200,"text/plain","Saved. Restarting. Reconnect to your usual Wi-Fi, or CYD-Clock to change setup.");rebootAt=millis()+1200;
 });
 server.begin();status=ssid.length()?"Connecting to Wi-Fi":"Join CYD-Clock: clocksetup";
 weather="Outdoor weather clock\nJoin CYD-Clock Wi-Fi\nPassword: clocksetup\nOpen 192.168.4.1\nSet Wi-Fi and location";
 render();
 digitalWrite(27,HIGH);
}
void loop(){
 if(!gfx){delay(1000);return;}
 server.handleClient();
 if(rebootAt && (int32_t)(millis()-rebootAt)>=0)ESP.restart();
 if(ssid.length() && WiFi.status()!=WL_CONNECTED && millis()-lastRetry>30000){lastRetry=millis();WiFi.reconnect();status="Wi-Fi offline; retrying";}
 static bool timeStarted=false;
 if(!timeStarted && WiFi.status()==WL_CONNECTED){
  configTime(0,0,"pool.ntp.org","time.nist.gov");
  timeStarted=true;
 }
 if(lat.length() && WiFi.status()==WL_CONNECTED && (lastFetch==0 || millis()-lastFetch>600000))fetchWeather();
 render();delay(10);
}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik