DS18B20 Digital Temperature Sensor
About 2 min
DS18B20 Digital Temperature Sensor
Overview
DS18B20 is a 1-Wire (OneWire) digital temperature sensor with a measurement range of -55°C to +125°C and accuracy of ±0.5°C. Multiple sensors can be mounted on the same bus.
Supported Peripheral Types
| Type | type Value | Sensor Category |
|---|---|---|
| SENSOR | 38 | SENSOR_DS18B20 (5) |
Hardware Wiring
| DS18B20 Pin | Connection | Description |
|---|---|---|
| VCC | 3.3V / 5V | Power supply |
| GND | GND | Ground |
| DQ | GPIO + 4.7KΩ pull-up to VCC | Data line |
The data line must have an external 4.7KΩ pull-up resistor to VCC, otherwise communication will be unstable.
Configuration
Method 1: Web Interface Configuration (Recommended)
Before saving DS18B20 configuration, verify OneWire pin, pull-up resistor, and sensor ID.
Step 1: Navigate to Peripheral Management Page
- Open a browser and navigate to the ESP32 IP address
- After logging in, click Peripheral Configuration in the left menu
Step 2: Add DS18B20 Peripheral
Click the Add Peripheral button
Fill in the configuration:
Field Value Description Peripheral ID ds18b20_1Unique identifier Name Water Temperature SensorDisplay name Peripheral Type Generic Sensor (type: 38) DS18B20 driver Pin Configuration 4DQ data pin Sensor Category DS18B20Temperature sensor Sampling Interval 20002 seconds (≥750ms) Click Save
Step 3: Verify Configuration
- Find the newly added peripheral in the peripheral list
- Click the Enable toggle
- Wait 2 seconds and check temperature data
⚠️ Important: Data line must have an external 4.7KΩ pull-up resistor to VCC
Method 2: JSON Configuration File Import
Add the following configuration to the peripherals array in data/config/peripherals.json:
Single DS18B20
{
"id": "ds18b20_1",
"name": "Water Temperature Sensor",
"type": 38,
"enabled": false,
"pins": [4],
"params": {
"sensorType": 5,
"sampleInterval": 2000
}
}Parameter Description
| Parameter | Description |
|---|---|
| sensorType | Sensor category: 5 = DS18B20 |
| sampleInterval | Sampling interval (ms), minimum 750ms (conversion time) |
Peripheral Execution Integration
Web Interface Configuration Steps
Create Timed Collection Rule
- Switch to the Peripheral Execution Management tab
- Click the Add Rule button
- Configure timer trigger:
- Trigger Type: Timer Trigger
- Execution Interval: 60 seconds
- Add action:
- Action Type: Sensor Read
- Target Peripheral: ds18b20_1
- Enable Report Data After Execution
- Click Save
Create Temperature Threshold Alarm Rule
- Create a new rule
- Configure platform trigger:
- Trigger Type: Platform Trigger
- Data Source: ds18b20_1
- Comparison: Greater Than
- Comparison Value: 60
- Add action:
- Action Type: High Level
- Target Peripheral: buzzer (buzzer)
- Click Save
JSON Configuration Example
Timed Temperature Collection
{
"id": "exec_ds18b20_read",
"name": "Timed Water Temperature Collection",
"enabled": false,
"execMode": 0,
"triggers": [
{
"triggerType": 1,
"triggerPeriphId": "",
"operatorType": 0,
"compareValue": "",
"timerMode": 0,
"intervalSec": 60,
"timePoint": "",
"eventId": "",
"pollResponseTimeout": 1000,
"pollMaxRetries": 2,
"pollInterPollDelay": 100
}
],
"actions": [
{
"targetPeriphId": "ds18b20_1",
"actionType": 19,
"actionValue": "",
"useReceivedValue": false,
"syncDelayMs": 0,
"execMode": 0
}
],
"protocolType": 0,
"scriptContent": "",
"reportAfterExec": true
}Temperature Threshold Alarm
{
"id": "exec_ds18b20_alarm",
"name": "Water Temperature Over-limit Alarm",
"enabled": false,
"execMode": 0,
"triggers": [
{
"triggerType": 0,
"triggerPeriphId": "ds18b20_1",
"operatorType": 2,
"compareValue": "60",
"timerMode": 0,
"intervalSec": 60,
"timePoint": "",
"eventId": "",
"pollResponseTimeout": 1000,
"pollMaxRetries": 2,
"pollInterPollDelay": 100
}
],
"actions": [
{
"targetPeriphId": "buzzer",
"actionType": 0,
"actionValue": "",
"useReceivedValue": false,
"syncDelayMs": 0,
"execMode": 0
}
],
"protocolType": 0,
"scriptContent": "",
"reportAfterExec": true
}Comparison with DHT Sensors
| Feature | DS18B20 | DHT11/DHT22 |
|---|---|---|
| Measured Parameters | Temperature only | Temperature + Humidity |
| Accuracy | ±0.5°C | ±2°C / ±0.5°C |
| Range | -55~125°C | 0~50°C / -40~80°C |
| Interface | OneWire | Single-bus (custom protocol) |
| Multi-Sensor | Supports multiple on one bus | Each requires independent pin |
| Waterproof | Available in waterproof package | Not waterproof |
Notes
- Pull-up Resistor: 4.7KΩ pull-up resistor is essential; use smaller pull-up (e.g., 2.2KΩ) for long wire runs
- Conversion Time: At 12-bit precision, conversion time is approximately 750ms; sampling interval should not be less than this
- Power Mode: Recommend external power mode (VCC connected to 3.3V/5V); avoid using parasitic power
- Bus Length: Standard wiring can reach 100m, but signal quality must be considered
- Multi-Sensor: Multiple DS18B20 sensors can be connected to the same pin, distinguished by ROM address
