ESP32-C3 SuperMini DHT11 Tutorial - Temperature & Humidity Sensor with MicroPython Web Server

By Nuno Bispo
7 min read

Table of Contents

Have you ever looked at a smart home dashboard and thought, “I could build this myself”? That itch to tinker, to understand what’s really going on behind the scenes, is what pulled me into building my own home monitoring setup from scratch.

I wanted a simple way to collect real environmental data using my own sensors, my own hardware, and my own code; no cloud dependency, no black boxes. So I started small. Using an ESP32-C3 SuperMini and a humble DHT11 temperature and humidity sensor, I built a tiny Wi-Fi-enabled node that reports real-time readings over serial and serves them through a minimal web interface.

This article is a follow-up to Getting Started with ESP32-C3 SuperMini and MicroPython. We’ll extend that foundation by adding a DHT11 sensor, reading data via GPIO, and exposing those readings both in the serial console and on a lightweight web server running directly on the ESP32.

By the end of this guide, you’ll know how to:

  • Wire a DHT11 to the ESP32-C3 SuperMini
  • Read temperature and humidity values using MicroPython
  • View live sensor data in the REPL / Serial Monitor
  • Run a tiny built-in web server for real-time readings
  • Use this setup as a building block for a DIY home-automation system

What You Need

To start, you will need some hardware components:

Item Notes
ESP32-C3 SuperMini board with MicroPython installed (see the previous article)
DHT11 temperature & humidity sensor module digital single-wire sensor
Female-to-female Dupont connectors for direct pin-to-pin connections
USB-C cable for power and serial communication

Buying through these affiliate links helps keep this blog running and the projects coming. Thanks for the support!


Hardware Wiring & Pin Diagram

Here’s how to wire the ESP32-C3 SuperMini directly to the DHT11 sensor module:

 ESP32-C3 SuperMini     DHT11 Sensor
 ───────────────        ─────────────
 3V3  ─────────────►    VCC
 GND  ─────────────►    GND
 GPIO5 ────────────►    DATA

All connections are made pin-to-pin using female-to-female Dupont connectors, no breadboard or additional components required.

On the ESP32-C3 Super Mini you connect like this:

Pins Connection ESP32

You can see the red wire connected to 3.3V, the brown wire connected to GND and the orange connected to the PIN5 on the ESP32.

For the sensor, you connect like this:

Pin Connection DHT11

You can see the red wire connected to '+', the brown wire connected to '-' and the orange connected to 'out'.

That’s it, three wires total.

Why GPIO5?

GPIO5 is a regular, general-purpose I/O pin that works well for digital sensors like the DHT11. You can use other free GPIOs if needed, but it’s best to avoid pins with special boot or flashing functions. GPIO5 is a safe and convenient default.


Reading the DHT11 in MicroPython (Serial Output)

Before building the web server, let's start with a simple script to verify your sensor is working correctly. This will help you troubleshoot any wiring issues early.

The dht module is included in most MicroPython builds for ESP32, but if you encounter an import error, you may need to install it.

Step 1: Create the Sensor Reading Script

In Thonny or your preferred editor, save this as dht_read.py:

import time
import machine
import dht

sensor_pin = machine.Pin(5)
sensor = dht.DHT11(sensor_pin)

print("Starting DHT11 sensor readings...")
print("Press Ctrl+C to stop\n")

while True:
    try:
        # DHT11 needs at least 2 seconds between readings
        time.sleep(2)
        
        # Trigger a measurement
        sensor.measure()
        
        # Read the values
        temp = sensor.temperature()
        hum = sensor.humidity()
        
        # Print formatted output
        print(f"Temperature: {temp}°C   Humidity: {hum}%")
        
    except Exception as e:
        print(f"Read error: {e}")
        print("Check your wiring and pull-up resistor!")

Step 2: Upload and Run

  1. Upload the file to your ESP32-C3 SuperMini using Thonny (File → Save As → MicroPython device).
  2. Open the Serial Monitor (View → Shell in Thonny).
  3. Run the script by pressing F5 or clicking Run.

You should see an output like this:

Starting DHT11 sensor readings...
Press Ctrl+C to stop

Temperature: 21°C   Humidity: 34%
Temperature: 21°C   Humidity: 34%
Temperature: 21°C   Humidity: 34%
Temperature: 21°C   Humidity: 34%
Temperature: 21°C   Humidity: 34%
...

Understanding the Output:

  • Temperature is in Celsius (you can convert to Fahrenheit: (temp * 9/5) + 32)
  • Humidity is a percentage (0-100%)
  • The DHT11 has ±2°C accuracy for temperature and ±5% for humidity
  • Readings update every 2 seconds (the sensor's minimum interval)

Important: The DHT11 can only update about every 2 seconds, so keep your loop delay ≥ 2 seconds. Reading faster than this will cause errors or return stale data.


Running a Simple Web Server

Now that you know the DHT11 is working, it’s time to expose those readings over the network. This is where the project really starts to feel like a building block for your own Home Assistant–style system.

You’ll connect the ESP32-C3 SuperMini to Wi-Fi and run a tiny web server that serves the latest temperature and humidity readings to any browser on your local network; no external services, no cloud required.

Step 1: Create the Web Server Script

This script combines Wi-Fi connectivity, sensor readings, and a basic HTTP server. Save it as main.py, MicroPython automatically runs this file on boot.

import socket
import network
import dht
import machine
import time

# ===== Wi-Fi Configuration =====
SSID = "your-ssid"
PASSWORD = "your-password"

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)

