Skip to content

Verify a DS18B20 conversion

Discover one addressed DS18B20, wait for its 12-bit conversion, and verify positive and negative readings without accepting protocol error values.

Physics Phoebe: I want you to prove identity and conversion completion before trusting the temperature., your practice guide

Physics Phoebe: I want you to prove identity and conversion completion before trusting the temperature.
Predict the reading, then compare it with the measurement.

Wokwi ESP32

Third party Tool

Discover one addressed DS18B20, wait for its 12-bit conversion, and verify positive and negative readings without accepting protocol error values.

Tier 1 · Web · No account

Version tested: Compiled and booted by the Wokwi gate (ESP32 Arduino core 3.3.11); captured in the Wokwi web editor on 2026-09-09. Date: 2026-09-09.

Open the ESP32 editor, paste diagram.json, then paste sketch.ino.

Open Wokwi to paste in the files (new tab)

Get the files

Use both prepared files. This is a paste-in setup; saving a project requires a Wokwi account.

diagram.json

774 bytes · Circuit connections

Download

sketch.ino

1,282 bytes · ESP32 program

Download

  1. Use the launch button above to open the ESP32 editor in Wokwi.
  2. Select the editor’s diagram.json tab and replace all its text with the supplied diagram.json.
  3. Select the sketch.ino tab, replace all its text with the supplied sketch.ino, then click Start Simulation.

Steps

Screens captured against Wokwi ESP32 Compiled and booted by the Wokwi gate (ESP32 Arduino core 3.3.11); captured in the Wokwi web editor on 2026-09-09 on 2026-09-09; the tool may have moved on — the text steps are the contract.

  1. 1 Step 1

    Do
    Paste diagram.json and sketch.ino into a new Wokwi ESP32 project, then trace the 1-Wire circuit.
    You will see
    The DS18B20 data pin reaches GPIO4 and a 4.7 kOhm resistor pulls the shared line to 3.3 V.
    Why it matters
    The pull-up is part of the digital bus, so discovery evidence is invalid if it is omitted.
    Step 1: The DS18B20 data line connects to GPIO4 with a 4.7 kilohm pull-up. The ring marks the sensor and resistor.
    Step 1 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  2. 2 Step 2

    Do
    Inspect device discovery, the nonblocking conversion request, and the 750 ms wait.
    You will see
    The sketch confirms exactly one address, requests 12-bit conversion, waits 750 ms, and rejects the disconnected sentinel.
    Why it matters
    Address, conversion completion, and validity are separate protocol claims that should remain visible.
    Step 2: The code discovers one device, waits 750 ms after conversion, and rejects disconnected readings. The ring marks the protocol checks.
    Step 2 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  3. 3 Step 3

    Do
    Start the simulation and read the bus discovery line.
    You will see
    ONEWIRE FOUND reports one sensor on GPIO4 with the 4.7 kOhm pull-up.
    Why it matters
    Counting devices before indexing them prevents an absent sensor from becoming a plausible-looking temperature.
    Step 3: ONEWIRE FOUND count=1 pin=4 pullup=4.7k The ring marks successful bus discovery.
    Step 3 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  4. 4 Step 4

    Do
    Read the discovered sensor's ROM code.
    You will see
    The sketch prints one 64-bit hexadecimal address.
    Why it matters
    A stored address is what lets firmware associate a reading with one physical position on a shared bus.
    Step 4: ONEWIRE ADDRESS 280102030405069E The ring marks the discovered ROM code.
    Step 4 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  5. 5 Step 5

    Do
    Leave the sensor at 24 degrees C and inspect the request and result.
    You will see
    After the declared 750 ms conversion wait, the result is 24.00 degrees C with status VALID.
    Why it matters
    The result is accepted only after the resolution-dependent conversion time has elapsed.
    Step 5: CONVERT requested resolution=12bit wait=750ms TEMP value=24.00C status=VALID conversion=750ms The ring marks the completed baseline conversion.
    Step 5 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  6. 6 Step 6

    Do
    Select the DS18B20 and set its temperature to 30 degrees C.
    You will see
    The next completed conversion reports 30.00 degrees C with status VALID.
    Why it matters
    A controlled positive change checks that new data follows a fresh conversion instead of a cached startup value.
    Step 6: TEMP value=30.00C status=VALID conversion=750ms The ring marks the changed positive temperature.
    Step 6 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  7. 7 Step 7

    Do
    Set the DS18B20 temperature to -7 degrees C.
    You will see
    The next completed conversion reports -7.00 degrees C with status VALID.
    Why it matters
    A negative test checks signed temperature handling rather than treating the raw word as unsigned.
    Step 7: TEMP value=-7.00C status=VALID conversion=750ms The ring marks the valid signed temperature.
    Step 7 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)

Chapter checks

These questions refer to the chapter’s examples. Use the return links to review their answers.

  1. Several DS18B20 sensors share one GPIO. What lets the controller distinguish their readings?

    Return to the chapter’s knowledge check
  2. The lab sensor returns the documented incomplete-conversion value. What should the firmware check?

    Return to the chapter’s knowledge check

Caution

Wokwi verifies the digital sequence, not cable integrity, absolute accuracy, self-heating, or waterproof-probe construction. On hardware, verify pin order, use the pull-up, wait for the configured resolution, check CRC and disconnection sentinels, and compare readings with a traceable reference.

Return to Temperature Sensor Labs: Comparing Sensor Types · Browse Labs