Close Menu
Circuit of Things
  • Home
  • About Us
  • Contact Us
  • 3D Print
  • Shop Now !
  • Projects
    • Raspberry Pi Projects
    • Arduino Projects
    • ESP8266 Projects
    • ESP32 Projects
    • IoT Tutorials
    • Sensors & Modules
    • IoT Basics
  • KSP Tools

Get Free Tutorials & Discounts!

Subscribe for the latest IoT tutorials and exclusive KSP Electronics discount codes.

Instagram WhatsApp
  • Terms and Conditions
  • Disclaimer
  • Privacy Policy
  • Contact Us
Circuit of Things Circuit of Things
  • Home
  • About Us
  • Contact Us
  • 3D Print
  • Shop Now !
  • Projects
    • Raspberry Pi Projects
    • Arduino Projects
    • ESP8266 Projects
    • ESP32 Projects
    • IoT Tutorials
    • Sensors & Modules
    • IoT Basics
  • KSP Tools
Hire us
Circuit of Things
Home»ESP32 Projects»Build an ESP32 DHT11 Webserver for Real-Time Temperature and Humidity Monitoring
ESP32 Projects

Build an ESP32 DHT11 Webserver for Real-Time Temperature and Humidity Monitoring

Sai Preetham KoyyalaBy Sai Preetham KoyyalaDecember 9, 2024Updated:May 7, 2026No Comments5 Mins Read
Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
Share
Facebook Twitter LinkedIn Pinterest Email
Showing 1 of 1

Monitoring environmental conditions like temperature and humidity is a key component of many IoT projects. In this tutorial, we’ll walk you through creating a simple yet powerful ESP32 DHT11 webserver. This project allows you to track temperature and humidity data from anywhere via a web browser, making it ideal for home automation, greenhouses, and more.

Contents
  • Why Choose ESP32 and DHT11?
  • Materials Needed for the Project
  • Circuit Diagram: ESP32 with DHT11 Sensor
  • Setting Up the ESP32 in Arduino IDE
  • Programming the ESP32 Webserver
  • Testing Your ESP32 DHT11 Webserver
  • Recommended Tools and Accessories

Why Choose ESP32 and DHT11?

The ESP32 is a versatile microcontroller with built-in Wi-Fi and Bluetooth capabilities, making it perfect for IoT applications. Coupled with the DHT11 sensor, which measures temperature and humidity efficiently, this duo offers an affordable and scalable solution for environmental monitoring.

Materials Needed for the Project

Before diving into the setup, gather the following components. You can purchase these through the provided links to ensure you get the best products:

  • ESP32 Development Board – Affordable and powerful IoT microcontroller with built-in Wi-Fi.
  • DHT11 Temperature and Humidity Sensor – Reliable sensor for measuring environmental conditions.
  • Jumper Wires – Essential for connecting components securely.
  • Breadboard – Simplifies circuit assembly and testing.
  • USB Cable – For programming and powering the ESP32.
  • A computer with Arduino IDE installed (free software).

Pro Tip: Purchasing components as a kit, like this IoT Starter Kit, can save you time and money.

Circuit Diagram: ESP32 with DHT11 Sensor

Steps to Connect the Components

  1. Connect the VCC pin of the DHT11 to the 3.3V pin of the ESP32.
  2. Connect the GND pin of the DHT11 to the GND of the ESP32.
  3. Attach the DATA pin of the DHT11 to GPIO4 (or any other GPIO pin) on the ESP32.
  4. Use a pull-up resistor (4.7k–10k ohms) between the DATA and VCC pins for stability.

Setting Up the ESP32 in Arduino IDE

For this tutorial, we’ll program the ESP32 board using the Arduino core. So, make sure you have the ESP32 add-on installed in your Arduino IDE:

  • Installing the ESP32 Board in Arduino IDE (Windows, Mac OS X, Linux)
  1. Go to Tools > Board > Boards Manager, search for ESP32, and install it.
  2. Install the following libraries via Sketch > Include Library > Manage Libraries:
  • DHT sensor library by Adafruit.
  • Adafruit Unified Sensor.

Programming the ESP32 Webserver

