logo smart home family kruse

Kruse Smart Home

Easy living in our smart home & Garden

The DS18B20 digital temperature sensor

DS18B20 sensor

24 May 2021

Jan-Willem

1. Introduction

The digital temperature sensor (previously named Dallas Semiconductor). As the operating voltage of the sensor is 3.0 to 5.5 Volt it can easily be used with several devices, including the Arduino (which operates at 5 Volt).

Main features of the temperature sensor:

  • requires only one digital I/O pin of the Arduino for communication as the sensor communicates using the Dallas Semiconductor protocol. This protocol works in a similar way as I2C, but with lower data rates and a longer range;
  • each sensor has a unique 64-bit serial code, which allows multiple sensors to function on the same 1-Wire bus. Also you can readout a specific sensor;
  • the resolution of the sensor can be set to temperature increments of 0.5 °C (default), 0.25 °C, 0.125 °C, and 0.0635 °C.

DS18B20 documentation from Maxim Integrated :

More articles and info from Maxim Integrated

2. Available types of DS18B20 digital temperature sensor

The sensor usually comes in three form factors. The most common types are shown in the images below. The manufactured sensor comes in the form of a 3-pin TO-92 package, which looks just like a transistor. The sensor is available as a waterproof sensor (usually jacketed in PVC so it is recommended to keep it under 100 °C), on shields etc.

Be aware there are , often cheaply offered from China.

Useful Maxim Integrated knowledge base articles :

3. Sensor principle

The DS18B20 is a silicon band gap temperature sensor. The sensor is based on the principle that the forward voltage drop of a silicon diode (wikipedia – diode) is temperature dependent. By measuring the forward voltage drop across the diode, the temperature of the silicon is calculated (Maxim Integrated Knowledge Base article 000096043).

The sensor uses two matching transistors with known voltage behaviors across temperature. The difference of those two voltages is taken and converted into a digital value as shown in the figure below (Maxim Integrated Knowledge Base 000096194).

4. Pinout

Make sure the sensor is wired correctly, else the sensor will be blown up!

5. Sensor accuracy etc.

The next sections cover the following sensor aspects:

  • Range and accuracy;
  • Resolution;
  • Drift in time;
  • Calibration;
  • Response time.

5.1 Sensor range and accuracy

The DS18B20 temperature sensor has a measuring range from -55 °C to + 125 °C, but the accuracy differs depending on the range in which the sensor operates (Maxim Integrated knowledge base article 000094893):

  • -55 °C to + 125 °C with ±2°C accuracy
  • -30 °C to +100 °C with ±1 °C accuracy
  • -10°C to +85°C with ±0.5°C accuracy

The maximum temperature difference between two different devices in the same environment is respectively 4℃, 2℃ and 1℃. For the latter one the manufacturer indicated that based on their lab tests the temperature difference between different devices is generally within 0.5℃. (Maxim Integrated knowledge base article 000103077)

The sensor does not sense temperature directly through the package, but primarily through the GND pin. Ensuring a good thermal connection between the GND pin of the sensor and the heat source you wish to measure will provide the best results (Maxim Integrated knowledge base article 000094882).

Useful Maxim Integrated knowledge base articles :

5.2 Sensor resolution

The sensor resolution can be adjusted, but this has impact on the acquisition speed:

No. of bits Maximum
conversion
time (ms)
Resolution
(°C)
Bits to
Ignore
9 93.75 0.500 2,1,0
10 187.5 0.250 1,0
11 375 0.125 0
12
(default)
750 0.0625

Be aware that resolution is not the same as accuracy! An increase in the sensor resolution does not increase the accuracy, but it allows you to monitor relative changes more easily.

Note:

  • Remember that the lower bits of the device output hex data must be ignored when using lower resolutions because the values of these bits are undefined so make sure they are zero when you use the output data.
  • There is no limit to the number of data acquisitions/temperature conversions the DS18B20 can execute. The accuracy of those conversions is guaranteed per the datasheet for the life of the product.

5.3 Sensor drift

In time the sensor readings drift hardly and are within the sensor accuracy of ±0.5°C. A stress test done by the manufacturer at 125°C shows a drift of max 0.2°C after 1000 hours  (±42 days).

Useful Maxim Integrated knowledge base articles:

5.4 Calibration

The calibration of the DS18B20 is guaranteed for life; there is no need for recalibration (Maxim Integrated Knowledge Base 000094864). Also, the sensor cannot be calibrated by the user.

5.5 Sensor response time

The response time of the DS18B20 conversion is not impacted by the distance of the sensor from the bus master. The DQ line (ie,1-Wire bus) is only transmitting the conversion result that occurred on-board the sensor IC.

