Example 51: OLED Temperature and Humidity Display
Example 51: OLED Temperature and Humidity Display
Scenario Overview
Use a DHT11/DHT22 temperature and humidity sensor to collect environmental data, and display real-time temperature and humidity values on an SSD1306 OLED screen. This is a typical "sensor read → screen display" linkage scenario.
Required Hardware
| Module | Model | Purpose |
|---|---|---|
| Temp & Humidity Sensor | DHT11 / DHT22 | Collect temperature and humidity |
| OLED Display | SSD1306 0.96" I2C | Display data |
| ESP32 Dev Board | Puzhong ESP32 | Main controller |
Hardware Wiring
DHT11 Wiring
| DHT11 Pin | ESP32 GPIO | Description |
|---|---|---|
| VCC | 3.3V | Power |
| DATA | GPIO 32 | Data pin |
| GND | GND | Ground |
SSD1306 OLED Wiring
| OLED Pin | ESP32 GPIO | Description |
|---|---|---|
| VCC | 3.3V | Power |
| GND | GND | Ground |
| SDA | GPIO 21 | I2C Data |
| SCL | GPIO 22 | I2C Clock |
Peripheral Execution Linkage Configuration
Scenario 1: Timed Read and Display Temp/Humidity (Timer Trigger)
Function: Read DHT11 data every 3 seconds and display on OLED
Web Interface Configuration Steps
Step 1: Create Rule
- Click Peripheral Configuration in the left menu → Switch to Peripheral Execution Management tab
- Click Add Rule button
- Fill in basic configuration:
- Rule Name:
OLED Display Temp & Humidity - Report Data: ✅ Enabled
- Enable: ✅ Enabled
- Rule Name:
Step 2: Configure Trigger (Timer Trigger)
Click Add Trigger button
Fill in trigger configuration:
Field Value Description Trigger Type Select Timer Trigger Timed collection Timer Mode Select Fixed Interval Millisecond interval Interval 30003 seconds
Step 3: Configure Actions (2 actions required)
Action 1: Read Sensor Data
- Click Add Action button
- Fill in:
- Action Type: Select Sensor Read
- Target Peripheral: Select
dht1
Action 2: OLED Display Data
Click Add Action button again
Fill in:
- Action Type: Select OLED Display
- Target Peripheral: Select
oled1 - Display Template:
=== FastBee === Temp: {dht1.temperature}C Humi: {dht1.humidity}% ===============Click Save button
Scenario 2: Display with Temperature Alarm (Poll Trigger)
Function: Display warning and trigger buzzer when temperature exceeds 35°C
Configuration Steps:
- Create a rule, name:
Temperature Alarm Display - Trigger configuration:
- Trigger Type: Select Poll Trigger
- Target Peripheral: Select
dht1 - Data Field:
temperature - Operator:
> - Threshold:
35 - Poll Interval:
5000
- Action configuration (2 actions required):
- Action 1: Select OLED Display, target
oled1, template:!! WARNING !! High Temp! {dht1.temperature}C Check cooling - Action 2: Select HIGH, target
buzzer1(buzzer must be configured in advance)
- Action 1: Select OLED Display, target
- Click Save
Complete Configuration Import
Save the following as a JSON file and import to peripherals.json via the Web interface file management:
[
{
"id": "dht1",
"name": "DHT11 Temp & Humidity",
"type": 38,
"enabled": false,
"pins": [32],
"params": {
"driver": "DHT",
"model": "DHT11",
"interval": 3000
}
},
{
"id": "oled1",
"name": "OLED Display",
"type": 36,
"enabled": false,
"pins": [21, 22],
"params": {
"driver": "SSD1306",
"width": 128,
"height": 64,
"i2cAddress": "0x3C"
}
}
]Display Output
OLED display example:
=== FastBee ===
Temp: 25.3C
Humi: 60.5%
===============- 128x64 resolution supports 4 lines of text (16px font size)
- Supports Chinese and English characters (Chinese characters occupy two character widths)
{periphId.field}in the template will be replaced with actual sensor values
Extension Suggestions
- Multi-Sensor Display: Add BMP280 barometric pressure data, alternate between multiple pages
- Graphical Display: Use script action to draw temperature trend curves
- Time Display: Combine NTP time to show clock on screen
- WiFi Status: Display WiFi connection status and IP address
Notes
- I2C Address: SSD1306 default address is usually
0x3C, some modules use0x3D - Refresh Rate: OLED refresh should not be too frequent (≥ 1000ms), otherwise flickering may occur
- Burn-in: Long-duration static content may cause OLED burn-in. Recommend periodically switching display content
- DHT Sampling Rate: DHT11 maximum 1 time/second, DHT22 maximum 1 time/2 seconds
- Shared I2C: OLED can share I2C bus with BMP280 and other sensors
