DS18B20 Temperature Sensor With Arduino

About: Share Knowledge about Arduino, ESP,GSM,Basic Electronics, DIY PROJECTS, Raspberry pi

This post shows how to use the DS18B20 temperature sensor with the Arduino board. You’ll learn how to wire the sensor, install the required libraries and get temperature from one or multiple DS18B20 sensors.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Introducing DS18B20 Temperature Sensor

TheDS18B20 temperature sensoris a one-wire digital temperature sensor. This means that it just requires one data line (and GND) to communicate with the Arduino.

It can be powered by an external power supply or it can derive power from the data line (called “parasite mode”), which eliminates the need for an external power supply.

The following table shows how you should wire the DS18B20 sensor to your Arduino board:

DS18B20 Arduino

  • DQ Any digital pin (with 4.7k Ohm pull-up resistor)
  • VDD 5V (normal mode) or GND (parasite mode)

Each DS18B20 temperature sensor has a unique 64-bit serial code. This allows you to wire multiple sensors to the same data wire. So, you can get temperature from multiple sensors using just one Arduino digital pin.

Step 2: Parts Required

To show you how the sensor works, we’ll build a simple example that reads the temperature from the DS18B20 sensor with the Arduino and displays the values on the Arduino Serial Monitor.

Here’s a list of parts you need to complete this tutorial

  • Arduino UNO
  • DS18B20 temperature sensor
  • 4.7k Ohm resistor
  • Breadboard
  • Jumper wires

You can use the preceding links or go directly to ut source to find all the parts for your projects at the best price!

Step 3: Schematic

The sensor can operate in two modes:

Normal mode: 3-wire connection is needed. You provide power to the VDD pin. Above is the schematic you need to follow:

Parasite mode: You only need data and GND. The sensor derives its power from the data line.

You can read the temperature of more than one sensor at the same time using just one Arduino digital pin. For that, you just need to wire together all the sensors data pins to an Arduino digital pin.

Step 4: Upload Code – Single DS18B20

To interface with the DS18B20 temperature sensor, you need to install theOne Wire library by Paul Stoffregenand the Dallas Temperature library. Follow the next steps to install those libraries.

Step 5: Installing Libraries

1. Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries. The Library Manager should open.

2. Type “OneWire” in the search box and install the OneWire library by Paul Stoffregen.

3. Then, search for “Dallas” and install the Dallas Temperature library by Miles Burton.

After installing the needed libraries, upload the following code to your Arduino board. This sketch is based on an example from the Dallas Temperature library.



// Data wire is conntec to the Arduino digital pin 4

#define ONE_WIRE_BUS 4

// Setup a oneWire instance to communicate with any OneWire devices OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature sensor

DallasTemperature sensors(&oneWire);

void setup(void) {

// Start serial communication for debugging purposes


// Start up the library



void loop(void){

// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus sensors.requestTemperatures();

Serial.print("Celsius temperature: ");

// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire Serial.print(sensors.getTempCByIndex(0));

Serial.print(" - Fahrenheit temperature: ");




There are many different ways to get the temperature from DS18B20 temperature sensors. If you’re using just one single sensor, this is one of the easiest and simplest ways.

Step 6: Demonstration

After uploading the code, open the Arduino IDE Serial Monitor at a 9600 baud rate. You should get the temperature displayed in both Celsius and Fahrenheit:

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest