Projects / Humidity display with OLED

Humidity display with OLED

Beginner45 minGuided buildReviewed
ESP32 DevKit3V3GPIO4GPIO21GPIO22GNDDHT22Temperature27 CHumidity 55 %OLED
Serial at 115200 baud

Tap 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 done
  1. ESP32

    Seat the ESP32

    Across the centre gap, USB towards you.

  2. ESP32DHT2226.3°C

    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.

  3. ESP3215.1 mASSD1306

    Wire the OLED

    SDA to GPIO21, SCL to GPIO22, VCC to 3V3, GND to GND.

  4. ESP32

    Upload

    Install the libraries, upload, and watch the display update every 2 seconds.

In short

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

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
DHT22 VCCESP32 3V3Power
DHT22 DATAESP32 GPIO4, with 10 kΩ to 3V3Data with pull-up
DHT22 GNDESP32 GNDGround
OLED VCC / GNDESP32 3V3 / GNDPower
OLED SDA / SCLESP32 GPIO21 / GPIO22I2C

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.

CheckExpected
Breathe on the sensorHumidity rises within a few seconds
Hold it in your handTemperature rises by 1 to 3 °C over a minute
Unplug DATADisplay 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 →

Ask Lark AI

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.