How to Make an ESP32 Wi-Fi Weather Station with DHT22/DHT11 and a Live Dashboard

Complete DIY STEM and IoT project guide

Project overview

Problem with ESP32-Wroom when connected to DHT22-Sensor - 3rd Party Boards - Arduino Forum

An ESP32 Wi-Fi Weather Station is an affordable Internet of Things (IoT) project that measures temperature and relative humidity and displays the readings on a live web dashboard. It uses an ESP32 development board and either a DHT11 or DHT22 sensor.

The dashboard can be opened using a smartphone, tablet, or computer connected to the same Wi-Fi network.

1. Project objectives

  • Measure temperature and humidity using a digital sensor.
  • Connect the ESP32 to a Wi-Fi network.
  • Create a live web dashboard.
  • Display environmental readings on a smartphone or computer.
  • Explore IoT applications in agriculture, schools, homes, and environmental monitoring.

2. Components and materials required

Mini Kit ESP32 Básico sem Caixa Organizadora - AutoCore Robótica - Arduino em Fortaleza, você encontra aqui!
ComponentQuantityPurpose
ESP32 DevKit1Main controller and Wi-Fi communication
DHT22 sensor1Temperature and humidity measurement
DHT11 sensor1Alternative lower-cost sensor
Breadboard1Circuit assembly
Jumper wiresSeveralElectrical connections
10 kΩ resistor1Pull-up resistor for bare sensor
USB cable1Programming and power
Wi-Fi router or hotspot1Wireless network
Smartphone or computer1Dashboard access

Only one sensor is needed: either DHT11 or DHT22.

DHT11 versus DHT22

FeatureDHT11DHT22
Temperature range0–50°C-40–80°C
Temperature accuracyApproximately ±2°CApproximately ±0.5°C
Humidity range20–80% RH0–100% RH
Humidity accuracyApproximately ±5% RHApproximately ±2–5% RH
CostLowerHigher

The DHT22 is recommended where better measurement accuracy and a wider operating range are required.

3. Completed ESP32 Wi-Fi weather station

ESP32 Temperature & Humidity Web Server with DHT22 Sensor - ESP32 DIY Kit | TecnoMate

The completed prototype consists of an ESP32 board connected to a DHT sensor. The ESP32 reads the environmental data and makes it available through a web server.

4. ESP32 and DHT22/DHT11 circuit connections

DHT22 sensor wire length with ESP32? - Page 2 - Hardware - Home Assistant Community

Connect the sensor as follows:

DHT sensor pinESP32 connection
VCC3V3
DATAGPIO 4
GNDGND

For a bare four-pin DHT sensor, connect a 10 kΩ pull-up resistor between DATA and VCC. Many three-pin sensor modules already include this resistor.

Important: ESP32 GPIO pins use 3.3 V logic. Do not apply 5 V to the GPIO pins.

5. System block diagram

ESP32 Mini Gateway - BLE Sensor Node - IoTLabs Maker

The system operates through the following stages:

  • The DHT sensor measures temperature and humidity.
  • The sensor sends digital data to the ESP32.
  • The ESP32 processes the measurements.
  • The ESP32 hosts a local web server.
  • A smartphone or computer accesses the ESP32 IP address.
  • The dashboard displays updated readings.

6. Installing the required software

Use the Arduino IDE to program the ESP32.

Download Arduino IDE: https://www.arduino.cc/en/software

Install ESP32 board support:

  • Open Arduino IDE.
  • Navigate to File → Preferences.
  • Add this URL under Additional Boards Manager URLs:
https://espressif.github.io/arduino-esp32/package_esp32_index.json
  • Open Tools → Board → Boards Manager.
  • Search for ESP32 and install the package by Espressif Systems.
  • Select the appropriate ESP32 board.

Install these libraries using Library Manager:

  • DHT sensor library by Adafruit
  • Adafruit Unified Sensor

7. ESP32 Wi-Fi weather station Arduino code

The code below reads the sensor and displays the measurements on a live web dashboard.

Replace the Wi-Fi name and password with your own credentials.

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

const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_WIFI_PASSWORD";

#define DHTPIN 4
#define DHTTYPE DHT22
// Change DHT22 to DHT11 if using DHT11

DHT dht(DHTPIN, DHTTYPE);
WebServer server(80);

float temperature = 0;
float humidity = 0;

