Blog

DS18B20 Digital Temperature Sensor – Complete Guide

1-Wire Digital Temperature Sensor

DS18B20 Digital Temperature Sensor

±0.5°C Accurate, Multi-Drop 1-Wire Interface

The DS18B20 is a digital temperature sensor built around Maxim/Dallas' 1-Wire protocol, and that single design choice is what makes it unusually convenient: dozens of these sensors can share one single GPIO pin, because each chip carries a unique 64-bit ROM code burned in at the factory that your microcontroller uses to address it individually during a bus search. Internally, an onboard delta-sigma ADC converts temperature into a digital word at a resolution you can configure from 9 to 12 bits - trading conversion speed (94ms at 9-bit) for precision (0.0625°C steps at 12-bit). It also supports an unusual ”parasite power” mode, where the sensor draws its operating power directly from the data line itself during conversions, letting you run a sensor on just two wires (data and ground) instead of three, which is especially useful for long cable runs where every extra conductor adds cost and failure points. Because the DS18B20 is factory-calibrated, there is no offset or slope calibration step required in software - you read a temperature and it is already accurate.

-55°C to +125°C
Range
± 0.5°C
Accuracy
9–12 bit
Resolution

Key features

1-Wire Digital Interface

Multiple sensors can share a single microcontroller GPIO pin.

Unique 64-Bit Address

A factory-programmed ROM code lets you identify and read each sensor individually on a shared bus.

Configurable Resolution

Selectable from 9 to 12 bits, trading conversion speed for finer precision.

Parasite Power Mode

Can operate from the data line alone, needing only two wires instead of three.

Waterproof Probe Variants

Available in stainless-steel-sheathed probes for liquid and outdoor sensing.

Factory Calibrated

No calibration curve needed in software - readings are accurate straight out of the box.

Technical specifications

Supply Voltage 3.0V – 5.5V
Temperature Range -55°C to +125°C
Accuracy ± 0.5°C (-10°C to +85°C range)
Resolution 9–12 bit (configurable)
Conversion Time 94ms (9-bit) to 750ms (12-bit)
Interface 1-Wire (single data pin)
Unique ROM Code 64-bit factory-programmed address
Power Mode External or parasite (2-wire)
Package TO-92, or waterproof stainless probe

Pinout

PinFunction
VCC 3.0V – 5.5V power supply (omit in parasite mode)
DATA Single-wire I/O - needs a 4.7k pull-up resistor to VCC
GND Ground

Applications

Multi-point temperature logging with many sensors on one pin Water tank and aquarium temperature monitoring (waterproof probe) 3D printer bed and enclosure temperature monitoring Weather stations Sous-vide cooker temperature control HVAC zone monitoring

What's in the box

1x DS18B20 temperature sensor module

Downloads

