Voltage safety first
The ESP32 is a 3.3V board. Its GPIO pins are NOT 5V-tolerant.
- Power the DHT11 from the ESP32 3V3 pin, never from 5V, when its data line goes straight into a GPIO.
- Double-check the GND connection — a floating ground gives garbage readings or nothing at all.
- Wire everything with the board unplugged, then plug in the USB last.
Temperature and Humidity with DHT11
Your ESP32 can already blink an LED. Now let us give it a sense of the weather. The DHT11 is a tiny, cheap sensor that tells your board two things about the air around it: how warm it is and how damp it is. By the end of this lesson you will have wired one up and printed live temperature and humidity to your screen.
Inside the little blue box are two miniature parts: a thermistor (a resistor whose value changes with heat) and a humidity-sensing capacitor (whose value changes with moisture). A tiny chip inside reads both, turns them into plain numbers, and hands those numbers to your ESP32 over a single wire. You never touch the raw electronics — you just ask a library "what is the temperature?" and it answers.