unsigned long previousMillis = 0;
const unsigned long interval = 2500;

const char webpage[] PROGMEM = R"rawliteral(
<!DOCTYPE html>
<html>
<head>
<title>ESP32 Weather Station</title>
<meta name="viewport"
content="width=device-width, initial-scale=1">

<style>
body {
  font-family: Arial;
  background: #eef3f8;
  text-align: center;
  padding: 20px;
}

.container {
  max-width: 650px;
  margin: auto;
}

.card {
  background: white;
  padding: 25px;
  margin: 18px 0;
  border-radius: 14px;
  box-shadow: 0 3px 12px #0002;
}

.value {
  font-size: 42px;
  font-weight: bold;
  color: #0879bd;
}

.label {
  color: #555;
  font-size: 18px;
}

.status {
  color: green;
  font-weight: bold;
}
</style>
</head>

<body>
<div class="container">

<h1>ESP32 Wi-Fi Weather Station</h1>
<p>Live Environmental Monitoring</p>

<div class="card">
  <div class="label">Temperature</div>
  <div class="value" id="temperature">-- °C</div>
</div>

<div class="card">
  <div class="label">Relative Humidity</div>
  <div class="value" id="humidity">-- %</div>
</div>

<p class="status" id="status">Connecting...</p>
<p id="updated">Waiting for readings</p>

</div>

<script>
async function updateData() {
  try {
    const response = await fetch('/data');
    if (!response.ok) throw new Error('Network error');

    const data = await response.json();

    document.getElementById('temperature').innerText =
      data.temperature + ' °C';

    document.getElementById('humidity').innerText =
      data.humidity + ' %';

    document.getElementById('status').innerText =
      'Sensor connected';

    document.getElementById('updated').innerText =
      'Last updated: ' + new Date().toLocaleTimeString();

  } catch (error) {
    document.getElementById('status').innerText =
      'Unable to retrieve readings';
  }
}

updateData();
setInterval(updateData, 3000);
</script>
</body>
</html>
)rawliteral";

void handleRoot() {
  server.send_P(200, "text/html", webpage);
}

void handleData() {
  String json = "{";
  json += "\"temperature\":" + String(temperature, 1) + ",";
  json += "\"humidity\":" + String(humidity, 1);
  json += "}";

  server.send(200, "application/json", json);
}

void setup() {
  Serial.begin(115200);
  dht.begin();

  WiFi.begin(ssid, password);

  Serial.print("Connecting to Wi-Fi");

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println();
  Serial.println("Wi-Fi connected!");

  Serial.print("Dashboard address: http://");
  Serial.println(WiFi.localIP());

  server.on("/", handleRoot);
  server.on("/data", handleData);

  server.begin();
}

void loop() {
  server.handleClient();

  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;

    float newHumidity = dht.readHumidity();
    float newTemperature = dht.readTemperature();

    if (!isnan(newHumidity) && !isnan(newTemperature)) {
      humidity = newHumidity;
      temperature = newTemperature;

      Serial.print("Temperature: ");
      Serial.print(temperature);
      Serial.print(" °C | Humidity: ");
      Serial.print(humidity);
      Serial.println(" %");
    } else {
      Serial.println("DHT sensor reading failed!");
    }
  }
}

For DHT11, change:

#define DHTTYPE DHT22

to:

#define DHTTYPE DHT11

8. Live web dashboard

Web Based Weather Station With ESP32 And DHT11 Sensor - ArduinoYard

The dashboard displays temperature, relative humidity, sensor status, and the time of the latest browser update.

The JavaScript function retrieves new measurements from the ESP32 /data endpoint every three seconds. The ESP32 reads the sensor approximately every 2.5 seconds.

9. Uploading and accessing the dashboard

  • Connect the ESP32 to your computer using a USB cable.
  • Open the Arduino IDE and paste the code.
  • Enter your Wi-Fi credentials.
  • Select the correct ESP32 board and COM port.
  • Click Verify, then Upload.
  • Open the Serial Monitor at 115200 baud.
  • Wait for the ESP32 to connect to Wi-Fi.
  • Copy the IP address displayed.
  • Open that address in a browser on a phone or computer connected to the same Wi-Fi network.

For example, the address may look like:

http://192.168.1.105

The actual address depends on the network.

