Close Menu
Circuit of Things
  • Home
  • Projects
    • Raspberry Pi Projects
    • Arduino Projects
    • ESP8266 Projects
    • ESP32 Projects
  • About Us
  • Get In Touch
  • 3D Print
  • Shop Now !
  • Electro Calc

Subscribe to Updates

Get the latest creative news from FooBar about art, design and business.

Instagram WhatsApp
  • Terms and Conditions
  • Disclaimer
  • Privacy Policy
Circuit of ThingsCircuit of Things
  • Home
  • Projects
    • Raspberry Pi Projects
    • Arduino Projects
    • ESP8266 Projects
    • ESP32 Projects
  • About Us
  • Get In Touch
  • 3D Print
  • Shop Now !
  • Electro Calc
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:December 9, 2024No 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 DHT22 sensor here.

How do I make the webserver accessible over the internet?

You can configure port forwarding on your router or use an IoT platform like ThingSpeak.

Is this setup suitable for outdoor monitoring?

For outdoor use, ensure the components are housed in a weatherproof enclosure.

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

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

ESP8266 Projects

ESP8266-01 Pinout: A Comprehensive Guide to Pin Configuration

June 25, 2023
ESP8266 Projects

Esp8266 / NodeMCU Pinout: A Comprehensive Guide for Beginners

June 25, 2023
Arduino Projects

Get Started with Arduino: A Beginner’s Guide to the World of Electronics

June 7, 2023
Add A Comment
Leave A Reply Cancel Reply

skillshare
Hire me
saipreetham0
Fiverr
Seller
As a skilled and experienced freelancer, I offer a range of services to help clients achieve their goals. I have a strong background in computer science and engineering and am proficient in a variety of programming languages and frameworks. I have experience in building custom websites, mobile apps, and IoT solutions and am always looking for new challenges. I value open communication and collaboration with my clients and am dedicated to meeting deadlines and ensuring high-quality work. If you are looking for a reliable and skilled freelancer, please don't hesitate to contact me. Thank you.
Top Posts

ESP8266-01 Pinout: A Comprehensive Guide to Pin Configuration

June 25, 2023

Get Started with Arduino: A Beginner’s Guide to the World of Electronics

June 7, 2023

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

July 14, 2023
Stay In Touch
  • Telegram

Subscribe to Updates

Get the latest tech news from FooBar about tech, design and biz.

Most Popular

ESP8266-01 Pinout: A Comprehensive Guide to Pin Configuration

June 25, 2023

Get Started with Arduino: A Beginner’s Guide to the World of Electronics

June 7, 2023

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

July 14, 2023
Our Picks

ESP32 vs Raspberry Pi Pico W: Which One Should You Choose for Your Next IoT Project? (2025 Ultimate Comparison Guide)

May 9, 2025

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

December 9, 2024

How to Install Arduino IDE on Windows and Mac: Step-by-Step Guide with ESP32, ESP8266 Integration and CH340 Driver Setup

December 7, 2024

Subscribe to Updates

Get the latest creative news from FooBar about art, design and business.

X (Twitter) Instagram YouTube WhatsApp
  • Book an Appointment
  • My Bookings
  • Support Us
© 2025 Circuit of Things. Designed by Sai Preetham Koyyala.

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