DS18B20
digital temperature sensor (also waterproof)
An accurate temperature sensor (±0.5 °C) that sends a digital value over a single wire. It comes as a small transistor package (TO-92) and as a waterproof probe for water, soil or a fridge.
Open the course →How it works
It uses the 1-Wire protocol: one data line (DQ) with a 4.7 kΩ pull-up resistor to 3.3 V. Every sensor has a unique 64-bit serial number, so dozens of sensors can share the same wire. The ESP32 says "measure", the sensor measures for up to 750 ms (at 12-bit precision), then returns the temperature. The OneWire and DallasTemperature libraries do all of that.
Pins and wiring
| Pin | What it is | Where it connects / why |
|---|---|---|
| GND | Ground (left leg, flat side facing you) | → GND. |
| DQ | Data (middle leg) | → GPIO (e.g. 4) + 4.7 kΩ to 3.3 V. |
| VDD | Supply (right leg) | → 3V3. |
Specifications
Range−55 to +125 °C
Accuracy±0.5 °C (−10…+85 °C)
Resolution9–12 bit (0.5–0.0625 °C)
Conversion timeup to 750 ms at 12 bit
Supply3.0–5.5 V
Tips and typical mistakes
- Reading −127 °C? The sensor is not seen — no pull-up, or it is reversed.
- Reading 85 °C? That is the power-up value: it was read before the measurement finished.
- Reversed, it heats up very fast — disconnect it immediately!