In this project, you’ll learn how to create a real-time temperature and humidity monitor using an ESP32-C3 board with a built-in 0.42” OLED display and a DHT11 sensor. This compact setup displays temperature (°C) and humidity (%) every second, making it a great mini weather station or IoT data display.
Project Overview
Each second, the OLED shows the current temperature and humidity in a clean, two-line format:
TMP: 27.4C
HMD: 43%
This is a perfect beginner-friendly ESP32 project and a practical tool for home, lab, or IoT environments.
PCBWay offers high-quality PCB prototyping and assembly at an affordable price, starting at just $5 for 5 PCBs. With fast turnaround, great customer support, and easy online ordering, it’s a top choice for hobbyists and professionals alike.
Components Required
| Component | Quantity | Description |
|---|---|---|
| ESP32-C3 Board with 0.42” OLED | 1 | Microcontroller with built-in SSD1306 OLED display |
| DHT11 Sensor | 1 | Temperature and humidity sensor |
| Jumper Wires | 3 | For connections |
| Breadboard (optional) | 1 | For prototyping |
Wiring Connections
DHT11 → ESP32-C3
| DHT11 Pin | ESP32-C3 Pin | Description |
|---|---|---|
| VCC | 3.3V | Power supply |
| GND | GND | Ground |
| DATA | GPIO2 | Sensor data pin |
The 0.42” OLED display is already integrated on the ESP32-C3 board, using:
| OLED Pin | GPIO | Function |
|---|---|---|
| SDA | 5 | I²C data |
| SCL | 6 | I²C clock |
Libraries Required
Install the following libraries via Arduino IDE → Sketch → Include Library → Manage Libraries:
- U8g2 by olikraus (for OLED display)
- DHT sensor library by Adafruit
- Adafruit Unified Sensor (dependency)
Arduino Code
#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>
#include <DHT.h>
#define SDA_PIN 5
#define SCL_PIN 6
U8G2_SSD1306_72X40_ER_F_HW_I2C u8g2(U8G2_R0, /* reset=*/U8X8_PIN_NONE, SCL_PIN, SDA_PIN);
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Wire.begin(SDA_PIN, SCL_PIN);
u8g2.begin();
dht.begin();
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.drawStr(5, 20, "Sensor Error!");
u8g2.sendBuffer();
delay(1000);
return;
}
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.drawStr(0, 15, "TMP:");
u8g2.setFont(u8g2_font_fub11_tr);
u8g2.setCursor(40, 15);
u8g2.print(t, 1);
u8g2.print("C");
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.drawStr(0, 35, "HMD:");
u8g2.setFont(u8g2_font_fub11_tr);
u8g2.setCursor(40, 35);
u8g2.print(h, 0);
u8g2.print("%");
u8g2.sendBuffer();
delay(1000);
}
How It Works
The DHT11 sensor measures temperature (°C) and humidity (%) every second. The ESP32-C3 reads these values and updates the OLED display using the U8g2 library. Large fonts ensure readability even on the small 0.42” display. If the sensor fails, the OLED shows “Sensor Error!” for troubleshooting.
Applications
- Compact weather station
- Indoor environmental monitor
- IoT dashboards and prototypes
- Educational projects for beginners
Example Display Output
TMP: 27.4C
HMD: 43%
TMP: Current temperature in Celsius
HMD: Current relative humidity percentage
Summary Table
| Feature | Description |
|---|---|
| MCU | ESP32-C3 |
| Sensor | DHT11 |
| Display | 0.42” OLED (SSD1306) |
| Interface | I²C (SDA=5, SCL=6) |
| Update Rate | 1 second |
| Power Supply | 3.3V |
Final Thoughts
This ESP32-C3 + DHT11 + OLED project is perfect for compact environmental monitoring. The small display remains clear thanks to large fonts, making it ideal for portable DIY devices or IoT prototypes.