Digital thermometer using Arduino and DS18B20 sensor

This post shows how to build a simple thermometer using Arduino UNO board and DS18B20 digital temperature sensor where the temperature value is displayed on 16×2 LCD screen and sent serially to Arduino IDE serial monitor.

The DS18B20 sensor is a 3-pin electronic component (like a simple transistor) from Maxim (formerly Dallas) which uses 1-wire protocol to communicate with master device (microprocessor, microcontroller ….). Each DS18B20 device has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus and controlled with one master device.
The DS18B20 sensor provides 9-bit to 12-bit Celsius temperature measurement resolution (programmable resolution).
The DS18B20 sensor is available in 8-Pin SO (150 mils), 8-Pin μSOP, and 3-Pin TO-92 Packages. DS18B20 pin configurations is shown below:

ds18b20 pin configurations

Hardware Required:

  • Arduino board
  • DS18B20 temperature sensor — datasheet
  • 16×2 LCD screen
  • 4.7k ohm resistor
  • Breadboard
  • Jumper wires

Interfacing Arduino with DS18B20 temperature sensor circuit:
Example circuit schematic diagram is shown below.

Arduino DS18B20 temperature sensor circuit

All grounded terminals are connected together.

The DS18B20 sensor has 3 pins: VCC (+5V), data and GND. The data pin is connected to Arduino pin 10.

The LCD screen is used to display the temperature value read by the DS18B20 sensor.

Arduino with DS18B20 sensor code:
Example Arduino code is below, it doesn’t use any library for the DS18B20 sensor, the only library used is for the LCD display.

Functions used in the code:
bool ds18b20_start(): used to know if the DS18B20 sensor is correctly connected to the circuit, returns 1 if OK and 0 if error.
ds18b20_write_bit(bool value): writes (sends) 1 bit to the DS18B20 sensor, the bit is ‘value’ which may be 1 or 0.
ds18b20_write_byte(byte value): writes 1 byte (8 bits) to the DS18B20 sensor, this function is based on the previous function. This function writes LSB first.
bool ds18b20_read_bit(void): reads 1 bit from the DS18B20 sensor, returns the read value (1 or 0).
byte ds18b20_read_byte(void): reads 1 byte from the DS18B20 sensor, this function is based on the previous function. This function reads LSB first.
bool ds18b20_read(int *raw_temp_value): reads the temperature raw data which is 16-bit long (two 8-bit registers), the data is stored in the variable raw_temp_value, returns 1 if OK and 0 if error.

The value of the temperature in degree Celsius is equal to the raw value divided by 16 (in case of 12-bit resolution). The default resolution of the DS18B20 is 12 bits.

Arduino with DS18B20 video:
The video below shows a simple Proteus simulation of this project.

Arduino IDE serial monitor output:

arduino ds18b20 serial monitor

Arduino + DS18B20 Proteus simulation file download:


DS18B20 datasheet

4 thoughts on “Digital thermometer using Arduino and DS18B20 sensor”

  1. First off all thank You for great tutorials you provided!
    And my question: Could You explain how should I change Your Arduino code to make DS18B20+PAR sensor work properly?
    DS18B20+PAR works in specific Parasite-Power mode. As I can see time intervals in Your code should be changed. But I can’t understand how.

Leave a Comment

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.

Scroll to Top