Skip to content

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 ​

ModuleModelPurpose
Temp & Humidity SensorDHT11 / DHT22Collect temperature and humidity
OLED DisplaySSD1306 0.96" I2CDisplay data
ESP32 Dev BoardPuzhong ESP32Main controller

Hardware Wiring ​

DHT11 Wiring ​

DHT11 PinESP32 GPIODescription
VCC3.3VPower
DATAGPIO 32Data pin
GNDGNDGround

SSD1306 OLED Wiring ​

OLED PinESP32 GPIODescription
VCC3.3VPower
GNDGNDGround
SDAGPIO 21I2C Data
SCLGPIO 22I2C 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

  1. Click Peripheral Execution in the left menu
  2. Click Add Rule button
  3. Fill in basic configuration:
    • Rule Name: OLED Display Temp & Humidity
    • Report Data: ✅ Enabled
    • Enable: ✅ Enabled

Step 2: Configure Trigger (Timer Trigger)

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Timer TriggerTimed collection
    Timer ModeSelect Fixed IntervalMillisecond interval
    Interval30003 seconds

Step 3: Configure Actions (2 actions required)

Action 1: Read Sensor Data

  1. Click Add Action button
  2. Fill in:
    • Action Type: Select Sensor Read
    • Target Peripheral: Select dht1

Action 2: OLED Display Data

  1. Click Add Action button again

  2. Fill in:

    • Action Type: Select OLED Display
    • Target Peripheral: Select oled1
    • Display Template:
    === FastBee ===
    Temp: {dht1.temperature}C
    Humi: {dht1.humidity}%
    ===============
  3. Click Save button


Scenario 2: Display with Temperature Alarm (Poll Trigger) ​

Function: Display warning and trigger buzzer when temperature exceeds 35°C

Configuration Steps:

  1. Create a rule, name: Temperature Alarm Display
  2. Trigger configuration:
    • Trigger Type: Select Poll Trigger
    • Target Peripheral: Select dht1
    • Data Field: temperature
    • Operator: >
    • Threshold: 35
    • Poll Interval: 5000
  3. 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)
  4. Click Save

Complete Configuration Import ​

Save the following as a JSON file and import it as peripherals.json from Device Configuration > Advanced Configuration > Configuration Import/Export:

json
[
  {
    "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 ​

  1. Multi-Sensor Display: Add BMP280 barometric pressure data, alternate between multiple pages
  2. Graphical Display: Use script action to draw temperature trend curves
  3. Time Display: Combine NTP time to show clock on screen
  4. WiFi Status: Display WiFi connection status and IP address

Notes ​

  1. I2C Address: SSD1306 default address is usually 0x3C, some modules use 0x3D
  2. Refresh Rate: OLED refresh should not be too frequent (≥ 1000ms), otherwise flickering may occur
  3. Burn-in: Long-duration static content may cause OLED burn-in. Recommend periodically switching display content
  4. DHT Sampling Rate: DHT11 maximum 1 time/second, DHT22 maximum 1 time/2 seconds
  5. Shared I2C: OLED can share I2C bus with BMP280 and other sensors

FastBee | fastbee.cn