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:
- A circuit connecting a DHT22 temperature and humidity sensor and an SSD1306 OLED display to the ESP32 S3
- A sketch that reads temperature and humidity from the DHT22 and displays them centered on the OLED
- A portable, stand-alone environmental monitor that works without a connected laptop
- A foundation you can extend into climate control systems, data loggers, or IoT weather stations
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables ESP32 S3 Starter Kit (ESP32 S3 included) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
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.
※ NOTE THAT:
The above code automatically horizontal and vertical center aligns the text on the OLED display.
Detailed Instructions
- New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
- Wire the DHT22 sensor and OLED display to the ESP32 S3 following the wiring diagram above.
- Connect the ESP32 S3 board to your PC using a USB Type-C cable.
- Open Arduino IDE on your PC.
- Select the correct ESP32 S3 board and COM port from the Tools menu.
- Click the Libraries icon on the left bar of the Arduino IDE.
- Type "SSD1306" in the search box, then find the SSD1306 library by Adafruit.
- Click the Install button to install the library.
- Search for Adafruit SSD1306 created by Adafruit and click the Install button.
- A window appears asking you to install dependencies for the library.
- Click Install All to install all required dependencies including Adafruit GFX.
- Type "DHT" in the search box, then find the DHT sensor library by Adafruit.
- Click the Install button to install the library.
- Search for DHT sensor library created by Adafruit and click the Install button.
- A window appears asking you to install dependencies for the library.
- Click Install All to install all required dependencies.
- Copy the above code and paste it into Arduino IDE.
- Click the Upload button to compile and upload the code to your ESP32 S3.

- Place the sensor near a warm cup of coffee or breathe gently on it to change the humidity.
- Watch the temperature and humidity readings update on the OLED display.
- 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.
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.
- Indoor climate monitor: Mount the sensor in a room and display temperature and humidity at a glance to ensure comfortable living conditions.
- Greenhouse controller: Trigger fans or misters automatically when the displayed humidity or temperature exceeds a set threshold.
- Server room monitor: Track temperature and humidity inside a cabinet and activate an alert if either value goes out of range.
- Plant care assistant: Display ambient humidity readings to remind users when conditions are too dry for sensitive houseplants.
- Data logger: Combine the OLED display with SD card logging so readings are both shown in real time and saved for later analysis.
- 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.
- Beginner: Modify the sketch to show temperature in both Celsius and Fahrenheit by alternating between the two units every four seconds.
- Beginner: Add a custom bitmap icon to the OLED output using the Adafruit GFX library's drawBitmap function for a more polished display.
- Intermediate: Implement a simple threshold alert that turns on an LED and prints a warning on the OLED when humidity exceeds 80 %.
- Intermediate: Apply a three-sample rolling average to both temperature and humidity readings to smooth out sensor jitter on the display.
- 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.
- 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.