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.
- 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
• DS18B20 Temperature Sensor x1
• SK40C + PIC16F877A with LCD x1
• PICKIT 2
Using DS18B20 temperature sensor
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.
The connection for my project is as below
The colour of the sensor are following the colour of the diagram
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,
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.
The reading function.
The writing function. The writing function is to send the ROM command to the sensor, for it to know what it need to do.
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
Initial condition for the sensor to sense room temperature
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 🙂