DSCF7958.jpg

DS18B20 Temperature Sensor

Introduction

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 microcontroller. The DS18B20 has an operating temperature range of -55°C to +125°C and the accuracy is ±0.5°C over the range of -10°C to +85°C. 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 microcontroller to control multiple 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, process monitoring and control systems.

Key Features

  • Unique 1-Wire Interface Requires Only One Pin for Communication
  • Each Device has a Unique 64-Bit Serial Code Stored in an On-Board ROM
  • Multidrop Capability Simplifies Distributed Temperature-Sensing Applications
  • Requires No External Components
  • Can Be Powered from Data Line; Power Supply Range is 3.0V to 5.5V, for long distance, power is necessary.
  • Measures Temperatures from -55°C to +125°C (-67°F to +257°F)
  • ±0.5°C Accuracy from -10°C to +85°C
  • Thermometer Resolution is User Selectable from 9 to 12 Bits
  • Converts Temperature to 12-Bit Digital Word in 750ms (Max)
  • User-Definable Nonvolatile (NV) Alarm Settings
  • Alarm Search Command Identifies and Addresses Devices Whose Temperature is Outside Programmed • • • Limits (Temperature Alarm Condition)
  • Available in 8-Pin SO (150 mils), 8-Pin µSOP, and 3-Pin TO-92 Packages
  • Software Compatible with the DS1822
  • Applications Include Thermostatic Controls, Industrial Systems, Consumer Products, Thermometers, or Any
  • Thermally Sensitive System

Hardware required:

DS18B20 Temperature Sensor x1

DSCF7961

SK40C + PIC16F877A with LCD x1

DSCF7953

Software required:

MPLAB IDE & HITECH C PRO Installation

PICKIT 2

Related References:

Getting Started with MPLAB IDE

How to Create a project

Getting Started with SK40C

Temperature Sensor Datasheet

Project:

Using DS18B20 temperature sensor

Procedure:

In this project, we are going to measuring the environment temperature using the water proof DS18B20 temperature sensor. This  type of sensor are quite special since it only use the One-Wire-protocol to read he temperature and to write any command into the sensor.

Since it only use 1 wire for signal and give command, so I will use RB0 as the only port to control the temperature sensor and to read it.

Connection

The connection for my project is as below

DSCF7957

DSCF7956

connection

The colour of the sensor are following the colour of the diagram

Sensor Colour
Red Vin
Green Gnd
Yellow Data

Programming and Result

Let’s take a look at the sample code before we proceed to explanation.

This is the main body of the sample coding. In this part we are setting up the sensor and at the second part, we are accepting the reading from the sensor and convert it further publish the value to the LCD screen,

codemain

We need to 1st reset the sensor. This is to check the availability of the sensor present in the communication line. If the sensor is present we will proceed to the read temperature step.

reset

The reading function.

read

The writing function. The writing function is to send the ROM command to the sensor, for it to know what it need to do.

write

Explanation

Maybe you are curious to know why one wire can do so many thing including read (receive) and write(transmit). Actually this sensor utilize the one wire protocol. Referring to the figure below, try to understand how the read and write works.

It is hard for me to explain here since it will consume few pages of words 🙂 I would strongly suggest you to read it at Wikipedia pages HERE

signal

 

RESULT

DSCF7958

Initial condition for the sensor to sense room temperature

DSCF7959DSCF7960

HOT WATER AROUND  ~68 degree Celsius….. Yes, you can submerge it in to water or liquid 🙂 Quite fun!

This sensor is perfect due to water proof feature and simple interface. Besides, you can also do multiple sensor in a network as it has unique address.

PROBLEM MAY OCCUR

• Please do take care of the voltage polarity, supplying wrong polarity of power will damage the sensor permanently.

Have fun and if you have any inquiry, welcome to post it in our technical forum as we seldom check the comment section in the tutorial 🙂

Sample Coding

Buy

, ,

Related Post

20160330_085520-e1459299689529-400x323

Control and Monitor via SMS Part 2

ciku-7-400x347

Simple steps to control Stepper Motor using 2Amp Motor Driver Shield and CIKU

18f4550arrowclock

PIC16F VS PIC18F:Analysis of PIC Mid-Range 8 bit family and Advanced 8-bits Family

DSC00191.000

SK40C vs CT-UNO

10 thoughts on “DS18B20 Temperature Sensor

  1. Not really sure. What is the expected temperature for the oil when it is cooked? Because the maximum operating temperature for this sensor is +125 degree Celsius. Besides, we do not know will the shrinking material that wrap the sensor react with the cooking oil.

  2. When I try to “rebuild” the code in MPLAB, the build failed with message :
    “Error [712] H:\Arduino\Projects-PIC\DS18B20\Example Code\lcd.c; 295. can’t generate code for this expression”

    The same lcd.c file that was used in another tutorial : “GSM modem TC35 with PIC16F877A” is able to build without any problems.

    What could be the problem ?

    Thank you.

  3. Yo,
    Just bought this months ago and I tried to use the file to run on Arduino but failed. Can this be run on it? Thanks!

  4. Hello
    I would like to ask about the lane “i = (float)i * 6.25 ; //calcuation from the table provided ” Where is that cable and why is 6.25 ?
    Thank you for your time.

  5. Can i ask you ,how to get the reading with using a programmable logic controlled (PLC),and how to convert the output voltage from the sensor to the degree of calcius

  6. Hello. I need to rename my sensors rather than having just a serial number. Can you point me in the right direction?

Leave a Reply

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