Example 52: TM1637 Seven-Segment Temp/Humidity Display
Example 52: TM1637 Seven-Segment Temp/Humidity Display
Scenario Overview
Use a DHT11/DHT22 temperature and humidity sensor to collect data, and alternately display temperature and humidity values on a TM1637 four-digit seven-segment display. Suitable for scenarios requiring long-distance data observation (e.g., greenhouse, server room temperature monitoring).
Required Hardware
| Module | Model | Purpose |
|---|---|---|
| Temp & Humidity Sensor | DHT11 / DHT22 | Collect temperature and humidity |
| Seven-Segment Display | TM1637 Four-Digit | Display values |
| 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 |
TM1637 Seven-Segment Wiring
| TM1637 Pin | ESP32 GPIO | Description |
|---|---|---|
| VCC | 3.3V / 5V | Power |
| GND | GND | Ground |
| CLK | GPIO 18 | Clock pin |
| DIO | GPIO 19 | Data pin |
Peripheral Execution Linkage Configuration
Scenario 1: Alternate Display of Temperature and Humidity (Timer Trigger)
Function: Alternate display every 6 seconds (temperature 3s, humidity 3s)
Web Interface Configuration Steps
Rule 1: Display Temperature
Click Peripheral Configuration in the left menu → Switch to Peripheral Execution Management tab
Click Add Rule button
Fill in basic configuration:
- Rule Name:
Display Temperature - Report Data: ✅ Enabled
- Enable: ✅ Enabled
- Rule Name:
Configure trigger:
- Trigger Type: Select Timer Trigger
- Timer Mode: Select Fixed Interval
- Interval:
6000(6 seconds) - Time Offset:
0(0 second offset)
Configure actions (2 actions required):
- Action 1: Select Sensor Read, target
dht1 - Action 2: Select Seven-Segment Display, target
tm1637_1, template{dht1.temperature}
- Action 1: Select Sensor Read, target
Click Save button
Rule 2: Display Humidity
- Create another rule, name:
Display Humidity - Trigger configuration:
- Trigger Type: Select Timer Trigger
- Interval:
6000(6 seconds) - Time Offset:
3000(3 second offset, staggered from temperature)
- Action configuration:
- Action 1: Select Sensor Read, target
dht1 - Action 2: Select Seven-Segment Display, target
tm1637_1, template{dht1.humidity}
- Action 1: Select Sensor Read, target
- Click Save
Scenario 2: Temperature Alarm Blink (Poll Trigger)
Function: Seven-segment display blinks and buzzer triggers when temperature exceeds 35°C
Configuration Steps:
- Create a rule, name:
High Temp Blink - 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 Seven-Segment Display, target
tm1637_1, template{dht1.temperature}, ✅ Enable blink - Action 2: Select HIGH, target
buzzer1(buzzer must be configured in advance)
- Action 1: Select Seven-Segment Display, target
- Click Save
Complete Configuration Import
[
{
"id": "dht1",
"name": "DHT11 Temp & Humidity",
"type": 38,
"enabled": false,
"pins": [32],
"params": {
"driver": "DHT",
"model": "DHT11",
"interval": 3000
}
},
{
"id": "tm1637_1",
"name": "Four-Digit Seven-Segment",
"type": 47,
"enabled": false,
"pins": [18, 19],
"params": {
"brightness": 4,
"colon": true
}
}
]Display Output
TM1637 four-digit seven-segment display:
Temperature mode: 25.3 (shows 25.3, colon blinks to indicate active sampling)
Humidity mode: 60.5 (shows 60.5)- Supports displaying values from 0-9999
- Supports one decimal point
- Colon can indicate status (blinking = normal, steady = alarm)
Comparison with OLED Solution
| Feature | TM1637 Seven-Segment | SSD1306 OLED |
|---|---|---|
| Display Content | Numbers only | Text + graphics |
| Viewing Distance | Far (5-10m) | Near (< 1m) |
| Power Consumption | Higher | Very low |
| Suitable Scenarios | Factory/greenhouse/server room | Desktop/portable devices |
| Information Capacity | Low (4 digits) | High (multi-line text) |
Notes
- Display Precision: TM1637 has only 4 digits, temperature shows
25.3, humidity60.5 - Data Format: Sensor values are automatically truncated to displayable digits
- Brightness Adjustment: Adjust brightness parameter per ambient light (0=dimmest, 7=brightest)
- Refresh Rate: Recommend ≥ 1000ms refresh interval, too fast causes flickering
- Pin Conflict: CLK/DIO can use any GPIO, avoid conflict with SPI devices
