Temperature Sensor-DS18B20

The DS18B20 digital thermometer provides 9-bit to 12-bit Celsius temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor.In addition, the DS18B20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply. Each DS18B20 has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus. Thus, it is simple to use one microprocessor to control many DS18B20s distributed over a large area. Applications that can benefit from this feature include HVAC environmental controls, temperature monitoring systems inside buildings, equipment, or machinery, and process monitoring and control systems.
Pin Details:

Multiple sensors can be connected to the same data bus. Each sensor identifies itself by a unique serial number. The sensor can operate in normal or parasite mode. In normal mode, a 3-wire connection is needed. In parasite mode the sensor derives its power from the data line. Only two wires, data and ground, are required.
Normal Mode
In normal mode, each sensor is connected between a power line (Vdd pin 3) and ground (GND pin 1), and the data output (DQ pin 2) connects to a third, data, line. The data output is a 3-state or open-drain port (DQ pin 2) and requires a 4k7 pull-up resistor. The data line is connected to an available Arduino digital input or Arduino digital pin 4 in the case of the emonTx.
Normal mode is recommended when many devices and/or long cable runs are involved.
Parasite Mode
Parasite power mode requires both DS18B20 GND (pin 1) and Vdd (pin 3) to be connected to ground. The DQ pin (pin 2 – the middle pin) is the data/parasite power line. The data line requires a pull-up resistor of 4k7 connected to + 5 V. The data line is connected to an available Arduino digital input or Arduino digital pin 4 in the case of the emonTx.
Parasite mode should be used only with a small number of devices, over relatively short distances.
The DS18B20 temperature sensor is a 1-wire digital temperature sensor. This means that you can read the temperature with a very simple circuit setup. It communicates on common bus, which means that you can connect several devices and read their values using just one digital pin of the Arduino
Benefits and Features
1. Unique 1-Wire® Interface Requires Only One Port Pin for Communication
2. Reduce Component Count with Integrated
3. Temperature Sensor and EEPROM
4. Measures Temperatures from -55°C to +125°C (-67°F to +257°F) ±0.5°C Accuracy from -10°C to +85°C
5. Programmable Resolution from 9 Bits to 12 Bits
6. No External Components Required
7. Parasitic Power Mode Requires Only 2 Pins for Operation (DQ and GND)
8. Simplifies Distributed Temperature-Sensing Applications with Multidrop Capability
9. Each Device Has a Unique 64-Bit Serial Code Stored in On-Board ROM
10. Flexible User-Definable Nonvolatile (NV) Alarm Settings with Alarm Search Command Identifies Devices with Temperatures Outside Programmed Limits
1. Thermostatic Controls
2. Industrial Systems
3. Consumer Products
4. Thermometers
5. Thermally Sensitive Systems Schematic
6. The sensor can operate in two different modes:
Normal mode: 3-wire connection is needed. Here’s the schematic you need to follow:

In this example, you’ll read the temperature using the DS18B20 sensor and the Arduino. The readings will be displayed on the Arduino Serial Monitor.  You’ll need to install the OneWire Library and DallasTemperature Library.
Installing the DallasTemperature Library
1. Download the Dallas Temperature library.You should have a .zip folder in your Downloads
2. Unzip the .zip folder and you should get Arduino-Temperature-Control-Library- master folder
3. Rename your folder from Arduino-Temperature-Control-Library-master to DallasTemperature
4. Move the DallasTemperature folder to your Arduino IDE installation libraries folder
5. Finally, re-open your Arduino IDE
After installing the needed libraries, upload the following code to your Arduino board.
Based on the Dallas Temperature Library example
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is connected to the Arduino digital pin 2
#define ONE_WIRE_BUS 2
// 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 sensors.begin();
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: “);
Serial.print(sensors.getTempCByIndex(0)); Serial.print(” – Fahrenheit temperature: “); Serial.println(sensors.getTempFByIndex(0));
Download OneWire Library: Here. Download DallsTemperarure_Library: Here

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.