Datasheet (PDF) Arduino OneWire + DallasTemperature Library
🔌
Pin Connections
1 Table
Pin Connections Table 1
BoardSensor PinConnection
DS18B20 ModuleVCC/GND/DATA3.3-5V / GND / board data pin
📟
DS18B20 Temperature Sensor Module
7 Examples • C/C++ | Boards: Arduino Uno, Arduino Nano, Arduino Mega, ESP32, ESP8266, STM32, Raspberry Pi Pico
DS18B20 Temperature Sensor Module - Arduino Uno
DS18B20 Temperature Sensor Module - Arduino Nano
DS18B20 Temperature Sensor Module - Arduino Mega
DS18B20 Temperature Sensor Module - ESP32
DS18B20 Temperature Sensor Module - ESP8266
DS18B20 Temperature Sensor Module - STM32
DS18B20 Temperature Sensor Module - Raspberry Pi Pico
📄 File: ds18b20_temperature_sensor_module_-_arduino_uno.inoArduino Uno
679 characters
1//ekostra.com
2//electronics store in egypt
3//+201008896258
4
5// OneWire data pin 2 on Arduino Uno. Needs a 4.7k pull-up resistor between data and VCC.
6#include <OneWire.h>
7#include <DallasTemperature.h>
8
9#define ONE_WIRE_BUS 2
10OneWire oneWire(ONE_WIRE_BUS);
11DallasTemperature sensors(&oneWire);
12
13void setup() {
14 Serial.begin(115200);
15 sensors.begin();
16}
17
18void loop() {
19 sensors.requestTemperatures();
20 float tempC = sensors.getTempCByIndex(0);
21
22 if (tempC == DEVICE_DISCONNECTED_C) {
23 Serial.println("Error: DS18B20 not found - check wiring/pull-up resistor.");
24 } else {
25 Serial.print("Temperature: "); Serial.print(tempC); Serial.println(" C");
26 }
27
28 delay(1000);
29}
📄 File: ds18b20_temperature_sensor_module_-_arduino_nano.inoArduino Nano
680 characters
1//ekostra.com
2//electronics store in egypt
3//+201008896258
4
5// OneWire data pin 2 on Arduino Nano. Needs a 4.7k pull-up resistor between data and VCC.
6#include <OneWire.h>
7#include <DallasTemperature.h>
8
9#define ONE_WIRE_BUS 2
10OneWire oneWire(ONE_WIRE_BUS);
11DallasTemperature sensors(&oneWire);
12
13void setup() {
14 Serial.begin(115200);
15 sensors.begin();
16}
17
18void loop() {
19 sensors.requestTemperatures();
20 float tempC = sensors.getTempCByIndex(0);
21
22 if (tempC == DEVICE_DISCONNECTED_C) {
23 Serial.println("Error: DS18B20 not found - check wiring/pull-up resistor.");
24 } else {
25 Serial.print("Temperature: "); Serial.print(tempC); Serial.println(" C");
26 }
27
28 delay(1000);
29}
📄 File: ds18b20_temperature_sensor_module_-_arduino_mega.inoArduino Mega
680 characters
1//ekostra.com
2//electronics store in egypt
3//+201008896258
4
5// OneWire data pin 2 on Arduino Mega. Needs a 4.7k pull-up resistor between data and VCC.
6#include <OneWire.h>
7#include <DallasTemperature.h>
8
9#define ONE_WIRE_BUS 2
10OneWire oneWire(ONE_WIRE_BUS);
11DallasTemperature sensors(&oneWire);
12
13void setup() {
14 Serial.begin(115200);
15 sensors.begin();
16}
17
18void loop() {
19 sensors.requestTemperatures();
20 float tempC = sensors.getTempCByIndex(0);
21
22 if (tempC == DEVICE_DISCONNECTED_C) {
23 Serial.println("Error: DS18B20 not found - check wiring/pull-up resistor.");
24 } else {
25 Serial.print("Temperature: "); Serial.print(tempC); Serial.println(" C");
26 }
27
28 delay(1000);
29}
📄 File: ds18b20_temperature_sensor_module_-_esp32.inoESP32
673 characters
1//ekostra.com
2//electronics store in egypt
3//+201008896258
4
5// OneWire data pin 4 on ESP32. Needs a 4.7k pull-up resistor between data and VCC.
6#include <OneWire.h>
7#include <DallasTemperature.h>
8
9#define ONE_WIRE_BUS 4
10OneWire oneWire(ONE_WIRE_BUS);
11DallasTemperature sensors(&oneWire);
12
13void setup() {
14 Serial.begin(115200);
15 sensors.begin();
16}
17
18void loop() {
19 sensors.requestTemperatures();
20 float tempC = sensors.getTempCByIndex(0);
21
22 if (tempC == DEVICE_DISCONNECTED_C) {
23 Serial.println("Error: DS18B20 not found - check wiring/pull-up resistor.");
24 } else {
25 Serial.print("Temperature: "); Serial.print(tempC); Serial.println(" C");
26 }
27
28 delay(1000);
29}
📄 File: ds18b20_temperature_sensor_module_-_esp8266.inoESP8266
677 characters
1//ekostra.com
2//electronics store in egypt
3//+201008896258
4
5// OneWire data pin D4 on ESP8266. Needs a 4.7k pull-up resistor between data and VCC.
6#include <OneWire.h>
7#include <DallasTemperature.h>
8
9#define ONE_WIRE_BUS D4
10OneWire oneWire(ONE_WIRE_BUS);
11DallasTemperature sensors(&oneWire);
12
13void setup() {
14 Serial.begin(115200);
15 sensors.begin();
16}
17
18void loop() {
19 sensors.requestTemperatures();
20 float tempC = sensors.getTempCByIndex(0);
21
22 if (tempC == DEVICE_DISCONNECTED_C) {
23 Serial.println("Error: DS18B20 not found - check wiring/pull-up resistor.");
24 } else {
25 Serial.print("Temperature: "); Serial.print(tempC); Serial.println(" C");
26 }
27
28 delay(1000);
29}
📄 File: ds18b20_temperature_sensor_module_-_stm32.inoSTM32
677 characters
1//ekostra.com
2//electronics store in egypt
3//+201008896258
4
5// OneWire data pin PB4 on STM32. Needs a 4.7k pull-up resistor between data and VCC.
6#include <OneWire.h>
7#include <DallasTemperature.h>
8
9#define ONE_WIRE_BUS PB4
10OneWire oneWire(ONE_WIRE_BUS);
11DallasTemperature sensors(&oneWire);
12
13void setup() {
14 Serial.begin(115200);
15 sensors.begin();
16}
17
18void loop() {
19 sensors.requestTemperatures();
20 float tempC = sensors.getTempCByIndex(0);
21
22 if (tempC == DEVICE_DISCONNECTED_C) {
23 Serial.println("Error: DS18B20 not found - check wiring/pull-up resistor.");
24 } else {
25 Serial.print("Temperature: "); Serial.print(tempC); Serial.println(" C");
26 }
27
28 delay(1000);
29}
📄 File: ds18b20_temperature_sensor_module_-_raspberry_pi_pico.inoRaspberry Pi Pico
685 characters
1//ekostra.com
2//electronics store in egypt
3//+201008896258
4
5// OneWire data pin 2 on Raspberry Pi Pico. Needs a 4.7k pull-up resistor between data and VCC.
6#include <OneWire.h>
7#include <DallasTemperature.h>
8
9#define ONE_WIRE_BUS 2
10OneWire oneWire(ONE_WIRE_BUS);
11DallasTemperature sensors(&oneWire);
12
13void setup() {
14 Serial.begin(115200);
15 sensors.begin();
16}
17
18void loop() {
19 sensors.requestTemperatures();
20 float tempC = sensors.getTempCByIndex(0);
21
22 if (tempC == DEVICE_DISCONNECTED_C) {
23 Serial.println("Error: DS18B20 not found - check wiring/pull-up resistor.");
24 } else {
25 Serial.print("Temperature: "); Serial.print(tempC); Serial.println(" C");
26 }
27
28 delay(1000);
29}
OneWire digital temperature sensor, breakout module (has its own pull-up resistor onboard on most versions - add an external one if readings are unstable).
The DATA line needs a 4.7k pull-up resistor to VCC to work reliably - many breakout modules already include this onboard, but bare TO-92 sensors and probe variants usually do not, so check before wiring. When running several sensors on one bus, read each one's unique 64-bit ROM code with a bus-search function first and store those addresses in your code, rather than assuming a fixed read order, since the order sensors respond in is not guaranteed to match wiring order. Temperature conversion is a blocking operation that takes up to 750ms at full 12-bit resolution - for time-sensitive sketches, issue the ”start conversion” command, do other work, and read the result after the appropriate delay rather than blocking the whole loop on it.