Working Principle
The DS18B20 is a digital temperature sensor from Maxim Integrated. Inside its TO-92 package sits a silicon bandgap temperature sensor whose output voltage is proportional to absolute temperature. An on-chip 12-bit ADC converts that voltage directly into a digital value transmitted over a proprietary 1-Wire bus.
Analogy: Imagine a mercury thermometer that, instead of expanding a column of liquid, sends a text message with the exact temperature. The DS18B20 is that self-reporting thermometer.
Electrical Characteristics
| Parameter | Value |
|---|---|
| Supply Voltage | 3.0 V – 5.5 V |
| Temperature Range | −55 °C to +125 °C |
| Accuracy (−10 to +85 °C) | ± 0.5 °C |
| Resolution | 9–12 bit (configurable) |
| Conversion Time (12-bit) | 750 ms max |
| Interface | 1-Wire (single data pin + GND) |
| Parasitic Power | Supported (data line powers device) |
Interfacing with an MCU
The 1-Wire protocol requires only one GPIO pin plus a 4.7 kΩ pull-up resistor to VCC. Multiple DS18B20 sensors can share the same data line because each has a unique 64-bit ROM address.
Calibration
The DS18B20 is factory-calibrated, but for applications needing < 0.5 °C accuracy:
- Ice-point calibration: Submerge in ice-water slurry (0.0 °C); record offset.
- Two-point calibration: Use ice water and boiling water; derive gain and offset.
- Software correction:
T_corrected = T_raw - offset
Code Example
/*
* DS18B20 Temperature Reader — Arduino
* Requires: OneWire library, DallasTemperature library
* Wiring: DQ → Pin 2, 4.7kΩ pull-up to 5V
*/
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 /* Data pin */
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup(void) {
Serial.begin(9600);
sensors.begin(); /* Detect all sensors on bus */
Serial.print("Found ");
Serial.print(sensors.getDeviceCount());
Serial.println(" sensor(s).");
}
void loop(void) {
sensors.requestTemperatures(); /* Trigger conversion */
float tempC = sensors.getTempCByIndex(0);
if (tempC == DEVICE_DISCONNECTED_C) {
Serial.println("Error: sensor disconnected!");
} else {
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.println(" °C");
}
delay(1000);
}
Real-World Applications
Cold-Chain Monitoring
Pharmaceutical warehouses string dozens of DS18B20 sensors on a single 1-Wire bus to monitor fridge and freezer temperatures continuously. Each sensor’s unique ROM address allows individual tracking with only one MCU GPIO.
Limitations
- Slow conversion: 750 ms at 12-bit — unsuitable for high-speed control loops.
- Limited range: Max 125 °C; use RTDs or thermocouples for furnace temperatures.
- Long cable runs: 1-Wire timing degrades beyond ~20 m without active pull-up drivers.
- Parasitic power fragility: Heavy bus loads can brown-out parasitic-powered sensors.