Skip to main manual content
Circuit Manual
Absolute BeginnerESP323.3V DC

ESP32 Desk Climate Monitor With DHT22 Sensor and 0.96 Inch I2C OLED

Build a live temperature and humidity monitor using an ESP32 DevKit V1, DHT22 sensor, and 0.96 inch I2C OLED screen with full wiring and code.

By Chathura PrabashanaUpdated Nov 16, 2026
Difficulty
Absolute Beginner
Build / Read Time
45 mins
Operating Voltage
3.3V DC
Hardware Platform
ESP32 DevKit V1
Est. Parts Cost
$16 USD
Direct Summary / Key Takeaway

Wire the 0.96 inch SSD1306 OLED screen to the ESP32 default I2C bus on GPIO21 (SDA) and GPIO22 (SCL), connect the DHT22 data pin to safe GPIO4 with a 10 kOhm pull up resistor, power both modules from 3.3V, and upload the Arduino sketch using Adafruit SSD1306 and DHT libraries.

This build combines two essential embedded skills on a single breadboard: reading a digital environmental sensor and driving a crisp miniature screen over . No soldering is required, and every part runs safely on 3.3V DC from your USB cable.

01. Why These Exact Pins and Components

Picking random pins on an ESP32 can cause mysterious boot failures. In this circuit, every pin choice is deliberate:

  • GPIO21 (SDA) and GPIO22 (SCL): These are the ESP32 default hardware I2C pins. Every major Arduino display library maps to them automatically without extra pin remap boilerplate.
  • GPIO4 for DHT22 DATA: GPIO4 is a completely safe general purpose I/O pin that does not interfere with boot strapping or USB flashing. Check our ESP32 GPIO Explorer whenever you add extra sensors.
  • 10 kOhm Pull Up Resistor: The DHT22 communicates using an open drain data line, meaning the sensor pulls the line down to 0V to send bits and lets go to signal a high state. A gently holds that line at 3.3V so electrical noise never corrupts readings.

02. Bill of Materials

Desk Climate Monitor BOM

5 Line Items / 5 Parts Total
Part NameSpecificationQtyBeginner Notes
ESP32 DevKit V1 (30 Pin)ESP32-WROOM-32, 3.3V logic, Micro USB or USB-C1Any standard 30 pin or 38 pin ESP32 development board works.
0.96 Inch OLED Display Module128x64 px, SSD1306 driver, 4 pin I2C (VCC, GND, SCL, SDA)1Confirm pin order on the silkscreen; some modules swap VCC and GND.
DHT22 (AM2302) Digital Sensor3.3V to 5V, +/-0.5 C accuracy, 0 to 100% RH1If using a 3 pin PCB breakout module, the 10 kOhm pull up resistor is already mounted.
Pull Up Resistor (Bare 4 Pin DHT22 Only)10 kOhm, 1/4W (Brown, Black, Orange, Gold)1Omit if your DHT22 is pre mounted on a 3 pin breakout PCB.
Solderless Breadboard and Jumpers830 point breadboard + Male to Male Dupont wires1Use two breadboards side by side if your ESP32 covers all 5 tie points on one side.

03. Pin to Pin Wiring Schedule and Schematic

ESP32 to OLED and DHT22 Wiring Table

9 Jumpers
Source PinDestination PinWire ColorSignal / Purpose
ESP32 3V3Breadboard +3.3V RailRedSupplies regulated 3.3V power to both the OLED display and DHT22 sensor
ESP32 GNDBreadboard GND RailBlackProvides a common 0V ground reference for logic signals
OLED VCCBreadboard +3.3V RailRedPowers the SSD1306 display controller at 3.3V
OLED GNDBreadboard GND RailBlackGround return for the display
ESP32 GPIO21 (D21)OLED SDABlueDefault ESP32 hardware I2C serial data line
ESP32 GPIO22 (D22)OLED SCLYellowDefault ESP32 hardware I2C serial clock line
DHT22 VCC (Pin 1)Breadboard +3.3V RailRedPowers the DHT22 temperature and humidity element
DHT22 DATA (Pin 2)ESP32 GPIO4 (D4)OrangeSingle wire digital sensor readout on a safe non strapping GPIO
DHT22 GND (Pin 4)Breadboard GND RailBlackGround return for the DHT22 (Pin 3 is unused)

SCHEMATIC FIG 01 / ESP32 + SSD1306 I2C + DHT22 PULL UP TOPOLOGY

ESP32 DEVKIT V13V3GNDGPIO21 (SDA)GPIO22 (SCL)GPIO4 (DATA)0.96” SSD1306 OLEDVCCGNDSDASCLDHT22 SENSORPIN1 VCCPIN2 DATAPIN4 GND10k PULL UP

04. Installing Required Libraries in Arduino IDE

