PyRaspBeta

DS18B20 probe module

The DS18B20 probe module is the DS18B20 digital thermometer with its 4.7 kΩ pull-up resistor fitted, the value the 1-Wire bus wants. It costs $6 and is for accurate temperature sensing over a long cable: thermostats, hot water, soil, any probe that has to sit away from the Pi. Wire VDD to 3.3 V, DQ to GPIO4 and GND to ground, then read the kernel's 1-Wire files.

What's inside

PartQtyPrice each
DS18B20 thermometer1$4
Resistor1$0.25
Total2$4.25
  • The DS18B20 converts on demand and reports to 0.0625 °C resolution (±0.5 °C accuracy), identifying itself with a unique 64-bit ROM code.
  • The 4.7 kΩ resistor pulls DQ up to the supply, because 1-Wire devices only pull the bus low; 4.7 kΩ is the datasheet's value.
Exposed pinInside the kit
vddt:VDD
dqt:DQ
gndt:GND

DQ must reach GPIO4: that is the Pi's default 1-Wire pin and the only one the simulator (and the dtoverlay=w1-gpio default on a real Pi) answers on. The kit has no chain ends.

Wiring it in circuit.py

circuit.py
from wiring import *

pi = Pi()
probe = kits.DS18B20Module()

pi.V3_3 >> probe.vdd
pi.GPIO4 >> probe.dq
probe.gnd >> pi.GND

Driving it in main.py

main.py
import glob
from time import sleep

device = glob.glob("/sys/bus/w1/devices/28-*/w1_slave")[0]

while True:
    lines = open(device).read().splitlines()
    if lines[0].endswith("YES"):
        millidegrees = int(lines[1].rsplit("t=", 1)[1])
        print(f"{millidegrees / 1000:.1f} C")
    sleep(1)

Why buy the kit

Loose parts cost $4 + $0.25 = $4.25, against $6 — $1.75 for the pull-up fitted and the probe terminated on a board. On a breadboard the 4.7 kΩ resistor is easy to miss and the bus quietly returns nothing; the module turns the three connections into the whole job.

Simulator vs real hardware

  • The 1-Wire bus is simulated at the transaction level: /sys/bus/w1/devices/28-* folders appear when the program starts (the wiring cannot change mid-run), and each read re-samples the probe and waits the conversion time — 750 ms at the default 12 bits.
  • About 1 % of reads come back with a bad CRC (crc=.. NO), so real code checks the YES line as above and retries; a bad read is not an error, just a skipped sample.
  • Each part draws one fixed ROM code from its seed, so it stays the same probe across the run.

Further reading