Skip to content

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 ​

Typetype ValueSensor Category
SENSOR38SENSOR_DS18B20 (5)

Hardware Wiring ​

DS18B20 PinConnectionDescription
VCC3.3V / 5VPower supply
GNDGNDGround
DQGPIO + 4.7KΩ pull-up to VCCData line

The data line must have an external 4.7KΩ pull-up resistor to VCC, otherwise communication will be unstable.

Configuration ​

Before saving DS18B20 configuration, verify OneWire pin, pull-up resistor, and sensor ID.

Step 1: Navigate to Peripheral Management Page ​

  1. Open a browser and navigate to the ESP32 IP address
  2. After logging in, click Peripheral Configuration in the left menu

Step 2: Add DS18B20 Peripheral ​

  1. Click the Add Peripheral button

  2. Fill in the configuration:

    FieldValueDescription
    Peripheral IDds18b20_1Unique identifier
    NameWater Temperature SensorDisplay name
    Peripheral TypeGeneric Sensor (type: 38)DS18B20 driver
    Pin Configuration4DQ data pin
    Sensor CategoryDS18B20Temperature sensor
    Sampling Interval20002 seconds (≥750ms)
  3. Click Save

Step 3: Verify Configuration ​

  1. Find the newly added peripheral in the peripheral list
  2. Click the Enable toggle
  3. 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 ​

json
{
  "id": "ds18b20_1",
  "name": "Water Temperature Sensor",
  "type": 38,
  "enabled": false,
  "pins": [4],
  "params": {
    "sensorType": 5,
    "sampleInterval": 2000
  }
}

Parameter Description ​

ParameterDescription
sensorTypeSensor category: 5 = DS18B20
sampleIntervalSampling interval (ms), minimum 750ms (conversion time)

Peripheral Execution Integration ​

Web Interface Configuration Steps ​

Create Timed Collection Rule

  1. Click Peripheral Execution in the left menu
  2. Click the Add Rule button
  3. Configure timer trigger:
    • Trigger Type: Timer Trigger
    • Execution Interval: 60 seconds
  4. Add action:
    • Action Type: Sensor Read
    • Target Peripheral: ds18b20_1
  5. Enable Report Data After Execution
  6. Click Save

Create Temperature Threshold Alarm Rule

  1. Create a new rule
  2. Configure platform trigger:
    • Trigger Type: Platform Trigger
    • Data Source: ds18b20_1
    • Comparison: Greater Than
    • Comparison Value: 60
  3. Add action:
    • Action Type: High Level
    • Target Peripheral: buzzer (buzzer)
  4. Click Save

JSON Configuration Example ​

Timed Temperature Collection ​

json
{
  "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 ​

json
{
  "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 ​

FeatureDS18B20DHT11/DHT22
Measured ParametersTemperature onlyTemperature + Humidity
Accuracy±0.5°C±2°C / ±0.5°C
Range-55~125°C0~50°C / -40~80°C
InterfaceOneWireSingle-bus (custom protocol)
Multi-SensorSupports multiple on one busEach requires independent pin
WaterproofAvailable in waterproof packageNot waterproof

Notes ​

  1. Pull-up Resistor: 4.7KΩ pull-up resistor is essential; use smaller pull-up (e.g., 2.2KΩ) for long wire runs
  2. Conversion Time: At 12-bit precision, conversion time is approximately 750ms; sampling interval should not be less than this
  3. Power Mode: Recommend external power mode (VCC connected to 3.3V/5V); avoid using parasitic power
  4. Bus Length: Standard wiring can reach 100m, but signal quality must be considered
  5. Multi-Sensor: Multiple DS18B20 sensors can be connected to the same pin, distinguished by ROM address

FastBee | fastbee.cn