ESP32 S3 - DHT11 - OLED

The DHT11 sensor paired with an SSD1306 OLED display gives the ESP32 S3 a compact, self-contained environmental monitoring station that renders live temperature and humidity readings on a crisp 128×64 screen without any Serial Monitor connection. This tutorial walks you through wiring both components to the ESP32 S3 and writing the Arduino code that reads the sensor and updates the display every two seconds.

What you'll build:

  1. A circuit connecting a DHT11 temperature and humidity sensor and an SSD1306 OLED display to the ESP32 S3
  2. A sketch that reads temperature and humidity from the DHT11 and renders them centered on the OLED every two seconds
  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
ESP32 S3 - DHT11 - OLED

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×DHT11 Temperature Humidity Sensor Module
1×Alternatively, DHT11 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 DHT11 and OLED

The DHT11 sensor uses a single-wire digital protocol to deliver calibrated temperature readings from 0 to 50 °C and relative humidity readings from 20 to 90 % RH, making it an accessible and affordable choice for indoor environmental monitoring projects. Pairing it with an SSD1306 OLED display gives the ESP32 S3 a sharp, high-contrast output that updates continuously without requiring a laptop or Serial Monitor to be attached.

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

Connect the DHT11 sensor and the SSD1306 OLED display to your ESP32 S3 following the diagram below, and double-check every connection before powering the board. The DHT11 can operate at either 3.3 V or 5 V, so you may connect its VCC pin to either rail depending on your setup.

The wiring diagram between ESP32 S3 DHT11 module OLED

This image is created using Fritzing. Click to enlarge image

A screw terminal keeps each wire tight, even when the board shakes. A Screw Terminal Block for ESP32 S3 solves this. Plug the ESP32 S3 into it and screw the wires in. Below is the wiring diagram with the screw terminal board.

The wiring diagram between ESP32 S3 DHT11 module OLED Screw Terminal

This image is created using Fritzing. Click to enlarge image

A GPIO Breakout Board for ESP32 S3 works too. Besides one S, 3.3V and GND pin for each GPIO, it has extra 3.3V and 5V pins:

The wiring diagram between ESP32 S3 DHT11 module OLED GPIO Breakout Board

This image is created using Fritzing. Click to enlarge image

Safety Notes

Always verify that the DHT11 data pin is connected to the GPIO defined in the sketch, and use a 10 kΩ pull-up resistor between the data pin and VCC if your module does not already include one. Keep the sensor away from heat sources, direct sunlight, and condensation, as these can skew readings and permanently damage the sensing element.

Component Pin ESP32 S3 Pin
DHT11 Sensor VCC 3.3V or 5V
DHT11 Sensor GND GND
DHT11 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 - DHT11 Sensor - OLED

The following code reads temperature and humidity from the DHT11 sensor every two seconds and renders the values centered both horizontally and vertically on the SSD1306 OLED display. It uses the Adafruit DHT library for sensor communication and the Adafruit SSD1306 library for display output, keeping both initialization and update logic concise and easy to follow.

/* * 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-dht11-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-dht11-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 DHT11_PIN 1 // The ESP32-S3 pin GPIO1 connected to DHT11 sensor Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); // create SSD1306 display object connected to I2C DHT dht11(DHT11_PIN, DHT11); 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 dht11.begin(); // initialize DHT11 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 = dht11.readHumidity(); // read humidity float tempC = dht11.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(); }

Detailed Instructions

  1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
  2. Wire the DHT11 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 look for 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.
  3. Type "DHT" in the search box, then look for 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 every two seconds.
  3. Pro Tip: The code automatically centers the text both horizontally and vertically on the OLED. If the display shows nothing, verify the I2C address in the code matches your module (try 0x3C or 0x3D) and confirm that SDA and SCL wires are not swapped.

Serial Monitor Output

The following Serial Monitor output shows the ESP32 S3 reading temperature and humidity from the DHT11 sensor and updating the OLED at regular two-second intervals. Each line is timestamped so you can verify the update rate and observe how readings respond to changes in the environment.

∞
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:22:10] Temperature: 26.0 °C Humidity: 58 % [2026-06-16 09:22:12] Temperature: 26.0 °C Humidity: 59 % [2026-06-16 09:22:14] Temperature: 28.0 °C Humidity: 63 % [2026-06-16 09:22:16] Temperature: 30.0 °C Humidity: 70 %
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 on the OLED 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 soil-adjacent 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 icon or bitmap to the OLED alongside the sensor readings to give the display a more polished, product-like appearance.
  3. Intermediate: Implement a simple threshold alert that flashes the OLED and prints a warning 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!