Sample Code for ESP32 DHT11 Webserver

Copy CodeCopiedUse a different Browser
#include <WiFi.h>
#include <WebServer.h>
#include <DHT.h>

// WiFi Configuration
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";

// DHT11 Sensor Configuration
#define DHT_PIN 4        // GPIO pin connected to DHT11 data line
#define DHTML_TYPE DHT11 // DHT 11 sensor type

// Create DHT sensor object
DHT dht(DHT_PIN, DHTML_TYPE);

// Create web server object on port 80
WebServer server(80);

void setup() {
  // Initialize serial communication
  Serial.begin(115200);
  
  // Initialize DHT sensor
  dht.begin();
  
  // Connect to WiFi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  
  // Print local IP address
  Serial.println("WiFi Connected");
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());
  
  // Define server routes
  server.on("/", handleRoot);
  server.on("/temperature", handleTemperature);
  server.on("/humidity", handleHumidity);
  
  // Start server
  server.begin();
}

void loop() {
  // Handle client requests
  server.handleClient();
  delay(100);
}

// Root page handler
void handleRoot() {
  // Read temperature and humidity
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();
  
  // Create HTML response
  String html = "<!DOCTYPE html>"
                "<html>"
                "<head>"
                "<title>ESP32 DHT11 Monitor</title>"
                "<meta http-equiv='refresh' content='5'>"
                "<style>"
                "body { font-family: Arial, sans-serif; text-align: center; }"
                "h1 { color: #333; }"
                ".reading { font-size: 2em; margin: 20px; }"
                "</style>"
                "</head>"
                "<body>"
                "<h1>ESP32 Temperature and Humidity Monitor</h1>";
  
  // Check if reading is valid
  if (isnan(temperature) || isnan(humidity)) {
    html += "<p>Failed to read from DHT sensor!</p>";
  } else {
    html += "<div class='reading'>Temperature: " + String(temperature, 1) + " °C</div>"
            "<div class='reading'>Humidity: " + String(humidity, 1) + " %</div>";
  }
  
  html += "<p>Last Updated: " + String(millis()/1000) + " seconds ago</p>"
          "</body>"
          "</html>";
  
  // Send HTML response
  server.send(200, "text/html", html);
}

// Temperature endpoint
void handleTemperature() {
  float temperature = dht.readTemperature();
  
  if (isnan(temperature)) {
    server.send(500, "text/plain", "Error reading temperature");
  } else {
    server.send(200, "text/plain", String(temperature, 1));
  }
}

// Humidity endpoint
void handleHumidity() {
  float humidity = dht.readHumidity();
  
  if (isnan(humidity)) {
    server.send(500, "text/plain", "Error reading humidity");
  } else {
    server.send(200, "text/plain", String(humidity, 1));
  }
}

Testing Your ESP32 DHT11 Webserver

  1. Upload the code to your ESP32 using Arduino IDE.
  2. Open the Serial Monitor to find the ESP32’s IP address.
  3. Enter the IP address in a browser to view the temperature and humidity data.

Recommended Tools and Accessories

Make your IoT project smoother with these highly rated accessories:

  • Multimeter – Test your connections and troubleshoot circuits.
  • Soldering Kit – For making durable, permanent connections.
  • Power Supply Module – Provides reliable power for your ESP32 and sensor.

What is the range of the DHT11 sensor?

The DHT11 can measure temperatures between 0–50°C and humidity levels from 20–90%.

Can I use DHT22 instead of DHT11?

Yes, the DHT22 offers higher accuracy and a broader range. Check out the u003cstrongu003eu003ca href=u0022https://kspelectronics.in/product/dht11-humidity-temperature-sensor-with-pcbu0022 data-type=u0022linku0022 data-id=u0022https://kspelectronics.in/product/dht11-humidity-temperature-sensor-with-pcbu0022u003eDHT22 sensor hereu003c/au003eu003c/strongu003e.

How do I make the webserver accessible over the internet?

You can configure u003cstrongu003eport forwardingu003c/strongu003e on your router or use an IoT platform like u003cstrongu003eu003ca href=u0022https://thingspeak.com/u0022u003eThingSpeaku003c/au003eu003c/strongu003e.

