Weather clock
A clock that shows the time, the forecast and a UV warning from an online API.
Build it step by step
0 of 7 doneTest the OLED
Run the library's example first.
Add Wi-Fi and time
Print the time on the screen.
Find your coordinates
Use a map to get your latitude and longitude.
Fetch the forecast
Print the temperature to the serial monitor.
Draw the pages
Show the clock with weather or UV below it.
Add the light sensor
Dim the display in a dark room.
Fit a frame
Mount the board behind a photo frame mat.
How do you build a weather clock?
A clock that shows the time, the forecast and a UV warning from an online API. You need ESP32 DevKit V1, SSD1306 OLED Display, LDR Photoresistor, Resistor 10 kΩ, Tactile push button 6 mm and 5 V 2 A USB adapter. It takes 7 steps and about 150 minutes.
- Level
- Beginner
- Time
- About 150 min
- Parts
- 6
Parts list
- Development BoardsBuyESP32 DevKit V1 × 1
- DisplaysBuy
- SensorsBuy
- PassivesBuyResistor 10 kΩ × 1
- SwitchesBuy
- PowerBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| OLED VCC | ESP32 3V3 | Power |
| OLED GND | ESP32 GND | Ground |
| OLED SDA | ESP32 GPIO21 | I2C data |
| OLED SCL | ESP32 GPIO22 | I2C clock |
| LDR one leg | ESP32 3V3 | Top of the light divider |
| LDR other leg and 10 kΩ resistor | GPIO34, resistor to GND | Light level for dimming |
| Button | GPIO27 and GND | Switches the page |
| 5 V adapter | ESP32 USB | Power |
Code
The forecast comes from Open-Meteo, a free service that needs no key. Put your own latitude and longitude in and fill in the Wi-Fi placeholders yourself, keeping them out of shared code. setInsecure() skips the certificate check, which is acceptable for a display that only shows public weather but is a trade-off; do not copy it into a project that sends private data. The UV advice follows the common World Health Organization bands and is general guidance, not medical advice. Arduino IDE with the ESP32 boards package, board "ESP32 Dev Module".
Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Weather clock: NTP time plus Open-Meteo forecast. Libraries: Adafruit SSD1306, Adafruit GFX, ArduinoJson (v7).
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <time.h>
const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";
const char* LAT = "12.97"; // your latitude
const char* LON = "77.59"; // your longitude
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
float tempNow = 0, uvMax = 0; int code = 0; bool haveData = false;
byte page = 0;
unsigned long lastFetch = 0, lastBtn = 0;
const char* codeText(int c) {
if (c == 0) return "Clear";
if (c <= 3) return "Cloudy";
if (c <= 48) return "Fog";
if (c <= 67) return "Rain";
if (c <= 77) return "Snow";
if (c <= 82) return "Showers";
return "Storm";
}
void fetchWeather() {
WiFiClientSecure client;
client.setInsecure(); // trade-off: skips the certificate check, fine for a weather display
HTTPClient http;
String url = String("https://api.open-meteo.com/v1/forecast?latitude=") + LAT + "&longitude=" + LON +
"¤t=temperature_2m,weather_code&daily=uv_index_max&timezone=auto&forecast_days=1";
if (!http.begin(client, url)) return;
if (http.GET() == 200) {
JsonDocument doc;
if (!deserializeJson(doc, http.getString())) {
tempNow = doc["current"]["temperature_2m"];
code = doc["current"]["weather_code"];
uvMax = doc["daily"]["uv_index_max"][0];
haveData = true;
}
}
http.end();
}
void setup() {
pinMode(27, INPUT_PULLUP);
Wire.begin(21, 22);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
oled.setTextColor(SSD1306_WHITE);
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) delay(300);
configTime(19800, 0, "pool.ntp.org"); // 19800 s = UTC+5:30, change for your zone
fetchWeather(); lastFetch = millis();
}
void loop() {
if (millis() - lastFetch > 900000UL) { fetchWeather(); lastFetch = millis(); } // every 15 minutes
if (!digitalRead(27) && millis() - lastBtn > 300) { page = (page + 1) % 2; lastBtn = millis(); }
int light = analogRead(34); // bright = high reading
oled.dim(light < 600); // dim the display in a dark room
struct tm t;
oled.clearDisplay();
if (getLocalTime(&t, 100)) {
char hm[8]; strftime(hm, sizeof(hm), "%H:%M", &t);
oled.setTextSize(3); oled.setCursor(10, 0); oled.print(hm);
}
oled.setTextSize(1);
if (!haveData) { oled.setCursor(0, 40); oled.print("Fetching forecast..."); }
else if (page == 0) {
oled.setCursor(0, 36); oled.print(codeText(code));
oled.setTextSize(2); oled.setCursor(0, 48); oled.print(tempNow, 1); oled.print(" C");
} else {
oled.setTextSize(2); oled.setCursor(0, 40); oled.print("UV "); oled.print(uvMax, 0);
oled.setTextSize(1); oled.setCursor(0, 56);
oled.print(uvMax >= 8 ? "Very high: cover up" : uvMax >= 6 ? "High: sunscreen" : uvMax >= 3 ? "Moderate" : "Low");
}
oled.display();
delay(200);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Power on | Time appears within seconds |
| Button press | Switches between weather and UV |
| Cover the LDR | Display dims |
| Switch the router off | Clock keeps time, forecast stays at the last value |
If it does not work
Time is wrong by hours
Change the offset in configTime for your zone.
Forecast never arrives
Check the coordinates and the Wi-Fi password.
JSON errors
Install ArduinoJson version 7 or change the code for version 6.
Display stays blank
Check address 0x3C with an I2C scanner.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the weather clock?
ESP32 DevKit V1, SSD1306 OLED Display, LDR Photoresistor, Resistor 10 kΩ, Tactile push button 6 mm and 5 V 2 A USB adapter.
How long does the weather clock take to build?
About 150 minutes for a beginner maker, in 7 steps.
How do I know the weather clock works?
Power on: Time appears within seconds. Button press: Switches between weather and UV. Cover the LDR: Display dims.
Time is wrong by hours: what should I check?
Change the offset in configTime for your zone.
Forecast never arrives: what should I check?
Check the coordinates and the Wi-Fi password.
JSON errors: what should I check?
Install ArduinoJson version 7 or change the code for version 6.
Display stays blank: what should I check?
Check address 0x3C with an I2C scanner.
