Electronics

Temperature Sensor DS18B20

AED 7.50

1

Description

The digital temperature sensor called the DS18B20 is produced by Maxim Integrated (formerly Dallas Semiconductor). One of the most widely used temperature sensors available, it offers reasonable accuracy (0.5 °C) over a wide temperature range (-55 °C to + 125 °C). The sensor can be used with both the Arduino (which runs at 5 V) and electronics like the ESP32 and Raspberry Pi, which have 3.3 V GPIO pins, because its operating voltage ranges from 3.0 to 5.5 V.

Package Includes:

  • 1x DS18B20 Temperature Sensor IC

Features:

  • Communicates over one-wire bus communication
  • Power supply range: 3.0V to 5.5V
  • Operating temperature range: -55ºC to +125ºC
  • Accuracy +/-0.5 ºC (between the range -10ºC to 85ºC)
  • The Dallas Semiconductor 1-Wire® protocol is used by the sensor for communication
  • 12-bit resolution max.
  •  

Description:

The digital temperature sensor called the DS18B20 is produced by Maxim Integrated (formerly Dallas Semiconductor). One of the most widely used temperature sensors available, it offers reasonable accuracy (0.5 °C) over a wide temperature range (-55 °C to + 125 °C). The sensor can be used with both the Arduino (which runs at 5 V) and electronics like the ESP32 and Raspberry Pi, which have 3.3 V GPIO pins, because its operating voltage ranges from 3.0 to 5.5 V.One of this sensor's biggest benefits is that it can communicate with the Arduino using just one digital pin. The Dallas Semiconductor 1-Wire® protocol is used by the sensor for communication. Similar to I2C in operation, but with a greater operating range and slower data rates. Another benefit is that multiple DS18B20 sensors can operate on a single 1-Wire bus because each DS18B20 sensor has a distinct 64-bit serial code. Consequently, you can use a single Arduino pin to read data from multiple sensors that are connected together. Programmatically, the sensor's resolution can be changed to 9, 10, 11, or 12 bits. This translates into temperature increments of 0, 0, 25, 0, 125, and 0, 0635 degrees Celsius, respectively. 12-bit resolution is the initial default setting.

Principle of Work:

The sensor operates using the 1-Wire communication protocol. The other two pins are used for power, and only the data pin needs to be connected to the microcontroller via a pull-up resistor. The pull-up resistor is used to maintain the line's high state when the bus is not in use. A 2-byte register inside the sensor will hold the temperature reading that was obtained by the sensor. By sending a series of data, this data can be read using the 1-wire method. To read the values, two different types of commands must be sent: a ROM command and a function command. The datasheet below provides the address value and sequence for each ROM memory. To learn how to communicate with the sensor, you must read it. You need not worry about any of these if you intend to interface it with Arduino. To access the data, use the built-in functions and the available library.

 

Pinout of the Board:

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


Applications:

  1. Measuring temperature in hard environments
  2. Liquid temperature measurement
  3. Applications where the temperature has to be measured at multiple points

Circuit:

Connect digital pin 2 to the middle pin (DQ. To keep the 1-Wire bus' idle state high, you must also add a 4.7 k pull-up resistor between the DQ pin and 5 V.

(When the flat side of the sensor—the side with the text printed on it—is facing you, pin 1 (GND) is the leftmost pin.)

Library: 

You can download the library by clicking here

Once the the.ZIP file is downloaded go to Arduino IDE -> Sketch -> Include Library -> Add.ZIP Library and look for the ZIP file to be installed.

Code:

This code is going to print the Temperature sensor on the Serial Monitor.

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

// Define to which pin of the Arduino the 1-Wire bus is connected:
#define ONE_WIRE_BUS 2

// Create a new instance of the oneWire class to communicate with any OneWire device:
OneWire oneWire(ONE_WIRE_BUS);

// Pass the oneWire reference to DallasTemperature library:
DallasTemperature sensors(&oneWire);

void setup() {
  // Begin serial communication at a baud rate of 9600:
  Serial.begin(9600);
  // Start up the library:
  sensors.begin();
}

void loop() {
  // Send the command for all devices on the bus to perform a temperature conversion:
  sensors.requestTemperatures();

  // Fetch the temperature in degrees Celsius for device index:
  float tempC = sensors.getTempCByIndex(0); // the index 0 refers to the first device
  // Fetch the temperature in degrees Fahrenheit for device index:
  float tempF = sensors.getTempFByIndex(0);

  // Print the temperature in Celsius in the Serial Monitor:
  Serial.print("Temperature: ");
  Serial.print(tempC);
  Serial.print(" \xC2\xB0"); // shows degree symbol
  Serial.print("C  |  ");

  // Print the temperature in Fahrenheit
  Serial.print(tempF);
  Serial.print(" \xC2\xB0"); // shows degree symbol
  Serial.println("F");

  // Wait 1 second:
  delay(1000);
}

 

Technical Details:

  • Programmable Digital Temperature Sensor
  • Communicates using 1-Wire method
  • Operating voltage: 3V to 5V
  • Temperature Range: -55°C to +125°C
  • Accuracy: ±0.5°C
  • Output Resolution: 9-bit to 12-bit (programmable)
  • Unique 64-bit address enables multiplexing
  • Conversion time: 750ms at 12-bit  

Resources:

Library

Tutorial

Comparisons:

The Dallas DS18B20 has a temperature range of -55 – 125° C / ± 0.5° C while in comparison to DHT11 which has a range of 0 – 50° C / ± 2° C  the DS18B20  has a an extraordinary speed compared to DHT11 but still, the DHT11 can sense the temperature and humidity.

 

DHT11 Specifications DS18B20
Humidity and temperature Measurement Temperature
0 – 50° C / ± 2° C Temperature Range -55 – 125° C / ± 0.5° C
20 – 80 / ± 5 % Humidity Range Nil
1 wire Communication Protocol  1 wire
1 Hz one reading every second Sampling Rate  
3 – 5 V Operating Voltage 3 – 5 V
2.5 mA Minimum current 10 mA