DS18B20 Explained – ElectroSchematics.com

The DS18B20 is a digital temperature sensor from Dallas Semiconductors, which is now part of Maxim (https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf). The sensor provides configurable 9 to 12-bit temperature readings that indicate the temperature of the device. The information is sent to/from the DS18B20 over a 1-Wire interface, so that only one wire (and ground) needs to be connected from an MCU to the sensor. Power for reading, writing, and performing temperature conversions can be derived from the data line itself with no need for an external power source (parasite power mode). Further, since each DS18B20 contains a unique silicon serial number, multiple DS18B20s can exist on the same 1-Wire bus. This allows for placing temperature sensors in many different places.

As you can see, there are multiple types of DS18B20 sensors available. There’re prewired modules that already contain the required components to drive the 1-Wire bus. There are DS18B20 sensors in different packages as well, for example, in waterproof enclosures like the one below.

If you want to measure the temperature of liquids, it’s strongly advised to use the waterproof version, else the sensor might be quickly damaged by corrosion. Note that to use the waterproof version, you need one additional 4.7KΩ resistor as the pull-up resistor for the 1-Wire bus data line.

Quick Test with Arduino

Let’s learn more about this digital temperature sensor by using a waterproof version together with an Arduino. At this point, we are going to use its three pins with a separate line for a power supply. Just forget about the parasite power mode for a while!

The wiring diagram below shows how to set up the quick test hardware. The DS18B20 “stainless steel tube” waterproof digital temperature sensor used here comes with a 90cm long cable for remote temperature sensing over the range of -55 to 85°C.

To be able to use the DS18B20 one-wire digital temperature sensor with the Arduino, we will make use of the “DallasTemperature” library. If you haven’t already done so, you need to install it. You also need to install the “OneWire” library alongside the Dallas Temperature library. The “OneWire” library is required to use the “DallasTemperature” library as it provides the necessitated functions for using the 1-wire bus.

This simplistic Arduino Sketch prints out the temperature values ​​in the Serial Monitor roughly every 6 seconds. Note, there’re so many ways to get the temperature reading from DS18B20 sensors. If you’re using one single sensor, this is one of the easiest ways!




OneWire bus(8); // DQ at pin D8

DallasTemperature sensors(&bus);

void setup() {

Serial.begin(9600); // Initialize Serial Monitor @ 9600 baud rate


void loop() {

// Begin the temperature measurement and wait for it


// Read and show the result

Serial.print(“Temperature (°C): “);


Serial.print(“Temperature (°F): “);





Once the above code is uploaded successfully to your Arduino setup, you should be able to read the current temperature values ​​(°C and °F) displayed in the serial monitor window (see the screenshot below).

This is a casual pic of my quick test setup (DS18B20 + Arduino Uno + Uno ProtoShield). It worked!

How to Detect Counterfeit DS18B20s?

You may get counterfeit DS18B20 sensors (bare chips or waterproof probes) when you buy from some online stores. So if you have a DS18B20 sensor not quite working as expected, you likely bought a clone as some of the counterfeit sensors do not work in parasitic power mode, have a high noise level, a temperature offset outside the advertised ±0.5 °C band, do not contain an E2PROM, have bugs and unspecified failure rates (https://www.cnx-software.com/2020/07/13/fake-ds18b20-temperature-sensors-counterfeit-clones/).

One way to find whether you have such a fake DS18B20 sensor is to check its ROM code. If the ROM code does not follow the pattern 28-xx-xx-xx-xx-00-00-xx then the DS18B20 sensor might be a clone! Related Link https://www.electronicproducts.com/hands-on-review-analyze-signals-with-free-open-source-sigrok-pulseview/

Another quick trick is to call an Arduino Sketch to help you. For example, the “discover_fake_DS18B20.ino” code can perform some safe tests and indicates if the sensor shows deviations from authentic DS18B20 (not designed to work with parasitic power). GitHub Link https://github.com/cpetrich/counterfeit_DS18B20

While on the subject, the parasitic power mode of DS18B20 only differs in the VDD pin connection. In parasitic power mode, VDD is connected to GND. The internal power supply for the DS18B20 draws from both VDD and the DQ pin so it will power itself from either pin but the VDD pin has a power supply sense system on it that detects whether an external VDD is connected. Parasite mode is detected when the VDD The pin does not have voltage on it and the manufacturer recommends it should be grounded to ensure that (refer datasheet for more details).

Below block diagram (snipped from datasheet) shows the parasite-powered circuitry.

Something very quirky: If you bought cheap DS18B20 sensors from Chinese vendors, the parasitic power mode may not work as anticipated!

How to Employ Multiple DS18B20 Sensors?

Now let’s look at how to use multiple temperature sensors on the same bus. Apparently, this calls for separate DS18B20 sensors, but you need only one pull-up resistor for the entire bus.

I won’t go into an in-depth explanation here, because I’ve found a nice writeup to help you go farther. Here it’s https://randomnerdtutorials.com/guide-for-ds18b20-temperature-sensor-with-arduino/

Raspberry Pi Pico & DS18B20

As you’re aware, the Raspberry Pi Pico is a microcontroller board like Arduino (https://www.electroschematics.com/raspberry-pi-pico-first-look-part-1/).

This passage may not help you much, but it’s good to know.

You can now use RPi Pico to make DS18B20 based temperature monitor projects as well. However, for DS18B20 you need to grab OneWire and DS18x20 libraries (https://github.com/micropython/micropython/tree/master/drivers/onewire).

I found this simple tutorial for using DS18B20 with RPi Pico where the author used MicroPython to get readings out and into the Thonny IDE Shell panel


Wrapping Up

If you have a microcontroller and you want to measure temperature, the DS18B20 is one of the most popular digital temperature sensor chips to use. Being a digital sensor, it can avoid many pitfalls of the traditional analog temperature sensors. Notably, the DS18B20 sensor has some extra features for complex solutions with networked sensors. I’ll try to cover some of these interesting features in an upcoming tutorial. See you then!

Source of inspiration (but not limited to) https://devxplained.eu/en

Leave a Comment