It is more likely that there is some difference in the insulation/waterproofing of that particular sensor that is allowing thermal conductivity to the DS18B20 through either the package or the GND pin. Keep in mind that the GND pin of the TO-92 package is directly connected to the die of the sensor, so if there is close or direct contact of the GND pin to the temperature being measured, then you can expect much better response time.

Sensing through the package of the DS18B20 is of course possible, but thermal conduction is much much better through the metal connection of the GND pin to the die inside the package (Maxim Integrated knowledge Base article 000096079).

6. Powering the sensor

There are two ways to power a DS18B20:

  • Parasitic power from the data line of the microcontroller
  • External 3-5V power supply
6.1 Parasitic power mode

In parasitic power mode, no separate power supply line is used. The sensor is powered via the data line as show in the figure below.

In parasitic power mode, the power is derived from the single 4.7kΩ pull-up resistor on the One-Wire bus and fed into the DQ line while you keep the VDD pin at Ground – this indicates that the sensor should use parasitic power. Parasitic power mode has drawbacks and hence the general recommendation is to use external power supply mode, which means that power must be individually supplied to the Vcc pin of the sensor, requiring a 3 core wire instead of 2 wire or using a separate power supply at the DS18B20 sensor location.

Note:

  • Powering the DS18B20 using GND and VDD without a pullup resistor does not work. You must have a pullup resistor from the chip control pin to the Vcc pin of about 4.7kΩ. Without the pullup resistor, the Arduino library can not detect the sensor. Only a single pull-up will be needed and it can be placed close to the microcontroller pin.
6.2 External (3-5V) power mode

An external power method ensures correct operation of the DS18B20 sensor, but requires a local source of power.

Useful Maxim Integrated knowledge base articles:

8. Connecting the sensors to a micro controller (i.e. Arduino)

Connecting a few sensors over short distances (5-10 metres) is not a problem, but more sensors over longer distances requires a good setup.

Originally the 1 wire protocol was intended for PCB communication only but its use grew into networked topologies with 100’s of metres of cable. In fact using special driver considerations, 500m is achievable.

8.1 Network topologies

There are many different topologies for DS18B20 layout including linear, linear with stubs, star network and switched linear (see the diagrams below). The Integrated Maxim tutorial “Guidelines for reliable long line 1-wire networks (AN148)” has a lot of detailed information on types of networks that can be used and maximizing the performance.

Note:

  • Testing has shown that unswitched star-type network topologies (i.e., those with several branches diverging at the master) are the most difficult to make reliable. The junction of various branches presents highly mismatched impedances; reflections from the end of one branch can travel distances equal to nearly the weight of the network (rather than the radius) and cause data errors. For this reason, the unswitched star topology is not recommended, and no guarantees can be made about its performance.
  • When a stub is connected to a 1-Wire bus, there is an impedance mismatch at the branch point. Reflections from the end of the stub return to the main trunk, delayed only by the time it takes for the signal to travel the length of the stub. These reflections can then cause problems for other slaves on the network. A resistor in series with the stub will reduce the severity of the mismatch and the amplitude of the reflected energy. That resistor mitigates adverse effects from stub-generated reflections on the main trunk.

The most successful implementation of this concept uses 150Ω resistors at each point where a stub is connected to the main trunk. This value reduces the mismatch at the connection point by about 20%, and attenuates the resulting stub reflections by about 40%. However, the added resistance also degrades noise immunity by about 80%, so caution must be observed. Tests have also shown good performance using 100Ω resistor values, which do not degrade noise immunity quite as much.

8.2 Distance and maximum number of sensors

On the web it is recommended not to use lines longer than 30 metres, but this seems to be based on example data from a Maxim Integrated tutorial example using this distance.

More info can be found in Maxim Integrated knowledge base articles (unfortunately no clear statements):

8.3 Cable type

The recommended wire is CAT5 and you arrange them as a bus or a daisy chained chained network – helping to avoid transmission line reflection problems – as opposed to a star network.

Useful Maxim Integrated knowledge base articles:

9. Temperature Sensor Alarm State

You can program into the sensor upper and lower temperatures (into non-volatile memory – internal EEPROM within the DS18B20 itself) so that if the temperature goes outside the upper or lower limits an alarm condition is created. This means you don’t have to continuously poll each (of possibly hundreds of devices) to check for an out of range temperature condition.

The master controller can issue an alarm search command at regular intervals- any sensor connected to the 1-wire bus that has an alarm condition will respond. The controller can then find out which device has the alarm condition flag set.

Article by <a href="https://smarthome.familykruse.eu/author/iamjwk/" target="_self">Jan-Willem</a>

Article by Jan-Willem

Position

Writen by the website owner

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *