Using DS18B20 Digital Thermometer With Arduino

Connecting an Arduino UNO to a Dallas DS18B20 Temperature Sensor

DS18B20 Sesnor Overview

The DS18B20 digital thermometer is a high-resolution (9-bit to 12-bit) temperature sensor with a built-in alarm and user-programmable alarm level. The sensor uses a 1-Wire bus to communicate to a microcontroller that requires data, power, and ground. Each sensor features a unique ID, allowing them to be configured and identified on the same bus.

Sensor temperature range: -67 °F to +257 °F (-55 °C to + 125 °C), comes packaged in a 3-pin TO-92 case and operates from 3 to 5.5 VDC.

DALLAS DS18B20 Temperature Sensor Pinout

The DS18B20 digital thermometer is a high-resolution (9-bit to 12-bit) temperature sensor with a built-in alarm and user-programmable alarm level. The sensor uses a 1-Wire bus to communicate to a microcontroller that requires data, power, and ground. Each sensor features a unique ID, allowing them to be configured and identified on the same bus.

Sensor temperature range: -67 °F to +257 °F (-55 °C to + 125 °C), comes packaged in a 3-pin TO-92 case and operates from 3 to 5.5 VDC.

DS18B20 Options

Through our site www.pcboard.ca, we offer individual DS18B20 sensors along with pre-wired 1m and 2m cable assemblies.

DS18B20 in TO92 Case and Prewired Cable

DS18B20 Connection To An Arduino UNO

Wiring for the DS18B20 to an Arduino UNO is straightforward. Power (Red wire) and Ground (Black wire) are supplied from the UNO to pins one and three of the sensor. The signal lead is attached to Digital Port 2 of the UNO from pin two of the sensor.

Additionally, a 4.7K Ω resistor (available separately) is connected across pin two (DQ) and pin three (Vdd) of the sensor. This resistor is necessary to pull up the DQ lead while reading the sensor. Failure to include the resistor can result in erroneous readings or temperature readings of -127. The resistor should be as close as possible to the sensor when used with longer-length sensor cables.

Arduino UNO Connection To DALLAS DS18B20 Temperature Sensor

Arduino IDE Setup

The Arduino IDE requires libraries to read and process the temperature data from the DS18B20 sensor. The libraries are freely available directly through the IDE Library Manager.

From the Arduino IDE, select the Sketch option, Include Library option, and use the Manage Libraries selection. From the Library Manager, enter DallasTemperature and Install it.

During the install, you may also be prompted to install the OneWire library; you will want to select Install All, and this will set up all the necessary libraries.

Simple Arudino Program For Reading DS18B20 Temperature

Now upload the sketch below to your Arduino UNO, and temperature readings will be read from the DS18B20. The results will display to the Serial Monitor. The temperature values are displayed in both degrees Farenheight and Celcius.

The sketch can be easily modified for additional sensors or send data to external displays such as LCD 2×16 and 4×20 displays or small OLED displays.

Have other questions on other Arduino topics? See our collection of Arduino articles.