What you will build
A desk monitor that shows temperature (°C) and relative humidity (%) on a small screen, and serves a live dashboard you can open on any phone or laptop on the same Wi-Fi at http://xbot-climate.local.
How it works
The SHT31 sensor and the OLED share the I²C bus (two wires: SDA on GPIO 21, SCL on GPIO 22), each with its own address. Every 2 seconds the ESP32 reads the sensor, draws the values on the OLED, and stores them. A tiny web server on the ESP32 answers two requests: / returns the dashboard page, /data returns the latest reading as JSON, which the page fetches every 2 seconds.
Parts
| Part | Qty | Purpose | Required |
|---|---|---|---|
| ESP32-DevKitC V4 + breadboard + USB cable | 1 | Controller + Wi-Fi | Yes |
| SHT31 breakout (I²C, 3.3 V) | 1 | Temperature + humidity | Yes |
| 0.96" SSD1306 OLED, 128×64, I²C | 1 | Local display | Yes |
| Jumper wires | 8 | Connections | Yes |
| 2.4 GHz Wi-Fi network | — | Dashboard | Yes |
We use the SHT31 only (not DHT22): it is more accurate, shares the I²C bus and keeps wiring identical to the Playground.
Build steps
- Connect both modules to the same rails: VIN/VCC → 3V3, GND → GND, SDA → GPIO 21, SCL → GPIO 22.
- In Arduino IDE Library Manager, install Adafruit SHT31, Adafruit SSD1306 and Adafruit GFX (accept dependencies).
- Create a tab named
secrets.hwith your Wi-Fi name and password (see code). Never publish this file. - Upload. Open the Serial Monitor at 115200 baud and wait for
Dashboard: http://xbot-climate.local. - Checkpoint: the OLED shows plausible values (e.g. 18–26 °C indoors). Breathe on the sensor: humidity rises within seconds.
- Open the address on your phone. If
.localdoes not resolve (some Android phones), use the IP address printed in the Serial Monitor.
Try it in the browser
Demo Mode. The dashboard runs on the project page with sample data labelled Simulated. Sliders change temperature and humidity so you can see how the OLED and dashboard react. Playground Simulation of the sensor + OLED uses the same sketch with a virtual SHT31.
Open Simulator PlaygroundCode
// secrets.h — keep private, do not commit
#define WIFI_SSID "your-network"
#define WIFI_PASS "your-password"
Download smart-room-climate-monitor.ino
// Smart Room Climate Monitor — XBOTNOW
// Board: ESP32-DevKitC V4 · Core: esp32 v3.x
// Libraries: Adafruit SHT31, Adafruit SSD1306, Adafruit GFX
#include <WiFi.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <Wire.h>
#include <Adafruit_SHT31.h>
#include <Adafruit_SSD1306.h>
#include "secrets.h"
Adafruit_SHT31 sht;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
WebServer server(80);
float tempC = NAN, hum = NAN;
unsigned long lastRead = 0;
const char PAGE[] PROGMEM = R"HTML(
<!doctype html><meta name=viewport content="width=device-width">
<title>Room climate</title>
<body style="font-family:sans-serif;text-align:center;padding:2em">
<h2>Room climate</h2><p style="font-size:3em"><span id=t>--</span> °C</p>
<p style="font-size:3em"><span id=h>--</span> %</p><small id=s>Live hardware</small>
<script>
setInterval(async()=>{try{const d=await (await fetch('/data')).json();
t.textContent=d.ok?d.t.toFixed(1):'err';h.textContent=d.ok?d.h.toFixed(0):'err';}
catch(e){s.textContent='Connection lost';}},2000);
</script>)HTML";
void handleData() {
bool ok = !isnan(tempC) && !isnan(hum);
String json = String("{\"ok\":") + (ok ? "true" : "false") +
",\"t\":" + (ok ? String(tempC, 2) : "null") +
",\"h\":" + (ok ? String(hum, 1) : "null") + "}";
server.send(200, "application/json", json);
}
void setup() {
Serial.begin(115200);
Wire.begin(21, 22);
if (!sht.begin(0x44)) Serial.println("SHT31 not found");
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) Serial.println("OLED not found");
oled.setTextColor(SSD1306_WHITE);
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) { delay(300); Serial.print('.'); }
MDNS.begin("xbot-climate");
Serial.printf("\nDashboard: http://xbot-climate.local (%s)\n", WiFi.localIP().toString().c_str());
server.on("/", [] { server.send_P(200, "text/html", PAGE); });
server.on("/data", handleData);
server.begin();
}
void loop() {
server.handleClient();
if (millis() - lastRead < 2000) return;
lastRead = millis();
tempC = sht.readTemperature(); // NAN on failure
hum = sht.readHumidity();
oled.clearDisplay();
oled.setTextSize(2);
oled.setCursor(0, 8);
if (isnan(tempC)) oled.print("Sensor err");
else { oled.printf("%.1f C", tempC); oled.setCursor(0, 40); oled.printf("%.0f %%", hum); }
oled.display();
}
Troubleshooting
| Symptom | Likely cause | Check |
|---|---|---|
| "SHT31 not found" | Wrong address or wiring | Some boards use 0x45; run an I²C scanner sketch |
| OLED blank | Address 0x3D | Change 0x3C to 0x3D |
| Stuck printing dots | Wrong password or 5 GHz network | ESP32 supports 2.4 GHz only |
| Temperature 2–3 °C too high | Heat from the ESP32 | Move the sensor 5 cm away on wires |
Safety and limitations
Educational monitor only: not calibrated, not a life-safety, medical or mould-assessment instrument. The dashboard has no password; only use it on your own home network.
Checklist
Next project
Plant Moisture Monitor: same OLED and Wi-Fi skills, now for your plants.

