Serial at 115200 baudTap a part to see what it does.
Tap the parts to see what each one does. A teaching simulation, not a circuit simulator.
Build it step by step
0 of 4 doneSeat the ESP32
Across the centre gap, USB towards you.
Wire the DHT22
VCC to 3V3, DATA to GPIO4, GND to GND. Add 10 kΩ from DATA to 3V3 if it is a bare sensor.
Wire the OLED
SDA to GPIO21, SCL to GPIO22, VCC to 3V3, GND to GND.
Upload
Install the libraries, upload, and watch the display update every 2 seconds.
How do you build a humidity display with OLED?
An ESP32 reads a DHT22 every 2 seconds and shows temperature and humidity in large digits on an OLED. You need ESP32 DevKit V1, DHT22 Sensor, SSD1306 OLED Display, Resistor 10 kΩ and Breadboard 830 Tie Points. It takes 4 steps and about 45 minutes.
- Level
- Beginner
- Time
- About 45 min
- Parts
- 5
Parts list
- Development BoardsBuyESP32 DevKit V1 × 1
- SensorsBuyDHT22 Sensor × 1
- DisplaysBuy
- PassivesBuyResistor 10 kΩ × 1Only if your DHT22 is a bare 4-pin sensor
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| DHT22 VCC | ESP32 3V3 | Power |
| DHT22 DATA | ESP32 GPIO4, with 10 kΩ to 3V3 | Data with pull-up |
| DHT22 GND | ESP32 GND | Ground |
| OLED VCC / GND | ESP32 3V3 / GND | Power |
| OLED SDA / SCL | ESP32 GPIO21 / GPIO22 | I2C |
Code
Libraries: "DHT sensor library" and "Adafruit SSD1306" (install Adafruit GFX and Unified Sensor when asked). Board: ESP32 Dev Module.
Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <DHT.h>
#include <Adafruit_SSD1306.h>
DHT dht(4, DHT22);
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
void setup() {
Serial.begin(115200);
dht.begin();
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) Serial.println("OLED not found");
oled.setTextColor(SSD1306_WHITE);
}
void loop() {
float t = dht.readTemperature(), h = dht.readHumidity();
oled.clearDisplay();
if (isnan(t) || isnan(h)) {
oled.setTextSize(1); oled.setCursor(0, 0); oled.print("Sensor error");
} else {
oled.setTextSize(1); oled.setCursor(0, 0); oled.print("Temperature");
oled.setTextSize(2); oled.setCursor(0, 12); oled.print(t, 1); oled.print(" C");
oled.setTextSize(1); oled.setCursor(0, 36); oled.print("Humidity");
oled.setTextSize(2); oled.setCursor(0, 48); oled.print(h, 0); oled.print(" %");
}
oled.display();
delay(2000);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Breathe on the sensor | Humidity rises within a few seconds |
| Hold it in your hand | Temperature rises by 1 to 3 °C over a minute |
| Unplug DATA | Display shows "Sensor error" instead of nonsense |
If it does not work
Always "Sensor error"
Check the pull-up and that you read no faster than every 2 s.
OLED blank
Run an I2C scanner: the address may be 0x3D.
Humidity stuck at 99 %
Condensation: let the sensor dry out.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the humidity display with OLED?
ESP32 DevKit V1, DHT22 Sensor, SSD1306 OLED Display, Resistor 10 kΩ and Breadboard 830 Tie Points. Resistor 10 kΩ: Only if your DHT22 is a bare 4-pin sensor.
How long does the humidity display with OLED take to build?
About 45 minutes for a beginner maker, in 4 steps.
How do I know the humidity display with OLED works?
Breathe on the sensor: Humidity rises within a few seconds. Hold it in your hand: Temperature rises by 1 to 3 °C over a minute. Unplug DATA: Display shows "Sensor error" instead of nonsense.
Always "Sensor error: what should I check?
Check the pull-up and that you read no faster than every 2 s.
OLED blank: what should I check?
Run an I2C scanner: the address may be 0x3D.
Humidity stuck at 99 %: what should I check?
Condensation: let the sensor dry out.
