Top Banner
A Digital temperature meter using an LM35 temperature sensor Introduction A digital thermometer is a good choice of project for beginners who just stepped in to the world of microcontrollers because it provides an opportunity to learn using sensors to measure the real world signals that are analog in nature. This article describes a similar project based on a PIC166!! microcontroller and an "#$% te mperature sensor. "#$% is an analog sensor that converts the surrounding temperature to a proportional analog voltage. The output from the sensor is connected to one of the A&C channel inputs of the PIC166!! microcontroller to derive the e'uivalent temperature value in digital format. The computed temperature is displayed in a 16() character "C&* in both +C and + scales. Theory  The "#$% series of temperatur e sensors are produced by ,ational -emiconductor Corporation and are rated to operate over a %% +C to 1%/+C temperature range. These sensors do not re'uire any e0ternal calibration and the output voltage is proportional to the temperatur e. The scale factor for temperature to voltage conversion is 1/ m per +C. The "#$% series sensors come in di2erent pac3ages. The one I used is in a hermatic T456 transistor pac3age wher e the metal case is connected to the negative pin 7nd8.  The meas urement of negative temperatur es below / +C8 r e'uires a negative voltage source. 9owever* this project does not use any negative voltage source* and therefore will demonstrate the use of sensor for measuring temperatures above /+C up to 1//+C8.  The output v oltage fr om the sensor is converted to a 1/bit digital number using the internal A&C of the PIC166!!. -ince the voltage to be measured by the A&C ranges from / to 1./ that corresponds to ma0imum temperature range* 1//
10

A Digital Temperature Meter Using an LM35 Temperature Sensor

Apr 13, 2018

Download

Documents

sunpnair
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: A Digital Temperature Meter Using an LM35 Temperature Sensor

7/24/2019 A Digital Temperature Meter Using an LM35 Temperature Sensor

http://slidepdf.com/reader/full/a-digital-temperature-meter-using-an-lm35-temperature-sensor 1/10

A Digital temperature meter using an LM35 temperature

sensor

Introduction

A digital thermometer is a good choice of project for beginners who just steppedin to the world of microcontrollers because it provides an opportunity to learn

using sensors to measure the real world signals that are analog in nature. This

article describes a similar project based on a PIC166!! microcontroller and an

"#$% temperature sensor. "#$% is an analog sensor that converts the

surrounding temperature to a proportional analog voltage. The output from the

sensor is connected to one of the A&C channel inputs of the PIC166!!

microcontroller to derive the e'uivalent temperature value in digital format. The

computed temperature is displayed in a 16() character "C&* in both +C and +

scales.

Theory

 The "#$% series of temperature sensors are produced by ,ational

-emiconductor Corporation and are rated to operate over a %% +C to 1%/+C

temperature range. These sensors do not re'uire any e0ternal calibration and

the output voltage is proportional to the temperature. The scale factor for

temperature to voltage conversion is 1/ m per +C. The "#$% series sensors

come in di2erent pac3ages. The one I used is in a hermatic T456 transistor

pac3age where the metal case is connected to the negative pin 7nd8.

 The measurement of negative temperatures below /+C8 re'uires a negative

voltage source. 9owever* this project does not use any negative voltage source*

and therefore will demonstrate the use of sensor for measuring temperatures

above /+C up to 1//+C8.

 The output voltage from the sensor is converted to a 1/bit digital number using

the internal A&C of the PIC166!!. -ince the voltage to be measured by the A&Cranges from / to 1./ that corresponds to ma0imum temperature range* 1//

Page 2: A Digital Temperature Meter Using an LM35 Temperature Sensor

7/24/2019 A Digital Temperature Meter Using an LM35 Temperature Sensor

http://slidepdf.com/reader/full/a-digital-temperature-meter-using-an-lm35-temperature-sensor 2/10

+C8* the A&C re'uires a lower reference voltage instead of the supply voltage

dd : %8 for A;& conversion in order to get better accuracy. The lower reference

voltage can be provided using a <ener diode* a resistor networ3* or sometime

 just simple diodes. =ou can derive an appro0imate 1.) reference voltage by

connecting two diodes and a resistor in series across the supply voltage* as

shown below. As a demonstration* I am going to use this circuit in this project. Imeasured the output voltage across the two diodes as 1.1>6 . The resistor ? I

used is of $.6@* but you can use 1@ too. The important thing is to measure the

voltage across the two diodes as accurate as possible.

e need do some math for A;& conversion. 4ur ref is 1.1>6 * and the A&C is

1/bit. -o* any input voltage from /1.1>6 will be mapped to a digital number

between /1/)$. The resolution of A&C is 1.1>6;1/)5 : /.//116! ;Count. Therefore* the digital output corresponding to any input voltage in :

in;/.//116!. ,ow* lets see how to get the temperature bac3 from this whole

process of converting sensorBs output to 1/bit digital number.

Assume* the surrounding temperature is )6.5 +C. The sensor output will be )65

m /.)65 8. The output of A&C will be /.)65;/.//116! : ))6. If we reverse this

