Overview
The DS18B20 is a digital temperature sensor with a beautifully simple wiring story: power, ground, and a single data wire. This waterproof version embeds the chip inside a stainless-steel probe with a 1-meter PVC-jacketed cable — perfect for water tanks, pipes, soil temperature, fish tanks, sous-vide projects, or anywhere a bare sensor would corrode.
Each DS18B20 communicates over Maxim's 1-Wire protocol and ships with a unique 64-bit factory-burned ID. That means you can put dozens of probes on the same data line and address each one individually — ideal for multi-zone temperature monitoring without burning a GPIO per sensor. Resolution is configurable from 9 to 12 bits, with +/-0.5 degC accuracy across most of its -55 to +125 degC range.
It works with Arduino, ESP32, Raspberry Pi, and Pico through readily available libraries (DallasTemperature for Arduino-class boards, w1-therm on Raspberry Pi).
At a Glance
Specifications
| Parameter | Value |
| Sensor IC | Maxim Integrated DS18B20 |
| Operating Voltage | 3.0V - 5.5V DC |
| Operating Current | 1 mA active, 1 uA standby |
| Temperature Range | -55 degC to +125 degC |
| Accuracy | +/-0.5 degC (from -10 to +85 degC) |
| Resolution | 9-bit (0.5 degC) to 12-bit (0.0625 degC), user-configurable |
| Conversion Time (12-bit) | ~750 ms |
| Protocol | 1-Wire (Maxim/Dallas) |
| Pull-up Resistor | 4.7k from data to VCC (required) |
| Unique ID | 64-bit factory-burned, allows multiple sensors on one bus |
| Probe Material | Stainless steel |
| Cable Length | ~1 meter (PVC jacket) |
| Wires | 3 (Red = VCC, Yellow = Data, Black = GND) |
Pinout Diagram
Wiring Guide
Arduino Wiring
The DS18B20 needs a 4.7k pull-up resistor between the Data line and VCC for the 1-Wire bus to work. Don't skip this — without it, you'll get garbage readings or no response at all.
| Probe Wire | Arduino Pin |
|---|---|
| Red (VCC) | 5V |
| Black (GND) | GND |
| Yellow (Data) | Digital Pin 2 |
ESP32 Wiring
Same 4.7k pull-up requirement. The DS18B20 is happy at 3.3V, so power the probe from the ESP32's 3V3 rail and pull-up to 3V3 as well.
| Probe Wire | ESP32 Pin |
|---|---|
| Red (VCC) | 3V3 |
| Black (GND) | GND |
| Yellow (Data) | GPIO 4 (with 4.7k pull-up to 3V3) |
Raspberry Pi Wiring
On the Pi, the 1-Wire driver is built into the Linux kernel. By default it uses GPIO 4 (Pin 7). Enable the 1-Wire interface in raspi-config > Interface Options.
| Probe Wire | Raspberry Pi Pin |
|---|---|
| Red (VCC) | Pin 1 (3.3V) |
| Black (GND) | Pin 6 (GND) |
| Yellow (Data) | Pin 7 (GPIO 4) with 4.7k pull-up to 3.3V |
sudo raspi-config > Interface Options > 1-Wire > Enable, then reboot.
/sys/bus/w1/devices/28-XXXXXXXXXXXX/w1_slave. Read that file to get the temperature.
Raspberry Pi Pico Wiring
MicroPython for the Pico has built-in 1-Wire support via the onewire and ds18x20 modules. Pull-up still required.
| Probe Wire | Pico Pin |
|---|---|
| Red (VCC) | 3V3 (OUT) |
| Black (GND) | GND |
| Yellow (Data) | GP15 (with 4.7k pull-up to 3V3) |
Code Examples
Arduino - Read One Sensor
// DS18B20 - Read temperature on Arduino
// Wire: Red=5V, Black=GND, Yellow=D2 with 4.7k pull-up to 5V
// Install libraries: OneWire, DallasTemperature
#include <OneWire.h>
#include <DallasTemperature.h>
const int ONE_WIRE_BUS = 2;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
sensors.begin();
}
void loop() {
sensors.requestTemperatures();
float c = sensors.getTempCByIndex(0);
float f = c * 9.0 / 5.0 + 32.0;
Serial.print("Temp: "); Serial.print(c, 2); Serial.print(" C / ");
Serial.print(f, 2); Serial.println(" F");
delay(1000);
}
Arduino - Multiple Sensors on Same Bus
// DS18B20 - Multiple probes sharing one data wire
// All sensors share Red, Black, Yellow; one 4.7k pull-up for the whole bus
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(2);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
sensors.begin();
Serial.print("Found "); Serial.print(sensors.getDeviceCount()); Serial.println(" sensors");
}
void loop() {
sensors.requestTemperatures();
for (int i = 0; i < sensors.getDeviceCount(); i++) {
Serial.print("Sensor "); Serial.print(i); Serial.print(": ");
Serial.print(sensors.getTempCByIndex(i)); Serial.println(" C");
}
Serial.println("---");
delay(2000);
}
Raspberry Pi (Python)
#!/usr/bin/env python3
# DS18B20 on Raspberry Pi via 1-Wire kernel driver
# Enable 1-Wire first: sudo raspi-config -> Interface Options -> 1-Wire
import glob, time
base = "/sys/bus/w1/devices/"
device = glob.glob(base + "28-*")[0] + "/w1_slave"
def read_temp():
with open(device, "r") as f:
lines = f.readlines()
while not lines[0].strip().endswith("YES"):
time.sleep(0.2)
with open(device, "r") as f:
lines = f.readlines()
pos = lines[1].find("t=")
if pos != -1:
return float(lines[1][pos+2:]) / 1000.0
return None
while True:
c = read_temp()
print("Temp: {:.2f} C / {:.2f} F".format(c, c * 9/5 + 32))
time.sleep(1)
Raspberry Pi Pico - MicroPython
# DS18B20 on Raspberry Pi Pico (MicroPython)
# Wire: Red=3V3, Black=GND, Yellow=GP15 with 4.7k pull-up to 3V3
from machine import Pin
import onewire, ds18x20, time
ow = onewire.OneWire(Pin(15))
ds = ds18x20.DS18X20(ow)
roms = ds.scan()
print("Found", len(roms), "DS18B20 sensors")
while True:
ds.convert_temp()
time.sleep_ms(750)
for rom in roms:
c = ds.read_temp(rom)
print("{}: {:.2f} C".format(bytes(rom).hex(), c))
time.sleep(1)