# temperature sensor LM35

Discussion in 'Electronic Projects Design/Ideas/Reviews' started by civictypeR, Dec 6, 2007.

1. ### ericgibbsWell-Known MemberMost Helpful Member

Joined:
Jan 4, 2007
Messages:
21,350
Likes:
649
Location:
Ex Yorks' Hants UK
hi,
You are correct that the LM35 requires 4V minimum, I use +5V.

The Vref I explained in my previous posts was for the +Vref pin of the PIC.

Get a 2.5V ref ic and connect the 2.5V output to the +Vref of the PIC.

This will set the PIC's adc conversion so that for a 2.5V input voltage onto the adc inputs, it will give a conversion value of 1023 decimal [3FFh]

Connect the LM35 Vs to +5V and the LM35 output to an adc input pin on the PIC.

So if the temperature is say, 100Cdeg, the 1,0V output from the LM35 will give a conversion value of [1.0V/2.5Vref] * 1023 = 409

This value has to be multiplied within the program to make it equivalent to 100Cdeg.

I prefer to use the PIC's internal +Vref [5v] and use an amplifier with a gain of five.
This means the output from the LM35 at 100Cdeg = 5V, so the adc converts this to 1023, the maximum possible value.

Do you understand this OK.?

2. ### cabralNew Member

Joined:
Apr 27, 2009
Messages:
9
Likes:
0
Got it!
But in the original circuit pin 5 of the pic 16F73, +Vref ( RA3 ) is not connected to anything! I need to stabilize a voltage of 2.5 V and connect this pin? Is this?

I appreciate the help and patience!

Cabral

3. ### ericgibbsWell-Known MemberMost Helpful Member

Joined:
Jan 4, 2007
Messages:
21,350
Likes:
649
Location:
Ex Yorks' Hants UK
hi,
Do you have a circuit diagram you could post.?

If you use a 2.5V ref, you must alter the program to make RA3 a Vref pin...

Joined:
Jan 12, 1997
Messages:
-
Likes:
0

5. ### cabralNew Member

Joined:
Apr 27, 2009
Messages:
9
Likes:
0

I will post the circuit diagram, and you can analyze it and make changes that will need to be made in
program and the hardware, ok? (The entire program I posted earlier)

Thank you again!

Cabral

#### Attached Files:

• ###### termometro.JPG
File size:
38.9 KB
Views:
692
Last edited: May 12, 2009
6. ### ericgibbsWell-Known MemberMost Helpful Member

Joined:
Jan 4, 2007
Messages:
21,350
Likes:
649
Location:
Ex Yorks' Hants UK
hi,
Look at this image.
Change ADCON1 configuration to set AN3 as a +Vref pin

File size:
39.9 KB
Views:
1,564
7. ### hckeatNew Member

Joined:
May 3, 2009
Messages:
8
Likes:
0
DEFINE osc 20

Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1

temp var word
temperature var word
quanta con 1250

TRISA = %11111111

Pause 500
Lcdout \$fe, 1

loop:
pause 5

