Example 18: DS18B20 Temperature Sensor
Example 18: DS18B20 Temperature Sensor
Experiment Overview
DS18B20 is a one-wire digital temperature sensor with a measurement range of -55°C~+125°C and ±0.5°C accuracy. FastBee has a built-in ONE_WIRE peripheral type (type: 44) that directly supports DS18B20.
Hardware Wiring
| Board Label | GPIO Pin | Connected Device |
|---|---|---|
| DATA | GPIO4 | DS18B20 data line (requires 4.7kΩ pull-up resistor) |
DS18B20 three-wire connection: VCC→3.3V, GND→GND, DATA→GPIO + 4.7kΩ pull-up to VCC.
JSON Configuration Example
{
"peripherals": [
{
"id": "ds18b20_01",
"name": "DS18B20 Temperature",
"type": 44,
"enabled": false,
"pins": [4],
"params": {}
}
]
}Peripheral Execution Linkage
Scenario 1: Periodic Temperature Acquisition (Timer Trigger)
Function: Read DS18B20 temperature 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:
Temperature Acquisition - 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 Timer Trigger Periodic acquisition Timer Mode Select Fixed Interval By millisecond interval Interval Time 50005 seconds
Step 3: Configure Action
Click Add Action button
Fill in:
- Action Type: Select Read Sensor
- Target Peripheral: Select
ds18b20_01 - Data Field:
temperature
Click Save button
Scenario 2: Temperature Over-Limit Alarm (Poll Trigger)
Function: Check temperature every 5 seconds, trigger buzzer alarm when temperature exceeds 40°C
Web Interface Configuration Steps
Step 1: Ensure buzzer peripheral is configured
- Peripheral ID:
buzzer_gpio - Type: GPIO Output
Step 2: Create Rule
- Click New Rule
- Fill in basic configuration:
- Rule Name:
High Temperature Alarm - Report Data: ✅ Enable
- Enabled: ✅ Enable
- Rule Name:
Step 3: Configure Trigger (Poll Trigger)
Click Add Trigger button
Fill in trigger configuration:
Field Value Description Trigger Type Select Poll Trigger Periodically detect condition Target Peripheral Select ds18b20_01Temperature sensor Poll Interval 50005 seconds Condition Expression temperature > 40Temperature greater than 40°C
Step 4: Configure Actions (2 actions needed)
Action 1: Buzzer Alarm
- Click Add Action button
- Fill in:
- Action Type: Select HIGH Level
- Target Peripheral: Select
buzzer_gpio
Action 2: Send Alarm Event
Click Add Action button again
Fill in:
- Action Type: Select Send Event
- Event Type:
alarm - Event Message:
Temperature too high
Click Save button
DS18B20 Features
| Feature | Parameter | Description |
|---|---|---|
| Measurement Range | -55°C ~ +125°C | Wide temperature range |
| Accuracy | ±0.5°C | High precision |
| Resolution | 9-12 bit adjustable | Default 12 bit |
| Conversion Time | 750ms (12 bit) | Auto wait |
| Bus Type | OneWire | Can mount multiple devices |
Notes
- Pull-up Resistor: Must connect 4.7kΩ resistor between data line and VCC
- Bus Length: Short distance (<5m) uses 4.7kΩ, longer distances need lower resistance
- Multi-Device: Multiple DS18B20 can be mounted on the same bus (each has a unique 64-bit ID)
- Conversion Time: ~750ms at 12-bit precision, FastBee handles waiting internally
- Parasitic Power: Supports two-wire (DATA+GND) parasitic power mode, but three-wire is recommended
- Waterproof: Waterproof DS18B20 probes in stainless steel housing are available