process* we have ))6 from A&C and we can go bac3 and nd the temperature by

using the sensor scale factor 1/ m;+C8*

temperature : ))6 D /.//116! ;Count8 ; /./1 ;+C8 : )6.5 +C

If you want to avoid Eoating point math in your program* just use*

temperature : ))6 D 116! : )6$>6!

hile displaying this* you need to put a decimal at the fourth place from the left.

-o the calculated temperature is )6.$>6!+C* which is pretty close to the actual

one. The di2erence is caused by 'uantiFation and rounding errors. In this project*

we will display temperature accurate to one decimal place* i.e.* we will divide the

above number by 1/// to get )6$. -o the temperature will be displayed as )6.$

+C.

Page 3: A Digital Temperature Meter Using an LM35 Temperature Sensor

7/24/2019 A Digital Temperature Meter Using an LM35 Temperature Sensor

http://slidepdf.com/reader/full/a-digital-temperature-meter-using-an-lm35-temperature-sensor 3/10

4nce you have derived the temperature bac3 in +C* you can convert it to +

using a simple e'uation*

temperature in + : > 0 temperature in +C ;% G $)

In this case* the number you got for +C is scaled by 1/ )6$ for )6.$8* you shoulduse

temperature in + : > 0 temperature in +C ;% G $)/

-ince* the number for +C may not be e0actly divisible by % such as )6$ is not8*

you can further eliminate the Eoating point by scaling it one more time by 1/. -o

the new e'uation will be*

temperature in + : > 0 temperature in +C 0 1/ ;% G $)//

or* temperature in + : 1! 0 temperature in +C G $)// : 1! 0 )6$G$)// :

H>$5

H>.$5 + is e'uivalent to )6.$ +C. In this project* it will be displayed as H>.$ +.

Circuit Diagram

An e0ternal reference voltage to the internal A&C of PIC166!! can be provided

through ?A1 I;4 pin. The output from the "#$% sensor is read through ?A);A,)

A&C channel. The temperature is displayed on a 16() character "C& that is

operating in the 5bit mode. A %@ potentiometer is used to adjust the contrast

level on the display. The detail circuit diagram is given below. ,ote that the

PIC166!! uses its internal cloc3 at 5./ #9F.

Page 4: A Digital Temperature Meter Using an LM35 Temperature Sensor

7/24/2019 A Digital Temperature Meter Using an LM35 Temperature Sensor

http://slidepdf.com/reader/full/a-digital-temperature-meter-using-an-lm35-temperature-sensor 4/10

Circuit setup on the breadboard

Page 5: A Digital Temperature Meter Using an LM35 Temperature Sensor

7/24/2019 A Digital Temperature Meter Using an LM35 Temperature Sensor

http://slidepdf.com/reader/full/a-digital-temperature-meter-using-an-lm35-temperature-sensor 5/10

A closer loo3 at the "#$%&9 sensor and the reference voltage circuit.

Software

 The rmware for this project is developed with #i3roC Pro for PIC compiler. The

lin3 to download the compiled 9J code is provided at the bottom of this section.

 The conguration bits for PIC166!! are

4scillator K Internal ?C ,o Cloc3

atchdog Timer K 42 

Power Lp Timer K 4n

#aster Clear nable K nabled

Code Protect K 42 

&ata ?ead Protect K 42 

Mrown 4ut &etect K M4& nabled* -M4?, &isabled

Internal 0ternal -witch 4ver #ode K nabled

#onitor Cloc3 ail-afe K nabled

 =ou can set these fuses in the dit Project window ProjectK dit Project8

;D &igital Thermometer using PIC166!! and "#$%

Internal 4scillator N 5#9F* #C"? nabled* P?T nabled* &T 4 Copyright N

?ajendra Mhatt ,ovember !* )/1/ D;

;; "C& module connections

sbit "C&O?- at ?C5Obit

Page 6: A Digital Temperature Meter Using an LM35 Temperature Sensor

7/24/2019 A Digital Temperature Meter Using an LM35 Temperature Sensor

http://slidepdf.com/reader/full/a-digital-temperature-meter-using-an-lm35-temperature-sensor 6/10

sbit "C&O, at ?C%Obit

sbit "C&O&5 at ?C/Obit

sbit "C&O&% at ?C1Obit

sbit "C&O&6 at ?C)Obit

sbit "C&O&H at ?C$Obit

sbit "C&O?-O&irection at T?I-C5Obit

sbit "C&O,O&irection at T?I-C%Obit

sbit "C&O&5O&irection at T?I-C/Obit

sbit "C&O&%O&irection at T?I-C1Obit

sbit "C&O&6O&irection at T?I-C)Obit

sbit "C&O&HO&irection at T?I-C$Obit

;; nd "C& module connections

;; &ene #essages

char message/QR : S"C& InitialiFedS

char message1QR : S?oom TemperatureS

;; -tring array to store temperature value to display

char DtempC : S///./S

char Dtemp : S///./S

;; ariables to store temperature values

unsigned int tempin* tempinC

