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 Glossary / I2CInter Integrated Circuit: a two wire serial communication bus (SDA data and SCL clock) that lets a microcontroller talk to screens and sensors using just two pins.. 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 Glossary / Pull Up ResistorA resistor connected between a signal line and positive supply voltage (3.3V) that holds the line at a clean HIGH state when no chip is actively pulling it LOW. 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 Name | Specification | Qty | Beginner Notes |
|---|---|---|---|
| ESP32 DevKit V1 (30 Pin) | ESP32-WROOM-32, 3.3V logic, Micro USB or USB-C | 1 | Any standard 30 pin or 38 pin ESP32 development board works. |
| 0.96 Inch OLED Display Module | 128x64 px, SSD1306 driver, 4 pin I2C (VCC, GND, SCL, SDA) | 1 | Confirm pin order on the silkscreen; some modules swap VCC and GND. |
| DHT22 (AM2302) Digital Sensor | 3.3V to 5V, +/-0.5 C accuracy, 0 to 100% RH | 1 | If 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) | 1 | Omit if your DHT22 is pre mounted on a 3 pin breakout PCB. |
| Solderless Breadboard and Jumpers | 830 point breadboard + Male to Male Dupont wires | 1 | Use 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 Pin | Destination Pin | Wire Color | Signal / Purpose |
|---|---|---|---|
| ESP32 3V3 | Breadboard +3.3V Rail | Red | Supplies regulated 3.3V power to both the OLED display and DHT22 sensor |
| ESP32 GND | Breadboard GND Rail | Black | Provides a common 0V ground reference for logic signals |
| OLED VCC | Breadboard +3.3V Rail | Red | Powers the SSD1306 display controller at 3.3V |
| OLED GND | Breadboard GND Rail | Black | Ground return for the display |
| ESP32 GPIO21 (D21) | OLED SDA | Blue | Default ESP32 hardware I2C serial data line |
| ESP32 GPIO22 (D22) | OLED SCL | Yellow | Default ESP32 hardware I2C serial clock line |
| DHT22 VCC (Pin 1) | Breadboard +3.3V Rail | Red | Powers the DHT22 temperature and humidity element |
| DHT22 DATA (Pin 2) | ESP32 GPIO4 (D4) | Orange | Single wire digital sensor readout on a safe non strapping GPIO |
| DHT22 GND (Pin 4) | Breadboard GND Rail | Black | Ground return for the DHT22 (Pin 3 is unused) |
SCHEMATIC FIG 01 / ESP32 + SSD1306 I2C + DHT22 PULL UP TOPOLOGY
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:
- DHT sensor library by Adafruit (accept the prompt to install Adafruit Unified Sensor).
- Adafruit SSD1306 by Adafruit.
- Adafruit GFX Library by Adafruit.
Select Tools > Board > esp32 > DOIT ESP32 DEVKIT V1 and choose your active USB serial port.
05. Commented Firmware Code
#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
- Open Tools > Serial Monitor at
115200baud right after flashing. You should see temperature and humidity printed cleanly every 2.5 seconds. - 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.
- 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.
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
Chathura Prabashana builds, tests, and documents beginner friendly ESP32 circuits, microcontroller firmware, and practical electronics prototypes from scratch.
About the Author & Verification Standards →