The DS18B20 is a digital temperature sensor most often sold as a sealed, waterproof stainless probe on a cable, which is exactly what you want for soil, water, and rough outdoor spots where the air-only sensors cannot go. It is accurate enough, rugged, cheap, and has a neat trick: many probes can share a single data pin.
What it is.
The DS18B20 measures temperature only, and reports it digitally over the one-wire “Dallas” bus. The reason it shows up everywhere outdoors is the packaging: the common version seals the chip inside a stainless tube on a cable, so you can push it into soil, drop it in a tank, or strap it to a pipe without worrying about moisture. It is the right tool when you need temperature in a place a DHT22 or SHT31 would not survive. It does not measure humidity.
Many on two wires.
The handy part: every DS18B20 has a unique 64-bit address baked in, and the one-wire bus lets you hang several probes off the same data pin and read each by its address. So one microcontroller pin can monitor soil temperature at four depths, or a tank top and bottom, with a single wire run. That makes it cheap to scale a temperature map across a bench or a bed.
Key facts.
How to wire it.
Three connections: VCC, GND, and DATA to a GPIO, with a 4.7 kΩ pull-up resistor from data to VCC (one pull-up covers the whole bus, however many probes you hang on it). On the waterproof probe the wires are usually red (VCC), black (GND), and yellow or white (data). In ESPHome it is read with the Dallas temperature component over a one-wire bus; in the Arduino IDE the DallasTemperature library handles it. Address each probe if you run more than one.
Where it fits, and where it doesn’t.
Where it fits
- Soil temperature, at one or several depths.
- Water and nutrient-tank temperature.
- Wet or rough spots that would kill an air sensor.
- Many temperature points on one data pin.
Where it doesn’t
- Humidity; it measures temperature only.
- Air climate plus humidity; use an SHT31.
- Sub-degree precision; it is good, not laboratory-grade.
- Without the pull-up resistor; it will not read.
Datasheet & where to buy.
ESPHome: Dallas temperature Analog Devices DS18B20 Where to buy Compare temp & humidity sensors
Frequently asked questions.
What is a DS18B20 used for?
It measures temperature, most often as a sealed waterproof probe for soil, water, and tanks where an air sensor cannot go. It is rugged, cheap, accurate to about half a degree, and a favorite for soil and water temperature in growing.
Is the DS18B20 waterproof?
The chip itself is not, but it is most commonly sold sealed inside a stainless steel probe on a cable, which is fully waterproof. That sealed-probe version is the one to buy for soil and water; bare versions exist for dry, in-enclosure use.
Can I connect several DS18B20 sensors to one pin?
Yes. Each sensor has a unique 64-bit address, and the one-wire bus lets you hang many on the same data pin and read each by its address. One 4.7 kilohm pull-up resistor covers the whole bus, which makes mapping temperature at several points cheap.
Does the DS18B20 measure humidity?
No, temperature only. If you need humidity as well, use an air sensor like the DHT22 or, for better accuracy, the SHT31. The DS18B20 is the choice specifically for temperature in wet or rugged places.
Why does my DS18B20 read -127 or 85?
Those are its error and power-on default values, usually meaning a wiring problem: a missing 4.7 kilohm pull-up resistor on the data line, a loose connection, or too long a cable run. Check the pull-up and connections first.