← How-Tos
raspberry-pi 1 hr ago ◯ 5 min read

1-Wire Temperature Sensing on Raspberry Pi: DS18B20 Multi-Sensor Bus Wiring and Parasitic Power

raspberry piDS18B201-wiretemperature sensorGPIO

Most Raspberry Pi temperature projects reach for a DHT22 or an I2C sensor like the BME280, and both are fine choices for a single sensor. But the moment you need several temperature readings around one project — multiple zones in an enclosure, several points along a duct, a print farm room with sensors at different shelf heights — 1-Wire and the DS18B20 solve a problem I2C and single-GPIO sensors don't: dozens of sensors sharing one data wire, each with its own factory-programmed unique address, no addressing conflicts to manage yourself.

How 1-Wire Actually Works

1-Wire is Maxim/Dallas's protocol for putting both data and (optionally) power on a single conductor plus ground. Every DS18B20 ships with a unique 64-bit ROM address burned in at the factory, so the bus master (your Pi) can address each sensor individually without any manual ID configuration, DIP switches, or software addressing scheme — you just scan the bus and get back a list of sensor IDs. This is the practical advantage over I2C for this specific use case: I2C sensors of the same model usually share a fixed address or a tiny range of address-select pins, which caps how many identical sensors you can put on one bus. 1-Wire has no such practical limit for temperature sensing — dozens of DS18B20s on one bus is normal.

Wiring

DS18B20 PinConnects ToNotes GNDPi GND (e.g. pin 6)Common ground for all sensors on the bus DATAPi GPIO4 (pin 7) by defaultAny GPIO works if you set the device tree overlay accordingly, but GPIO4 is the Raspberry Pi OS default and needs no extra configuration VDDPi 3.3V (pin 1) — external power modeSimplest and most reliable mode for a handful of sensors; use this unless you have a specific reason to run parasitic power Pull-up resistor4.7kΩ between DATA and 3.3VRequired on every 1-Wire bus — without it, bus communication is unreliable or fails outright. One resistor covers the whole bus, not one per sensor.

For multiple sensors, wire all of them in parallel on the same three signal lines (GND, DATA, VDD) — 1-Wire is a true bus topology, not a star or daisy-chain requirement, though keeping wiring reasonably close to a line topology (rather than a tangle of long stubs) improves reliability on longer runs.

Parasitic Power vs External Power

The DS18B20 can run in "parasitic power" mode, stealing power from the data line itself and omitting the VDD connection entirely — useful when you're routing a sensor on just two wires (handy for waterproof probe versions with long thin cables). The tradeoff is real: parasitic power requires the bus master to actively pull the data line high during the sensor's temperature conversion, and with more than a couple of sensors, or runs longer than a few meters, this becomes unreliable — you'll see intermittent read failures or all-zero/garbage readings. For anything beyond a single sensor or a very short run, wire the VDD pin to 3.3V and skip parasitic mode entirely; it removes an entire class of flaky-read troubleshooting for the cost of one extra wire.

Enabling 1-Wire on Raspberry Pi OS

Enable the 1-Wire interface either through raspi-config (Interface Options → 1-Wire) or by adding dtoverlay=w1-gpio to /boot/firmware/config.txt (or /boot/config.txt on older OS releases) and rebooting. This loads the w1-gpio and w1-therm kernel modules, which expose each detected sensor as a directory under /sys/bus/w1/devices/, named by its unique ROM address (e.g. 28-000005e1a2b3). Reading a sensor is as simple as reading the w1_slave file in that directory — no root permissions or special libraries required for a quick test:

cat /sys/bus/w1/devices/28-000005e1a2b3/w1_slave

The output includes a CRC check result and the temperature in millidegrees Celsius on the last line. For anything beyond quick testing, the w1thermsensor Python package wraps this sysfs interface cleanly, handles multi-sensor discovery automatically, and returns temperatures in your unit of choice without you needing to parse the raw file yourself.

Multi-Sensor Identification

Since every sensor's address is unique and permanent, the practical workflow for a multi-zone project is: wire all sensors to the bus, run a scan to list every detected ROM address, then physically label or note which physical sensor corresponds to which address (a sticky note at install time saves real troubleshooting time later) before writing zone-mapping logic in your monitoring script. There's no way to reassign or shorten these addresses — treat the 64-bit ROM ID as the sensor's permanent name in your code, or maintain a simple lookup table mapping addresses to zone labels.

Troubleshooting

SymptomLikely CauseFix No sensors detected at allOverlay not loaded, or missing pull-up resistorConfirm dtoverlay=w1-gpio is active and reboot; verify the 4.7k pull-up is actually between DATA and 3.3V, not floating Reading returns 85000 (85°C) consistentlySensor hasn't completed a conversion, or a wiring/power issue85°C is the DS18B20's power-on default value — it means you're reading before or without a valid conversion. Check power wiring first. CRC check fails intermittentlyNoise on a long run, or parasitic power strugglingSwitch to external power (VDD wired) if using parasitic mode; use twisted-pair or shielded cable for runs over a few meters; add a stronger pull-up (e.g. 2.2kΩ) if the bus is long or has many sensors Some sensors drop out under load with several others presentBus loading / pull-up too weak for the sensor countReduce the pull-up value slightly (stronger pull) or split sensors across two separate GPIO buses if you're running 15+ sensors

For a handful of temperature points around a project — a filament dry box, a multi-zone incubator, a shed or crawlspace monitoring setup — 1-Wire with the DS18B20 is genuinely less wiring and less code than the equivalent number of separate I2C or analog sensors would require, precisely because addressing is solved for you at the hardware level. It's not the right choice for high sample-rate or precision work (I2C sensors with faster conversion times and tighter tolerances win there), but for "how many degrees is it, at these ten points, checked every few seconds" it's hard to beat.