Skip to content

Example 19: DHT11 Temperature and Humidity Sensor ​

Experiment Overview ​

DHT11 is a commonly used digital temperature and humidity sensor, measurement range: temperature 0~50°C (±2°C), humidity 20~90%RH (±5%RH). FastBee has a built-in SENSOR_GENERIC generic sensor type (type: 38) that directly supports DHT11/DHT22.

Hardware Wiring ​

Board LabelGPIO PinConnected Device
DATAGPIO27DHT11 data pin

DHT11 three-wire connection: VCC→3.3V/5V, GND→GND, DATA→GPIO (module has built-in pull-up resistor).

JSON Configuration Example ​

json
{
  "peripherals": [
    {
      "id": "dht_01",
      "name": "DHT11 Temp/Humidity",
      "type": 38,
      "enabled": false,
      "pins": [27],
      "params": {}
    }
  ]
}

Peripheral Execution Linkage ​

Scenario 1: Periodic Temp/Humidity Acquisition (Timer Trigger) ​

Function: Read temperature and humidity data every 5 seconds

Web Interface Configuration Steps ​

Step 1: Create Rule

  1. Click Peripheral Execution in the left menu
  2. Click New Rule button
  3. Fill in basic configuration:
    • Rule Name: DHT Temp/Humidity Acquisition
    • Report Data: ✅ Enable (report to cloud platform after reading)
    • Enabled: ✅ Enable

Step 2: Configure Trigger

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Timer TriggerExecute at time intervals
    Timer ModeSelect Interval TimerExecute every X seconds
    Interval Seconds5Acquire every 5 seconds

Step 3: Configure Action

  1. Click Add Action button

  2. Fill in action configuration:

    FieldValueDescription
    Action TypeSelect Sensor ReadRead sensor data
    Target PeripheralSelect dht_roomSensor to read
    Data FieldtemperatureRead temperature (or humidity)
  3. Click Save button

Execution Flow:

Every 5 seconds
  ↓
Read dht_room sensor
  ↓
Get temperature value
  ↓
Report to cloud platform (if reporting enabled)

💡 Tip: DHT11 minimum sampling interval is 1 second, recommend 2 seconds or more to avoid read failures


Scenario 2: Low Humidity Alarm (Poll Trigger) ​

Function: When humidity drops below 30%, start humidifier (relay control)

Web Interface Configuration Steps ​

Step 1: Create Rule

  1. Click New Rule
  2. Fill in basic configuration:
    • Rule Name: Low Humidity Alarm
    • Report Data: ✅ Enable
    • Enabled: ✅ Enable

Step 2: Configure Trigger

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Poll TriggerPeriodically detect humidity
    Target PeripheralSelect dht_roomTemp/humidity sensor
    Poll Interval10 secondsCheck every 10 seconds
    Comparison OperatorSelect Less ThanLower limit alarm
    Comparison Value30Humidity threshold 30%

Step 3: Configure Action

  1. Click Add Action button

  2. Fill in action configuration:

    FieldValueDescription
    Action TypeSelect HIGH LevelGPIO output HIGH
    Target PeripheralSelect relay_humidifierHumidifier relay
  3. Click Save button

Execution Flow:

Every 10 seconds
  ↓
Read dht_room humidity value
  ↓
Check: humidity < 30 ?
  ↓ Yes
Start humidifier (relay closes)

⚠️ Note: This rule only has start function, no stop function. Recommend adding another rule: turn off humidifier when humidity > 50%


Scenario 3: Display Temp/Humidity on OLED (Timer Trigger + Multi-Action) ​

Function: Display current temperature and humidity on OLED screen every 3 seconds

Prerequisites ​

Need to configure OLED display peripheral (type: 36) first, assuming ID is oled_display

Web Interface Configuration Steps ​

Step 1: Create Rule

  1. Click New Rule
  2. Fill in basic configuration:
    • Rule Name: Temp/Humidity Display
    • Report Data: ❌ Disable
    • Enabled: ✅ Enable

Step 2: Configure Trigger

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Timer TriggerPeriodically refresh display
    Timer ModeSelect Interval TimerExecute every X seconds
    Interval Seconds3Refresh every 3 seconds

Step 3: Configure Actions (3 actions needed)

Action 1: Read Temperature

  1. Click Add Action button
  2. Fill in:
    • Action Type: Select Sensor Read
    • Target Peripheral: Select dht_room
    • Data Field: temperature

Action 2: Read Humidity

  1. Click Add Action button again
  2. Fill in:
    • Action Type: Select Sensor Read
    • Target Peripheral: Select dht_room
    • Data Field: humidity

Action 3: Display on OLED

  1. Click Add Action button a third time

  2. Fill in:

    • Action Type: Select OLED Display
    • Target Peripheral: Select oled_display
    • Display Content:
      Temp: ${dht_room.temperature}°C
      Humidity: ${dht_room.humidity}%
    • Execution Mode: Select Synchronous
  3. Click Save button

Execution Flow:

Every 3 seconds
  ↓
Read temperature value
  ↓
Read humidity value
  ↓
Display two lines on OLED:
  Line 1: Temp: 25.3°C
  Line 2: Humidity: 65%

💡 Variable Substitution: ${dht_room.temperature} will be automatically replaced with the actual temperature value read

Notes ​

  1. Sampling Interval: DHT11 minimum sampling interval is 1 second, recommend 2 seconds or more
  2. DHT22 Compatible: DHT22 (AM2302) uses the same configuration, with higher precision
  3. Power Supply: Both 3.3V and 5V work, 5V for longer transmission distance
  4. First Read: First read after power-on may fail, second read is normal
  5. Wire Length: Data line should not exceed 20m, longer distances need increased pull-up resistance

FastBee | fastbee.cn