print("Connecting to Wi-Fi...")
timeout = 20
while not wlan.isconnected() and timeout > 0:
    time.sleep(1)
    timeout -= 1
    print(".", end="")

if not wlan.isconnected():
    raise RuntimeError("Wi-Fi connection failed")

ip = wlan.ifconfig()[0]
print(f"\nConnected. IP address: {ip}")

# ===== Sensor Setup =====
sensor = dht.DHT11(machine.Pin(5))
print("DHT11 initialized on GPIO5")

# ===== Web Server Setup =====
addr = socket.getaddrinfo("0.0.0.0", 80)[0][-1]
server = socket.socket()
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server.bind(addr)
server.listen(1)

print(f"Web server running at http://{ip}/")

# ===== Main Server Loop =====
while True:
    try:
        client, addr = server.accept()
        print(f"Client connected: {addr[0]}")
        client.recv(1024)  # Read and ignore request

        sensor.measure()
        temp = sensor.temperature()
        hum = sensor.humidity()
        fahrenheit = (temp * 9 / 5) + 32

        html = f"""<!DOCTYPE html>
<html>
<head>
    <title>ESP32-C3 Sensor Node</title>
    <meta http-equiv="refresh" content="5">
    <style>
        body {{
            font-family: Arial, sans-serif;
            max-width: 600px;
            margin: 40px auto;
            padding: 20px;
            background: #f4f4f4;
        }}
        h1 {{ text-align: center; }}
        .card {{
            background: white;
            padding: 20px;
            border-radius: 8px;
            margin-bottom: 15px;
        }}
        .value {{
            font-size: 2em;
            color: #0066cc;
            font-weight: bold;
        }}
    </style>
</head>
<body>
    <h1>ESP32-C3 Sensor Node</h1>
    <div class="card">
        <strong>Temperature</strong>
        <div class="value">{temp} C ({fahrenheit:.1f} F)</div>
    </div>
    <div class="card">
        <strong>Humidity</strong>
        <div class="value">{hum} %</div>
    </div>
    <p style="text-align:center;color:#777;">
        Auto-refreshes every 5 seconds
    </p>
</body>
</html>
"""

        client.send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n")
        client.send(html)
        client.close()

        print(f"Served: {temp}°C, {hum}%")

    except Exception as e:
        print("Server error:", e)
        try:
            client.close()
        except:
            pass
        time.sleep(1)

Let's understand what this code does:

  • Connects to Wi-Fi with a timeout to avoid blocking forever
  • Reads the DHT11 fresh on each HTTP request
  • Serves a simple HTML dashboard directly from the ESP32
  • Auto-refreshes every 5 seconds for near-real-time updates
  • Keeps running even if a request or read fails

This pattern, sensor → local web endpoint, is exactly how many DIY home-automation systems start.

Note: Don't forget to input your Wi-Fi credentials before running the script.

Step 2: Upload and Run

  1. Upload main.py to your ESP32-C3 SuperMini
  2. Reset the board
  3. Watch the serial output for the assigned IP address
  4. Open a browser on the same network
  5. Visit the indicated IP address

For reference, this is an example of the serial output on Thonny:

MPY: soft reboot
Connecting to Wi-Fi...
...
Connected. IP address: 192.168.2.73
DHT11 initialized on GPIO5
Web server running at http://192.168.2.73/

Opening the browser on the indicated address, you should see the web page showing live temperature and humidity readings, updating automatically every 5 seconds.

ESP32-C3 SuperMini - Web Server

Conclusion

You’ve just built your first Wi-Fi-enabled sensor node, and more importantly, you’ve laid the groundwork for your own DIY home-automation system.

With the ESP32-C3 SuperMini and a simple DHT11 sensor, you now have a device that can read real-world data, connect to your network, and expose that data through a web interface, all running locally on MicroPython. No cloud services, no vendor lock-in, just hardware and code you control.

The concepts covered here, GPIO wiring, sensor polling, Wi-Fi connectivity, and serving data over HTTP, are the same building blocks used in larger systems like Home Assistant, MQTT-based sensor networks, and custom dashboards. From here, it’s easy to imagine adding more sensors, exposing a JSON API, or aggregating multiple nodes into a central controller.

Projects like this are even more fun when they’re shared. If you know someone who enjoys tinkering with hardware, building smart-home setups, or learning MicroPython, feel free to pass this along, it might be the starting point for their own sensor network.

Happy hacking.


Follow me on Twitter: https://twitter.com/DevAsService

Follow me on Instagram: https://www.instagram.com/devasservice/

Follow me on TikTok: https://www.tiktok.com/@devasservice

Follow me on YouTube: https://www.youtube.com/@DevAsService

Last Update: February 02, 2026

About the Author

Nuno Bispo Netherlands

Building better devs, one post at a time. 💻 Practical tips, pro insights, and tools that actually work. Read the blog today.

View All Posts