Is this setup suitable for outdoor monitoring?

For outdoor use, ensure the components are housed in a u003cstrongu003eu003cau003eweatherproof enclosureu003c/au003eu003c/strongu003e.

Conclusion

Congratulations! You’ve successfully built an ESP32 DHT11 webserver to monitor temperature and humidity. This project is a stepping stone to more advanced IoT systems. Consider enhancing it with features like data logging or integrating it with platforms like Blynk for mobile app monitoring.

Ready to get started? Order your components now:

  • ESP32 Development Board
  • DHT11 Sensor
  • IoT Starter Kit

Related Tutorials

  • ESP32 vs Raspberry Pi Pico W: Which One Should You Choose for Your Next IoT Project? (2025 Ultimate Comparison Guide)
  • An Introduction to the ESP32 Development Board
  • ESP32 OTA Updates: Program Your Board Over Wi-Fi with Arduino IDE
Showing 1 of 1
Arduino Project esp8266 esp8266-01 pinout pinout projects
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Previous ArticleHow to Install Arduino IDE on Windows and Mac: Step-by-Step Guide with ESP32, ESP8266 Integration and CH340 Driver Setup
Next Article ESP32 vs Raspberry Pi Pico W: Which One Should You Choose for Your Next IoT Project? (2025 Ultimate Comparison Guide)
Sai Preetham Koyyala
  • Website
  • Facebook
  • X (Twitter)
  • Instagram
  • LinkedIn

Hello, I am Sai Preetham Koyyala. I'm an electronics engineer by profession, a DIY enthusiast by passion. ESP32 and Arduino are the main topics of my work.

Related Posts

ESP32 Projects

Step-by-Step Guide: Interface DHT11 and DHT22 Sensors with ESP32

May 6, 2026
ESP32 Projects

An Introduction to the ESP32 Development Board

May 6, 2026
ESP32 Projects

The Complete ESP32 Pinout Guide: Which Pins to Use?

May 6, 2026
Add A Comment

Comments are closed.

⚡

Circuit of Things

Free IoT tutorials & electronics projects — powered by KSP Electronics.

📸 Instagram 💬 Community
✓ Official Partner Store

Everything for Your
Next IoT Build

Boards, sensors, modules & kits — fast delivery across India.

ESP32 Arduino Sensors Raspberry Pi 3D Print
🛒 Shop KSP Electronics →
Top Posts

Raspberry Pi: How to Control a DC Motor with L298N and PWN on a Web Server

July 14, 2023

Step-by-Step Guide: Interface DHT11 and DHT22 Sensors with ESP32

May 6, 2026

Esp8266 / NodeMCU Pinout: A Comprehensive Guide for Beginners

June 25, 2023
Available for Projects

Hire Us for IoT Development

End-to-end solutions for your needs:

  • → ESP32 & Embedded Systems
  • → LoRaWAN & Cloud Dashboards
  • → Custom Hardware Design
  • → IoT Product Prototyping
View Services →

Get Free Tutorials & Discounts!

Subscribe to get the latest IoT tutorials and exclusive hardware discount codes for KSP Electronics delivered directly to your inbox.

Follow Us
  • Instagram
  • Telegram
About Circuit of Things

We are a community-driven engineering platform dedicated to IoT, Robotics, and DIY electronics tutorials.

Proudly partnered with KSP Electronics.

Quick Links
  • Home
  • ESP32 Projects
  • Arduino Projects
  • IoT Tutorials
  • Sensors & Modules
  • Shop on KSP Electronics
  • Electro Calc
Legal & Support
  • Terms and Conditions
  • Disclaimer
  • Privacy Policy
  • Contact Us
📩

Get Free Tutorials & Discounts!

Subscribe for IoT tutorials and exclusive KSP discount codes.

Subscription Form


By subscribing, you agree to our Privacy Policy. No spam, ever.

X (Twitter) Instagram YouTube WhatsApp
  • Terms and Conditions
  • Disclaimer
  • Privacy Policy
  • Contact Us
© 2026 Circuit of Things. Designed by Sai Preetham Koyyala.

Type above and press Enter to search. Press Esc to cancel.