unsigned long tempOvalue

void &isplayOTemperature8

 ;; convert Temp to characters

 if tempinC;1////8

 ;; 5! is the decimal character code value for displaying / on "C&

 tempCQ/R : tempinC;1//// G 5!

 else tempCQ/R : U U

 tempCQ1R : tempinC;1///8V1/ G 5! ;; 0tract tens digit

Page 7: A Digital Temperature Meter Using an LM35 Temperature Sensor

7/24/2019 A Digital Temperature Meter Using an LM35 Temperature Sensor

http://slidepdf.com/reader/full/a-digital-temperature-meter-using-an-lm35-temperature-sensor 7/10

 tempCQ)R : tempinC;1//8V1/ G 5! ;; 0tract ones digit

 ;; convert tempOfraction to characters

 tempCQ5R : tempinC;1/8V1/ G 5! ;; 0tract tens digit

 ;; print temperature on "C&

 "cdO4ut)* 1* tempC8

 if tempin;1////8

 tempQ/R : tempin;1//// G 5!

 else tempQ/R : U U

 tempQ1R : tempin;1///8V1/ G 5! ;; 0tract tens digit

 tempQ)R : tempin;1//8V1/ G 5!

 tempQ5R : tempin;1/8V1/ G 5!

 ;; print temperature on "C&

 "cdO4ut)* 1/* temp8

W

void main8

 A,-" : /b/////1// ;; ?A);A,) is analog input

 A&C4,/ : /b/1//1/// ;; Connect A,) to -;9* select ref:1.1>

 C#C4,/ : /0/H ;; &isbale comparators

 T?I-C : /b//////// ;; P4?TC All 4utputs

 T?I-A : /b////111/ ;; P4?TA All 4utputs* 0cept ?A$ and ?A)

 "cdOInit8 ;; InitialiFe "C&

 "cdOCmdO"C&OC"A?8 ;; C"A? display

 "cdOCmdO"C&OCL?-4?O48 ;; Cursor o2 

 "cdO4ut1*1*message/8

 &elayOms1///8

 "cdO4ut1*1*message18 ;; rite message1 in 1st row

 ;; Print degree character

 "cdOChr)*6*))$8

Page 8: A Digital Temperature Meter Using an LM35 Temperature Sensor

7/24/2019 A Digital Temperature Meter Using an LM35 Temperature Sensor

http://slidepdf.com/reader/full/a-digital-temperature-meter-using-an-lm35-temperature-sensor 8/10

 "cdOChr)*1%*))$8

 ;; &i2erent "C& displays have di2erent char code for degree symbol

 ;; if you see gree3 alpha letter try typing 1H! instead of ))$

 "cdOChr)*H*UCU8

 "cdOChr)*16*UU8

 do

 tempOvalue : A&CO?ead)8

 tempOvalue : tempOvalueD116!

 tempinC : tempOvalue;1///

 tempinC : tempinCD1/

 tempin : >DtempinC;% G $)//

 &isplayOTemperature8

 &elayOms1///8 ;; Temperature sampling at 1 sec interval

 W while18

W

&ownload 9J le

Output

I too3 some pictures of the completed project displaying temperatures in both

the scales.

Page 9: A Digital Temperature Meter Using an LM35 Temperature Sensor

7/24/2019 A Digital Temperature Meter Using an LM35 Temperature Sensor

http://slidepdf.com/reader/full/a-digital-temperature-meter-using-an-lm35-temperature-sensor 9/10

 Temperature goes up if you touch the sensor with your ngers

Accuracy of the measurement

Page 10: A Digital Temperature Meter Using an LM35 Temperature Sensor

7/24/2019 A Digital Temperature Meter Using an LM35 Temperature Sensor

http://slidepdf.com/reader/full/a-digital-temperature-meter-using-an-lm35-temperature-sensor 10/10

 The accuracy of the temperature measurement highly depends upon the stability

of the reference voltage. If the reference voltage drifts from the value that we

considered in our calculation* the measured temperature value could be

signicantly o2 from the actual value. Lsing a simple dioderesistor networ3 for

deriving a reference voltage may not be a very good idea* but the purpose of this

project was to demonstrate the techni'ue* not to come up with a commercialdigital thermometer product. =ou can also try a <ener diode or a potentiometer

to derive the reference voltage. Mesides* the 'uantiFation error introduced by the

1/bit A&C* rounding numbers while doing the math* and the accuracy of the

sensor itself within the desired range of temperature also a2ect the

measurement output. ?ead the manufacturerBs datasheet for more details on the

performance of the "#$% series sensor.

pdate

 This design has a little Eaw. It uses a voltage drop across two diodes X 1.) 8 asa reference voltage ref8 for A;& conversion. 9owever* the datasheet of

PIC166!! suggests to use ref greater than ).) to ensure 1"-M accuracy in

the A;& conversion. Therefore* I have rewritten this project but this time using a

#CP1%)% device for creating a precise ).% reference voltage. The new design is

more precise and accurate in ta3ing temperature measurements