Skip to main content

Build. Learn.
Innovate.

Reading Temperature and Humidity with DHT11

Written By:

Published on:

Project Overview

This project teaches students how to measure temperature and humidity using the DHT11 sensor and an ESP32 microcontroller. Students will learn how to read sensor data and display it in the serial monitor, OLED, or web dashboard, introducing basic data collection and real-world IoT applications.

Educational Goals

  • Learn how environmental sensors work
  • Understand the DHT11 communication protocol
  • Display sensor data on serial monitor, OLED, or web interface
  • Analyze changes in environmental data over time

Detailed Parts List

  • 1x ESP32 Dev Board (36-pin)
  • 1x DHT11 Temperature & Humidity Sensor
  • 1x 10kΩ Resistor (if using DHT11 with 3 pins)
  • Jumper wires
  • Breadboard (optional)

Circuit Diagram Description

  • DHT11 has 3 pins: VCC, Data, GND (some models have 4 pins, ignore NC pin)
  • Connect Data to GPIO 4 (or another digital GPIO pin)
  • Use 10kΩ pull-up resistor between VCC and Data line if needed

ESP32 3.3V —> VCC (DHT11)
ESP32 GPIO4 —> DATA (DHT11)
ESP32 GND —> GND (DHT11)
10kΩ resistor between VCC and DATA

Software Functionality

  • Read temperature and humidity values from DHT11
  • Print values in serial monitor
  • Optionally display on OLED screen or send to a web dashboard

Web Interface Features

  • Real-time temperature and humidity display
  • Charts to show variations over time
  • Color-coded values for heat and moisture levels

Implementation Steps

  1. Connect DHT11 to ESP32 as per circuit diagram
  2. Flash MicroPython firmware to ESP32
  3. Upload “** MicroPython library (official driver)**
  4. **Upload and run **“
  5. (Optional) Extend to OLED or web dashboard

Extensions and Challenges

  • Graph readings over time on a web dashboard
  • Trigger fan/LED when temperature exceeds threshold
  • Log readings to a file or Google Sheets
  • Compare indoor vs outdoor readings

Troubleshooting Guide

  • All values are None: Check wiring and timing of sensor reads
  • ESP32 crashes: Ensure correct pull-up resistor
  • Incorrect readings: Use a delay between reads (2 seconds minimum)
  • Sensor not responding: Check if it’s a DHT11 or DHT22 (code differs slightly)

Project Code

from machine import Pin
import dht
from time import sleep

sensor = dht.DHT11(Pin(4))  # GPIO4

while True:
    try:
        sensor.measure()
        temp = sensor.temperature()
        hum = sensor.humidity()
        print("Temperature:", temp, "°C")
        print("Humidity:", hum, "%")
    except OSError as e:
        print("Sensor error:", e)
    sleep(2)

STEM Benefits

  • Science: Understand weather, atmosphere, and the effects of temperature and humidity on living systems.
  • Technology: Learn to interface with environmental sensors and visualize climate data.
  • Engineering: Build data acquisition systems and environmental monitoring tools.
  • Math: Use collected sensor data for analysis, averages, and graphing trends.

Project Code

Projects
ShowCase

Real-World Projects
with Code & Hardware

Insights, Ideas
& How-Tos

Help, Support, and
Common Questions

What types of projects can I find on your website?

You can explore a wide range of microcontroller and electronics projects, including Arduino, ESP32, IoT, and more. Each project comes with downloadable code, detailed guides, and the necessary hardware list.

You can explore a wide range of microcontroller and electronics projects, including Arduino, ESP32, IoT, and more. Each project comes with downloadable code, detailed guides, and the necessary hardware list.

You can explore a wide range of microcontroller and electronics projects, including Arduino, ESP32, IoT, and more. Each project comes with downloadable code, detailed guides, and the necessary hardware list.

You can explore a wide range of microcontroller and electronics projects, including Arduino, ESP32, IoT, and more. Each project comes with downloadable code, detailed guides, and the necessary hardware list.