temperature= (temp*10) */ quanta
lcdout \$fe,2
lcdout \$fe,\$80,"Temp ",dec2 (temperature/100),".", dec1 (temperature//100),\$DF,"C"
Pause 200

Goto loop
End

OK. Now I have this code of displaying temperature on LCD, I need to improve it where I need to use a keypad to enter a value of temperature, when the air temperature equal of greater than the temperature being set, PIC will ON a LED. I am wondering how to insert the keypad part. I'll be using a 4*3 keypad.

8. ### cabralNew Member

Joined:
Apr 27, 2009
Messages:
9
Likes:
0
Ericgibbs,

How is the first time you use a PIC with ADC input, just not with literature on the internet to help me configure AN3 as voltage reference.
Make time I tried to not need to ask, but really is not an answer here, give the projeto.Agradeço if you can analyze the source code as posted above and make the necessary changes ...

Cabral

9. ### ericgibbsWell-Known MemberMost Helpful Member

Joined:
Jan 4, 2007
Messages:
21,350
Likes:
649
Location:
Ex Yorks' Hants UK
hi,
Do you mean this code.???, please confirm.

I understand you require RA3 as a +Vref for the ADC.?

Code (text):
DEFINE osc 20

Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1

temp var word
temperature var word
quanta con 1250

TRISA = %11111111

Pause 500
Lcdout \$fe, 1

loop:
pause 5

temperature= (temp*10) */ quanta
lcdout \$fe,2
lcdout \$fe,\$80,"Temp ",dec2 (temperature/100),".", dec1 (temperature//100),\$DF,"C"
Pause 200

Goto loop
End

10. ### cabralNew Member

Joined:
Apr 27, 2009
Messages:
9
Likes:
0
The pic is a 16F73 and this is the code below. You showed me to a reference voltage of 2.56v on pin 5 (AN3), so I did, but to configure, document RA3 + Vref for the ADC, I can not!

DEFINE LCD_DREG PORTB ' LCD Data bits on PORTB
DEFINE LCD_DBIT 0 ' PORTB starting address
DEFINE LCD_RSREG PORTB ' LCD RS bit on PORTB
DEFINE LCD_RSBIT 5 ' LCD RS bit address
DEFINE LCD_EREG PORTB ' LCD E bit on PORTB
DEFINE LCD_EBIT 4 ' LCD E bit address
DEFINE LCD_BITS 4 ' LCD in 4-bit mode
DEFINE LCD_LINES 2 ' LCD has 2 rows
'
' Define A/D converter parameters
'
DEFINE ADC_BITS 8 ' A/D number of bits
DEFINE ADC_CLOCK 3 ' Use A/D internal RC clock
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us
DEG CON 223
'
' Variables
'
Res Var Word ' A/D converter result
Temp1 Var Byte ' Temperature in degrees C
quatro var byte
TRISA = 1 ' RA0 (AN0) is input
TRISB = 0 ' PORTB is output
PAUSE 500 ' Wait 0.5sec for LCD to initialize
'
' Initialize the A/D converter
'
' make reference voltage = VDD
ADCON0 = %11000001 ' A/D clock is internal RC, select AN0
' Turn on A/D converter
LCDOUT \$FE, 1 ' Clear LCD
AGAIN:
'
' Start A/D conversion
'

Temp1 = Res * 2' Convert to degrees C
LCDOUT \$FE,2,"TEMP = ",DEC Temp1, deg,"C"
PAUSE 1000 ' Wait 1 second
GOTO AGAIN ' Repeat
END ' End of program

11. ### ericgibbsWell-Known MemberMost Helpful Member

Joined:
Jan 4, 2007
Messages:
21,350
Likes:
649
Location:
Ex Yorks' Hants UK
hi,
Code (text):

change to

Look at this image.

File size:
32.3 KB
Views:
366
12. ### cabralNew Member

Joined:
Apr 27, 2009
Messages:
9
Likes:
0
Unfortunately it did not work ... The LCD shows 254 degrees and does not change if not heat or cool the LM35

13. ### ericgibbsWell-Known MemberMost Helpful Member

Joined:
Jan 4, 2007
Messages:
21,350
Likes:
649
Location:
Ex Yorks' Hants UK
What voltage do have connected to AN3, it should be +2.5V, thats the reference voltage that you have to apply to the AN3 pin.

#### Attached Files:

• ###### termometro.JPG
File size:
41.7 KB
Views:
834
Last edited: Jun 26, 2009
14. ### ericgibbsWell-Known MemberMost Helpful Member

Joined:
Jan 4, 2007
Messages:
21,350
Likes:
649
Location:
Ex Yorks' Hants UK
You are not setiing the ADCON1 correctly!!!!!

Its not correct if you want to use a external +2.5V ref.

Please post a circuit diagram showing how you have the analog pins connected.

15. ### cabralNew Member

Joined:
Apr 27, 2009
Messages:
9
Likes:
0
Ericgibbs,

I put a reference of 2.56 volts on pin 5 (AN3) as you guided me in the drawing in
Annex, and the software I replace the ADCON1 = 0
as you guided me ...

Cabral

File size:
39.9 KB
Views:
798
16. ### ericgibbsWell-Known MemberMost Helpful Member

Joined:
Jan 4, 2007
Messages:
21,350
Likes:
649
Location:
Ex Yorks' Hants UK
hi,
This is your program, I have had to modify it so that it will run in the Oshonsoft simulator.

Its uses the same pins as your circuit, with ADCON1 set and it works OK.

Look at this image.

#### Attached Files:

• ###### AAAimage03.gif
File size:
77.8 KB
Views:
450
Last edited: Jun 26, 2009
17. ### cabralNew Member

Joined:
Apr 27, 2009
Messages:
9
Likes:
0
Ericgibbs,

It worked! Now worked!

and 2.56 V on pin 5 (AN3) and not more variable Temp1 multiply by two (res = temp1 * 2) and
worked very well!

Thank you very much for your help and patience friend!

Big hug,

Cabral

18. ### avzMember

Joined:
Nov 30, 2008
Messages:
95
Likes:
0
Hi
is it possible to build a simpler version (without the PIC) of a lm35 based thermometer? all I want it to do is to measure and disply. if there is, could you please direct me to where I can find the diagram?
Thanks.

19. ### ericgibbsWell-Known MemberMost Helpful Member

Joined:
Jan 4, 2007
Messages:
21,350
Likes:
649
Location:
Ex Yorks' Hants UK
hi,
Look at the datasheet for the ICL7106, with a simple amplifier and a LM35 you can make a temperature display.

File size:
219.5 KB
Views:
377
20. ### zhiyungsuckballsNew Member

Joined:
Aug 3, 2009
Messages:
1
Likes:
0
Hi, I need to boost the output voltage of LM35 to 4 ~ 7V. How do i go about building the circuit? Please kindly include circuit diagrams as I'm a noob in circuit designs. Thanks and your help is greatly appreciated.

21. ### enenxxNew Member

Joined:
Sep 7, 2009
Messages:
1
Likes:
0
Hi, i am new here
i need some help. i need to build a thermometer..
i am ask to design a circuit using LM35 and ampilfied by a op-amp MCP602 to 5v..
then connected to PIC16F876..