Skip to content

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 LabelGPIO PinConnected Device
DATAGPIO4DS18B20 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 ​

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

  1. Click Peripheral Execution in the left menu
  2. Click New Rule button
  3. Fill in basic configuration:
    • Rule Name: Temperature Acquisition
    • Report Data: ✅ Enable
    • Enabled: ✅ Enable

Step 2: Configure Trigger

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Timer TriggerPeriodic acquisition
    Timer ModeSelect Fixed IntervalBy millisecond interval
    Interval Time50005 seconds

Step 3: Configure Action

  1. Click Add Action button

  2. Fill in:

    • Action Type: Select Read Sensor
    • Target Peripheral: Select ds18b20_01
    • Data Field: temperature
  3. 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

  1. Click New Rule
  2. Fill in basic configuration:
    • Rule Name: High Temperature Alarm
    • Report Data: ✅ Enable
    • Enabled: ✅ Enable

Step 3: Configure Trigger (Poll Trigger)

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Poll TriggerPeriodically detect condition
    Target PeripheralSelect ds18b20_01Temperature sensor
    Poll Interval50005 seconds
    Condition Expressiontemperature > 40Temperature greater than 40°C

Step 4: Configure Actions (2 actions needed)

Action 1: Buzzer Alarm

  1. Click Add Action button
  2. Fill in:
    • Action Type: Select HIGH Level
    • Target Peripheral: Select buzzer_gpio

Action 2: Send Alarm Event

  1. Click Add Action button again

  2. Fill in:

    • Action Type: Select Send Event
    • Event Type: alarm
    • Event Message: Temperature too high
  3. Click Save button

DS18B20 Features ​

FeatureParameterDescription
Measurement Range-55°C ~ +125°CWide temperature range
Accuracy±0.5°CHigh precision
Resolution9-12 bit adjustableDefault 12 bit
Conversion Time750ms (12 bit)Auto wait
Bus TypeOneWireCan mount multiple devices

Notes ​

  1. Pull-up Resistor: Must connect 4.7kΩ resistor between data line and VCC
  2. Bus Length: Short distance (<5m) uses 4.7kΩ, longer distances need lower resistance
  3. Multi-Device: Multiple DS18B20 can be mounted on the same bus (each has a unique 64-bit ID)
  4. Conversion Time: ~750ms at 12-bit precision, FastBee handles waiting internally
  5. Parasitic Power: Supports two-wire (DATA+GND) parasitic power mode, but three-wire is recommended
  6. Waterproof: Waterproof DS18B20 probes in stainless steel housing are available

FastBee | fastbee.cn