Open Arduino IDE 2.x, click the Library Manager icon on the left bar, and install these three packages:

  1. DHT sensor library by Adafruit (accept the prompt to install Adafruit Unified Sensor).
  2. Adafruit SSD1306 by Adafruit.
  3. Adafruit GFX Library by Adafruit.

Select Tools > Board > esp32 > DOIT ESP32 DEVKIT V1 and choose your active USB serial port.

05. Commented Firmware Code

desk_climate_monitor.inocpp
Library Note:Tested with ESP32 Board Core v3.0.x, Adafruit SSD1306 v2.5.13, DHT sensor library v1.4.6
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>

// Hardware pin assignments
#define DHTPIN 4
#define DHTTYPE DHT22

// OLED display dimensions and I2C address
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C

DHT dht(DHTPIN, DHTTYPE);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// Non blocking timing interval (DHT22 requires >= 2000 ms between reads)
unsigned long lastSampleMs = 0;
const unsigned long SAMPLE_INTERVAL_MS = 2500;

void setup() {
Serial.begin(115200);
delay(200);

// Explicitly start I2C on ESP32 default pins (SDA=21, SCL=22)
Wire.begin(21, 22);
dht.begin();

if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
  Serial.println("ERROR: SSD1306 OLED not found at 0x3C. Check SDA/SCL wiring.");
  while (true) {
    delay(1000);
  }
}

display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
display.setCursor(0, 0);
display.println("CIRCUIT MANUAL");
display.println("Warming DHT22 sensor...");
display.display();
}

void loop() {
unsigned long now = millis();
if (now - lastSampleMs < SAMPLE_INTERVAL_MS) {
  return;
}
lastSampleMs = now;

float humidity = dht.readHumidity();
float tempC = dht.readTemperature();

if (isnan(humidity) || isnan(tempC)) {
  Serial.println("WARNING: Failed to read from DHT22. Verify GPIO4 and 10k pull up.");
  display.clearDisplay();
  display.setTextSize(1);
  display.setCursor(0, 16);
  display.println("SENSOR READ ERROR");
  display.println("Check GPIO4 + Pull Up");
  display.display();
  return;
}

float tempF = (tempC * 9.0 / 5.0) + 32.0;

Serial.printf("Temp: %.1f C (%.1f F) | Humidity: %.1f %%\n", tempC, tempF, humidity);

display.clearDisplay();

// Header strip
display.setTextSize(1);
display.setCursor(0, 0);
display.print("DESK CLIMATE / GPIO4");
display.drawLine(0, 10, 127, 10, SSD1306_WHITE);

// Large temperature readout
display.setTextSize(2);
display.setCursor(0, 18);
display.print(tempC, 1);
display.print(" C");

// Secondary humidity readout
display.setTextSize(1);
display.setCursor(0, 44);
display.print("HUMIDITY: ");
display.print(humidity, 1);
display.println(" %");

display.setCursor(0, 55);
display.print("FAHRENHEIT: ");
display.print(tempF, 1);
display.print(" F");

display.display();
}

06. Testing and Calibration Notes

  1. Open Tools > Serial Monitor at 115200 baud right after flashing. You should see temperature and humidity printed cleanly every 2.5 seconds.
  2. Breathe gently over the slotted plastic grille of the DHT22. Relative humidity should climb immediately by 10% to 20% and settle back down over 30 seconds.
  3. Keep the DHT22 at least 4 cm away from the ESP32 metal shield if you mount both inside an enclosure; heat from the ESP32 voltage regulator can skew temperature readings upward by 1.5 C to 3.0 C.
Diagnostics & Common Questions

Testing and Troubleshooting FAQ

Why does my OLED screen stay completely blank after uploading?+

Ninety percent of blank SSD1306 screens come from two issues: swapped SDA/SCL wires or an I2C address of 0x3D instead of 0x3C. First confirm GPIO21 goes to SDA and GPIO22 goes to SCL, then try changing SCREEN_ADDRESS to 0x3D in the code.

Why does the Serial Monitor print Failed to read from DHT22?+

The DHT22 can only be sampled once every 2 seconds. Polling faster returns NaN errors. Also check that a 10 kOhm pull up resistor sits between DATA and 3.3V if you bought the bare white 4 pin sensor instead of a 3 pin module.

Can I use a DHT11 sensor instead of a DHT22?+

Yes. Keep the exact same wiring and change #define DHTTYPE DHT22 to #define DHTTYPE DHT11 near the top of the sketch. The DHT11 is cheaper, though less accurate at low humidity.

Chathura Prabashana
Verified Author / Bench Tester

Chathura Prabashana

Embedded Systems Builder and IT Undergraduate

Chathura Prabashana builds, tests, and documents beginner friendly ESP32 circuits, microcontroller firmware, and practical electronics prototypes from scratch.

About the Author & Verification Standards →