Example 19: DHT11 Temperature and Humidity Sensor
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 Label | GPIO Pin | Connected Device |
|---|---|---|
| DATA | GPIO27 | DHT11 data pin |
DHT11 three-wire connection: VCC→3.3V/5V, GND→GND, DATA→GPIO (module has built-in pull-up resistor).
JSON Configuration Example
{
"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
- Click left menu Peripheral Configuration → Switch to Peripheral Execution Management tab
- Click New Rule button
- Fill in basic configuration:
- Rule Name:
DHT Temp/Humidity Acquisition - Report Data: ✅ Enable (report to cloud platform after reading)
- Enabled: ✅ Enable
- Rule Name:
Step 2: Configure Trigger
Click Add Trigger button
Fill in trigger configuration:
Field Value Description Trigger Type Select Timer Trigger Execute at time intervals Timer Mode Select Interval Timer Execute every X seconds Interval Seconds 5Acquire every 5 seconds
Step 3: Configure Action
Click Add Action button
Fill in action configuration:
Field Value Description Action Type Select Sensor Read Read sensor data Target Peripheral Select dht_roomSensor to read Data Field temperatureRead temperature (or humidity) 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
- Click New Rule
- Fill in basic configuration:
- Rule Name:
Low Humidity Alarm - Report Data: ✅ Enable
- Enabled: ✅ Enable
- Rule Name:
Step 2: Configure Trigger
Click Add Trigger button
Fill in trigger configuration:
Field Value Description Trigger Type Select Poll Trigger Periodically detect humidity Target Peripheral Select dht_roomTemp/humidity sensor Poll Interval 10secondsCheck every 10 seconds Comparison Operator Select Less Than Lower limit alarm Comparison Value 30Humidity threshold 30%
Step 3: Configure Action
Click Add Action button
Fill in action configuration:
Field Value Description Action Type Select HIGH Level GPIO output HIGH Target Peripheral Select relay_humidifierHumidifier relay 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
- Click New Rule
- Fill in basic configuration:
- Rule Name:
Temp/Humidity Display - Report Data: ❌ Disable
- Enabled: ✅ Enable
- Rule Name:
Step 2: Configure Trigger
Click Add Trigger button
Fill in trigger configuration:
Field Value Description Trigger Type Select Timer Trigger Periodically refresh display Timer Mode Select Interval Timer Execute every X seconds Interval Seconds 3Refresh every 3 seconds
Step 3: Configure Actions (3 actions needed)
Action 1: Read Temperature
- Click Add Action button
- Fill in:
- Action Type: Select Sensor Read
- Target Peripheral: Select
dht_room - Data Field:
temperature
Action 2: Read Humidity
- Click Add Action button again
- Fill in:
- Action Type: Select Sensor Read
- Target Peripheral: Select
dht_room - Data Field:
humidity
Action 3: Display on OLED
Click Add Action button a third time
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
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
- Sampling Interval: DHT11 minimum sampling interval is 1 second, recommend 2 seconds or more
- DHT22 Compatible: DHT22 (AM2302) uses the same configuration, with higher precision
- Power Supply: Both 3.3V and 5V work, 5V for longer transmission distance
- First Read: First read after power-on may fail, second read is normal
- Wire Length: Data line should not exceed 20m, longer distances need increased pull-up resistance
