ESP32 temperature and humidity web dashboard with a DHT22: design worksheet and code

A ₹760 design worksheet for a DHT22 weather node on an ESP32 that serves a live page and a JSON feed, with a one-hour history buffer and a worked dew-point table.

About the author · Editorial & verification standards

  • Parts₹760
  • Bench time2–4 h
  • LevelBeginner
  • ReviewedNov 2026

A ₹760 room monitor that shows temperature, humidity and dew point on a web page you open from any phone on your Wi-Fi. A DHT22 sensor is read every 30 seconds, the last hour of readings is kept in memory, and a JSON address lets other tools read the same data.

Scope: beginner. This is a design worksheet with illustrative costs. It has not been bench-tested by this site. The dew-point table was computed by script from the Magnus formula. DHT22 accuracy is often listed as about ±0.5 °C and a few percent of humidity, which is fine for comfort and not for calibration work. The Wi-Fi name and password in the sketch are placeholders for your own.

How it works

The DHT22 can only be read about once every 2 seconds, so the sketch reads it every 30 seconds and stores the result in a ring buffer of 120 entries, which covers one hour. Each entry is two floats of 4 bytes, so the whole buffer is about 960 bytes, which is small for an ESP32.

Dew point is the temperature at which the air would be saturated. The Magnus formula with constants b = 17.62 and c = 243.12 °C gives γ = ln(RH/100) + b × T / (c + T) and the dew point as c × γ / (b − γ). It is a useful number because condensation forms on surfaces colder than it.

Bill of materials

PartQtyUnitTotal
ESP32 development board1₹450₹450
DHT22 module (with pull-up resistor)1₹200₹200
Breadboard1₹60₹60
Jumper wires1₹50₹50
Parts total₹760

Scroll the table sideways to see every column.

Prices checked Nov 2026. Shipping and tools are not included.

Prices are illustrative figures for Indian sellers in November 2026, before shipping, and have not been checked against current listings.

The numbers

Air temperatureHumidityDew point
35 °C40%19.4 °C
30 °C60%21.4 °C
25 °C50%13.9 °C
20 °C80%16.4 °C
15 °C90%13.4 °C
Computed with the Magnus formula (b = 17.62, c = 243.12 °C); results are approximate and fine for comfort use.

When the dew point is within a degree or two of the temperature of a cold surface, such as a window or a cold water pipe, condensation is likely there. That is why dew point is more useful than relative humidity for spotting damp problems.

Power and wiring

PartConnects toNote
DHT22 VCC3V3Check your module’s voltage range
DHT22 GNDGND
DHT22 DATAGPIO 4A 10 kΩ pull-up to VCC is needed; most modules include one
Keep the sensor away from the ESP32 board, which warms up and skews the temperature reading.

The sketch

// ESP32 DHT22 web dashboard: live page + JSON + one-hour history
// Design worksheet: set your Wi-Fi name and password.

#include <WiFi.h>
#include <WebServer.h>
#include <DHT.h>

const char* WIFI_NAME = "your-wifi";
const char* WIFI_PASS = "your-password";

const int DHT_PIN = 4;
DHT dht(DHT_PIN, DHT22);
WebServer server(80);

const int N = 120;                 // 120 x 30 s = 1 hour
float temps[N], hums[N];
int head = 0, filled = 0;
unsigned long lastRead = 0;
const unsigned long READ_MS = 30000UL;

float dewPoint(float t, float rh) {
  const float b = 17.62, c = 243.12;
  float g = log(rh / 100.0) + b * t / (c + t);
  return c * g / (b - g);
}

void handleData() {
  int last = (head + N - 1) % N;
  char out[120];
  if (filled == 0) {
    snprintf(out, sizeof(out), R"({"ready":false})");
  } else {
    snprintf(out, sizeof(out), R"({"ready":true,"t":%.1f,"h":%.1f,"dew":%.1f,"samples":%d})",
             temps[last], hums[last], dewPoint(temps[last], hums[last]), filled);
  }
  server.send(200, "application/json", out);
}

const char PAGE[] PROGMEM = R"(
<!doctype html><meta name=viewport content="width=device-width,initial-scale=1">
<h1>Room</h1><p id=v>waiting for the first reading...</p>
<script>
async function u(){
  try{
    const d=await (await fetch('/data')).json();
    document.getElementById('v').textContent=d.ready?
      d.t+' C, '+d.h+' % humidity, dew point '+d.dew+' C':'waiting for the first reading...';
  }catch(e){}
}
u(); setInterval(u,5000);
</script>
)";

void setup() {
  Serial.begin(115200);
  dht.begin();
  WiFi.begin(WIFI_NAME, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print('.'); }
  Serial.println(WiFi.localIP());
  server.on("/", []() { server.send_P(200, "text/html", PAGE); });
  server.on("/data", handleData);
  server.begin();
}

void loop() {
  server.handleClient();
  if (millis() - lastRead >= READ_MS || lastRead == 0) {
    lastRead = millis();
    float h = dht.readHumidity(), t = dht.readTemperature();
    if (!isnan(h) && !isnan(t)) {
      temps[head] = t; hums[head] = h;
      head = (head + 1) % N;
      if (filled < N) filled++;
    }
  }
}

The sketch keeps the history but only serves the latest reading; a chart of the one-hour buffer is a natural next step. If the board prints a long run of dots, check the Wi-Fi name and that the network is 2.4 GHz, since the ESP32 does not use 5 GHz Wi-Fi. The sketch has been proofread but not compiled on this site.

Test plan

  1. Sensor check: compare the temperature with a reliable thermometer in the same spot for ten minutes.
  2. Humidity sanity check: breathe near the sensor and watch the humidity rise and fall back.
  3. Dew point: compare a few readings with the table above.
  4. JSON: open the data address from a phone and a laptop on the same network.
  5. Long run: leave it a day and see that it keeps responding.
  6. Placement: move the sensor away from the board and see how the temperature changes.

What usually goes wrong

SymptomLikely causeFix
NaN readingsWiring or missing pull-upCheck the data pin and pull-up resistor
Temperature reads highSensor next to the warm boardMove the sensor out on a short lead
Cannot connect to Wi-Fi5 GHz network or wrong passwordUse a 2.4 GHz network
Page shows waiting foreverNo valid reading yetWait 30 seconds or check the sensor
Readings stallRead too oftenKeep to one reading every 2 seconds or slower

Upgrades

  • History chart: add a /history address and draw a line chart.
  • MQTT: publish readings to a broker or Home Assistant.
  • Deep sleep: wake every few minutes to run on a battery.
  • Second sensor: add outdoor readings for comparison.

Cost and parts notes

The ₹760 total is an illustration and does not include shipping. Use the cost calculator to compare sellers.

Common questions

Why is the DHT22 read only every 30 seconds?

The sensor cannot be read more often than about once every 2 seconds, and room conditions change slowly.

What is dew point?

The temperature at which the air would become saturated. Surfaces colder than that collect condensation.

How accurate is a DHT22?

Listings often quote about ±0.5 °C and a few percent humidity. Treat it as good for comfort, not for measurement.

Can I use a DHT11?

Yes, with DHT11 in the constructor, but it is less precise and has a narrower range.

Last reviewed: November 2026. This is a design worksheet with illustrative costs. It has not been bench-tested by this site; library names, pins and limits must be checked against your board and the current library versions, and measurements from your build are welcome.

More builds

Next builds to try

Free: the final-year project pack

A shortlist with BOMs, a report outline that matches the usual chapter scheme, a costing sheet and 40 viva questions. Built for the February–April submission season.

The Build Note

One short email when something is worth your bench time.

A new build sheet, a part price that moved, or a mistake worth avoiding. No daily drip, no recycled news.

One short email when a build or a price is worth your time. Unsubscribe in one click.