Digital Temperature Sensor DS18B20 With Arduino

Introduction: Digital Temperature Sensor DS18B20 With Arduino

Hi guys in this instructables we will learn how to use DS18B20 temperature sensor with arduino.
So in this instructables we will do required setup & Libraries for this temperature sensor.

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: Things You Need

For this instructables we will need following things :

Arduino uno

Jumper wires



Resistor 4.7k ohm

Step 2: About DS18B20

The DS18B20 temperature sensor is 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.
We will take a look into its working modes in further steps.

Step 3: Connections

The sensor can operate in two modes:

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

Parasite mode: You only need data and GND. The sensor derives its power from the data line. In this case, here’s the schematic you need to follow:

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: 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.

Step 5: Code

Please copy the following code and upload it to the arduino Board :

#include "OneWire.h"
#include "DallasTemperature.h"

// 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

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(" - Fahrenheit temperature: ");

Step 6: Reading Temperature

After uploading the code & connecting everything together plug the arduino cable to the PC and open the serial monitor in arduino ide and you'll able to read the temperature data in your serial monitor from this sensor.

Be the First to Share


    • Raspberry Pi Contest 2020

      Raspberry Pi Contest 2020
    • Wearables Contest

      Wearables Contest
    • Fix It Contest

      Fix It Contest