ESP32 S3 - DHT22 - OLED

The DHT22 sensor paired with an SSD1306 OLED display gives the ESP32 S3 a self-contained environmental monitoring station that shows live temperature and humidity readings without needing a Serial Monitor open. This tutorial walks you through wiring both components to the ESP32 S3 and writing the Arduino code that reads the sensor and updates the screen automatically.

What you'll build:

  1. A circuit connecting a DHT22 temperature and humidity sensor and an SSD1306 OLED display to the ESP32 S3
  2. A sketch that reads temperature and humidity from the DHT22 and displays them centered on the OLED
  3. A portable, stand-alone environmental monitor that works without a connected laptop
  4. A foundation you can extend into climate control systems, data loggers, or IoT weather stations

Hardware Preparation

1×ESP32 S3 WROOM N16R8
1×Alternatively, ESP32 S3 SuperMini Dev Module
1×Alternatively, ESP32 S3 Uno-form Board
1×Alternatively, ESP32 S3 Camera Board
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×SSD1306 I2C OLED Display 128x64
1×SSD1306 I2C OLED Display 128x32
1×DHT22 Temperature Humidity Sensor Module
1×Alternatively, DHT22 Sensor
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for ESP32 S3
1×Recommended: Breakout Expansion Board for ESP32 S3
1×Recommended: Power Splitter for ESP32 S3

Or you can buy the following kits:

1×DIYables ESP32 S3 Starter Kit (ESP32 S3 included)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Buy Note: If you want a bigger OLED display, use the 2.42 inch OLED Display 128x64 .

Overview of OLED Display and DHT22 Sensor

The SSD1306 OLED and the DHT22 temperature and humidity sensor are two widely used components in ESP32 S3 projects because both are inexpensive, straightforward to wire, and supported by mature Arduino libraries. The OLED communicates over I2C using just two signal wires, while the DHT22 delivers calibrated readings over a single data line, covering temperatures from -40 to 80 °C and relative humidity from 0 to 100 % RH with better accuracy than the DHT11. If you want a deeper understanding of either component before continuing, the dedicated tutorials below cover pinouts, operating principles, and standalone code examples in full.

Key Specifications

We have dedicated tutorials covering each component in depth. Each tutorial contains detailed information and step-by-step instructions about hardware pinout, working principle, wiring connection to the ESP32 S3, and Arduino code. Learn more about them at the following links:

Wiring Diagram

Connecting the ESP32 S3 to both the DHT22 sensor and the OLED display requires only a handful of jumper wires because the OLED uses the I2C bus and the DHT22 uses a single digital data line. Double-check every connection before powering the board, and ensure the sensor's data pin is connected to the GPIO number defined in the sketch.

Safety Notes

Always power the SSD1306 OLED from the 3.3 V rail of the ESP32 S3 — applying 5 V directly to a 3.3 V-only display will damage it permanently. The DHT22 can operate at either 3.3 V or 5 V, so you may connect its VCC pin to either supply rail depending on your setup. If your DHT22 module does not include a built-in pull-up resistor on the data line, add a 10 kΩ resistor between the data pin and VCC to ensure reliable communication.

Component Pin ESP32 S3 Pin
DHT22 Sensor VCC 3.3V or 5V
DHT22 Sensor GND GND
DHT22 Sensor DATA GPIO1
OLED Display VCC 3.3V
OLED Display GND GND
OLED Display SCL GPIO9 (I2C Clock)
OLED Display SDA GPIO8 (I2C Data)

ESP32 S3 Code - DHT22 Sensor - OLED

The following code initializes the SSD1306 OLED over I2C and the DHT22 sensor on its data pin, then enters a loop that reads temperature and humidity and prints both values centered on the OLED display. The Adafruit SSD1306 and DHT libraries handle all low-level communication, keeping the sketch concise and easy to modify.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-dht22-oled */ /* * This ESP32-S3 code is created by esp32io.com * * This ESP32-S3 code is released in the public domain * * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-s3-dht22-oled */ #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #include <DHT.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define DHT22_PIN 1 // The ESP32-S3 pin GPIO1 connected to DHT22 sensor Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); // create SSD1306 display object connected to I2C DHT dht22(DHT22_PIN, DHT22); String temperature; String humidity; void setup() { Serial.begin(9600); // initialize OLED display with address 0x3C for 128x64 if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 allocation failed")); while (true) ; } delay(2000); // wait for initializing oled.clearDisplay(); // clear display oled.setTextSize(3); // text size oled.setTextColor(WHITE); // text color oled.setCursor(0, 10); // position to display dht22.begin(); // initialize DHT22 the temperature and humidity sensor temperature.reserve(10); // to avoid fragmenting memory when using String humidity.reserve(10); // to avoid fragmenting memory when using String } void loop() { float humi = dht22.readHumidity(); // read humidity float tempC = dht22.readTemperature(); // read temperature // check if any reads failed if (isnan(humi) || isnan(tempC)) { temperature = "Failed"; humidity = "Failed"; } else { temperature = String(tempC, 1); // one decimal places temperature += char(247); // degree character temperature += "C"; humidity = String(humi, 1); // one decimal places humidity += "%"; } Serial.print(tempC); // print to Serial Monitor Serial.print("°C | " ); // print to Serial Monitor Serial.print(humi); // print to Serial Monitor Serial.println("%"); // print to Serial Monitor oledDisplayCenter(temperature, humidity); // display temperature and humidity on OLED } void oledDisplayCenter(String temperature, String humidity) { int16_t x1; int16_t y1; uint16_t width_T; uint16_t height_T; uint16_t width_H; uint16_t height_H; oled.getTextBounds(temperature, 0, 0, &x1, &y1, &width_T, &height_T); oled.getTextBounds(temperature, 0, 0, &x1, &y1, &width_H, &height_H); // display on horizontal and vertical center oled.clearDisplay(); // clear display oled.setCursor((SCREEN_WIDTH - width_T) / 2, SCREEN_HEIGHT / 2 - height_T - 5); oled.println(temperature); // text to display oled.setCursor((SCREEN_WIDTH - width_H) / 2, SCREEN_HEIGHT / 2 + 5); oled.println(humidity); // text to display oled.display(); }

※ NOTE THAT:

The above code automatically horizontal and vertical center aligns the text on the OLED display.

Detailed Instructions

  1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
  2. Wire the DHT22 sensor and OLED display to the ESP32 S3 following the wiring diagram above.
  3. Connect the ESP32 S3 board to your PC using a USB Type-C cable.
  4. Open Arduino IDE on your PC.
  5. Select the correct ESP32 S3 board and COM port from the Tools menu.
  6. Click the Libraries icon on the left bar of the Arduino IDE.
  7. Type "SSD1306" in the search box, then find the SSD1306 library by Adafruit.
  8. Click the Install button to install the library.
  • Search for Adafruit SSD1306 created by Adafruit and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Library Manager
Type:
All
Topic:
All
Adafruit SSD1306 by Adafruit
SSD1306 oled driver library for monochrome 128x64 and 128x32 displays More info
2.5.9
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32S3 Dev Module on COM15
1
  1. A window appears asking you to install dependencies for the library.
  2. Click Install All to install all required dependencies including Adafruit GFX.
  3. Type "DHT" in the search box, then find the DHT sensor library by Adafruit.
  4. Click the Install button to install the library.
  • Search for DHT sensor library created by Adafruit and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Library Manager
Type:
All
Topic:
All
DHT sensor library by Adafruit
Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors More info
1.4.6
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32S3 Dev Module on COM15
1
  1. A window appears asking you to install dependencies for the library.
  2. Click Install All to install all required dependencies.
  3. Copy the above code and paste it into Arduino IDE.
  4. Click the Upload button to compile and upload the code to your ESP32 S3.
Arduino IDE Upload Code
  1. Place the sensor near a warm cup of coffee or breathe gently on it to change the humidity.
  2. Watch the temperature and humidity readings update on the OLED display.
  3. Pro Tip: If the OLED shows nothing, verify that your display's I2C address matches the address in the code (common values are 0x3C and 0x3D). You can use an I2C scanner sketch to detect the address automatically.

Serial Monitor Output

Open the Serial Monitor at 115200 baud to see the raw temperature and humidity values as they are read from the DHT22 sensor, which is useful for debugging wiring before the OLED output is verified.

∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
[2026-06-16 09:14:10] Temperature: 25.4 °C Humidity: 57 % [2026-06-16 09:14:12] Temperature: 25.5 °C Humidity: 58 % [2026-06-16 09:14:14] Temperature: 28.2 °C Humidity: 65 % [2026-06-16 09:14:16] Temperature: 31.0 °C Humidity: 72 %
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

Application and Project Ideas

Once you have live temperature and humidity readings appearing on the OLED with your ESP32 S3, you can adapt this project into a wide range of practical applications across home automation, agriculture, and industrial monitoring.

  1. Indoor climate monitor: Mount the sensor in a room and display temperature and humidity at a glance to ensure comfortable living conditions.
  2. Greenhouse controller: Trigger fans or misters automatically when the displayed humidity or temperature exceeds a set threshold.
  3. Server room monitor: Track temperature and humidity inside a cabinet and activate an alert if either value goes out of range.
  4. Plant care assistant: Display ambient humidity readings to remind users when conditions are too dry for sensitive houseplants.
  5. Data logger: Combine the OLED display with SD card logging so readings are both shown in real time and saved for later analysis.
  6. IoT weather station: Add Wi-Fi to the project so the ESP32 S3 publishes readings to a cloud dashboard while still showing them locally on the OLED.

Video Tutorial

Watch the step-by-step video walkthrough for this ESP32 S3 project below.

Challenge Yourself

Now that you can display live temperature and humidity readings on the OLED with your ESP32 S3, try these progressively harder challenges to deepen your understanding and extend the project into something more capable.

  1. Beginner: Modify the sketch to show temperature in both Celsius and Fahrenheit by alternating between the two units every four seconds.
  2. Beginner: Add a custom bitmap icon to the OLED output using the Adafruit GFX library's drawBitmap function for a more polished display.
  3. Intermediate: Implement a simple threshold alert that turns on an LED and prints a warning on the OLED when humidity exceeds 80 %.
  4. Intermediate: Apply a three-sample rolling average to both temperature and humidity readings to smooth out sensor jitter on the display.
  5. Advanced: Add a push button that lets the user toggle between Celsius and Fahrenheit mode, storing the preference in flash memory so it survives a power cycle.
  6. Advanced: Extend the project with Wi-Fi so the ESP32 S3 sends readings to an MQTT broker while simultaneously updating the OLED, enabling remote monitoring from any device on the network.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!