Interfacing DS18B20 Temperature Sensor with Arduino

Interfacing DS18B20 Temperature Sensor with Arduino: This article is all about DS18B20 and its interfacing with arduino. DS18B20 comes in two variants: Normal and waterproof version. Normal version is available TO-92 and uSOP. Let’s start with introduction.

Description of DS18B20

It is digital programmable temperature sensor based on one wire communication i.e. it requires only data line and common GND. Power supply is optional because this sensor can drain require power supply from data line and this mode called parasite mode.

DS18B20 can provide different temperature resolution is 0.50C, 0.250C, 0.1250C and 0.06250C corresponding to 9-bit, 10-bit, 11-bit and 12-bit respectively. So, accuracy depends upon bit we are using.

pin diagram of DS18B20Figure: pin diagram of DS18B20

As DS18B20 work on wire protocol so a small pull up resistor is required because it linked to bus through an open-drain port or 3-state. You can also use multiple sensors over single line because of its 64-bit serial code. So, virtually you can connect unlimited number of DS18B20 sensor over a single digital pin of arduino.

DS18B20 also have in built alarm signaling i.e. if alarm condition exists, alarm flag is set and this value is update after every measurement. Any controller (master device, let’s say arduino nano) can check the flag using proper command.

Time for temperature reading and conversion:

The time require for temperature measurement and conversion of this sensor depends upon resolution we are using. As resolution increases, measurement and conversion time also increases as shown in table below.

Register to select resolution Resolution Bits Max. Conversion Time
R1 R0
0 0 9 93.75 mS
0 1 10 187.5 mS
1 0 11 375 mS
1 1 12 750 mS

Summery of Specification and features

  • Work on one wire communication protocol
  • Two mode of power supply
  1. External power supply mode: Power supply voltage 3.0V to 5.5V.
  2. Parasite mode: No external power supply needed
  • Measuring Temperature range: -550C to + 1250C
  • Accuracy +/-0.50C
  • Resolution: 0.06250C to 0.50

Component required for Interfacing DS18B20 Temperature Sensor with Arduino

1 x Arduino Nano

1 x DS18B20 temperature sensor

1 x I2C 16x2LCD

1 x 4.7K Resistor

Jumper wire

Breadboard

Circuit description of Interfacing DS18B20 Temperature Sensor with Arduino

The circuit of Interfacing DS18B20 Temperature Sensor with Arduino is shown in figure below. An I2C LCD is connected to arduino I2C pin which display the temperature. According to 1-wire bus protocol, a 5k resistor is required which make idle state for 1-wire bus is high. So, a 4.7k (nearest resistor) is connected to DQ pin to power supply pin.

There are two way to power DS13B20

Using External power supply: VDD pin is connected to 5V of arduino, where ground pin is connected to GND pin of arduino. Data line DQ is connected to D5 of arduino with a pull up as shown in circuit diagram.

Interfacing DS18B20 Temperature Sensor with Arduino with external power

Without using external power supply (parasite mode): All the connection is same except VDD pin of sensor is sorted to ground as shown in figure below.

Interfacing DS18B20 Temperature Sensor with Arduino with external power without external power

author prototype of ds18b20Figure: Author Prototype of Interfacing DS18B20 Sensor with Arduino

Software Code:

Before going to software section, you have to download two different libraries.

For downloading library go to Sketch>>Include Library>>Manage Libraries and then search for “onewire” and install OneWire by Jim Studt.

one wire libFigure: Installing OneWire Library

Now again search for Dallas and install DallasTemperature by Miles Burton

download dallas sensor libraryFigure: Installing Dallas Temperature Sensor Library

After installing these two libraries upload the sketch to your arduino board. The sketch is based on Dallas temperature library example.

Interfacing Multiple DS18B20 to Arduino

Interfacing of multiple DS18B20 is simple as shown in circuit diagram below. All sensor are connected in parallel to each other i.e. VCC of all sensors are sorted together, GND of all sensors are sorted together and Data pin of all sensors are sorted together as show in circuit below.

interfacing multiple ds18b20 to arduino

Software Code:

author prototype of interfacing multiple DS18B20 sensor with arduino
Figure: Author Prototype of Interfacing Multiple DS18B20 Sensor with Arduino

Leave a Comment