Network limitation: This version provides a local dashboard. Remote access outside the local network requires additional secure networking or cloud integration.

10. Testing and evaluation

Tutorial Web Server ESP32 + DHT22 — Monitoring Suhu via Browser — Koding Indonesia
TestProcedureExpected result
Sensor testPower the ESP32Temperature and humidity appear
Wi-Fi testConnect to the networkESP32 obtains an IP address
Dashboard testOpen IP addressDashboard loads
Temperature testCompare with reference thermometerReadings are reasonably close
Humidity testCompare with reference hygrometerReadings are reasonably close
Refresh testObserve dashboardValues update automatically

Record actual measurements during testing rather than assuming a particular accuracy.

11. Construction and installation

Wetterstation mit ESP32 | Elektor Magazine

For outdoor use, place the electronics in a weather-resistant enclosure and mount the DHT sensor in a ventilated radiation shield. Keep the sensor away from direct sunlight, rain, and heat sources to obtain more representative ambient measurements.

12. Applications

  • Smart agriculture: Monitor greenhouse temperature and humidity.
  • Poultry farming: Observe environmental conditions inside poultry houses.
  • Schools: Demonstrate IoT, sensors, and wireless communication.
  • Smart homes: Monitor indoor environmental conditions.
  • Storage facilities: Monitor conditions in rooms storing sensitive materials.

13. Possible project improvements

How to Build a Smart Weather Station with Sensors? - Blog - Ampheo
UpgradeComponentFunction
Atmospheric pressureBMP280/BME280Measures air pressure
Light monitoringBH1750Measures light intensity
Rain detectionRain sensorDetects rainfall
Wind speedAnemometerMeasures wind speed
Cloud storageThingSpeakStores readings online
Historical graphsChart.jsDisplays measurement trends
Local displayOLED screenDisplays readings on the device

14. Troubleshooting

How to Fix Common ESP32 Upload and Connection Errors

ProblemPossible solution
ESP32 not detectedUse a data USB cable and check the USB driver
Upload failureSelect the correct board and hold BOOT if required
Wi-Fi not connectingCheck credentials and use a compatible 2.4 GHz network
DHT returns NaNCheck wiring, sensor type, and pull-up resistor
Dashboard not openingConfirm the IP address and same Wi-Fi network

15. STEM and CBE learning outcomes

Learners develop practical skills in:

  • Scientific investigation through environmental measurement.
  • Electronics and sensor connections.
  • Programming using Arduino IDE.
  • Wireless communication and IoT.
  • Data collection, analysis, and interpretation.
  • Engineering design and problem-solving.
  • Development of solutions to agricultural and environmental challenges.

16. Conclusion

The ESP32 Wi-Fi Weather Station is an affordable and practical IoT project that demonstrates how sensors, microcontrollers, wireless communication, and web technologies can be integrated into an environmental monitoring system.

Using an ESP32 and a DHT11 or DHT22 sensor, learners can measure temperature and humidity and display the results on a live dashboard. The system can later be expanded into a smart agriculture or remote environmental monitoring platform.

  • mbeva

    Dominic Mbeva is a science teacher, experienced researcher, innovator, and creative technologist with expertise in STEM education, digital media, and scientific research. As a Kenya Science and Engineering Fair (KSEF) advisor and projects manager, he mentors young scientists, guiding them in developing award-winning innovations. He is also an IC Technorat, leading advancements in science and technology. Beyond education, Dominic is a skilled photographer and video editor, using visual storytelling to make science more engaging. His philosophy, “If you take care of minutes, hours will take care of themselves,” reflects his belief in consistent effort, strategic thinking, and innovation to drive success in both research and creativity.

    Related Posts

    How to make Water Tank Level Monitoring System Using ESP32 and Ultrasonic Sensor

    Meta Description: Learn how to build a smart water tank level monitoring system using ESP32 and an ultrasonic sensor. Measure water levels, monitor tank capacity and receive real-time updates through…

    Read more

    RFID Smart Attendance System Using Arduino and Google Sheets (Cloud-Based Attendance Monitoring)

    RFID Smart Attendance System Using Arduino and Google Sheets (Cloud-Based Attendance Monitoring) Meta description: Learn how to build an RFID smart attendance system using Arduino, an RFID RC522 reader, ESP8266…

    Read more

    Leave a Reply

    Your email address will not be published. Required fields are marked *