Reading LM35 Temperature IC

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Sparkoids
Posts: 267
Joined: Mon Sep 14, 2009 10:34 am
Has thanked: 30 times
Been thanked: 19 times
Contact:

Reading LM35 Temperature IC

Post by Sparkoids »

Hi guys,

I have a Flowchart running correctly by taking parts from other people's samples here and that is great.

However I have actually got muddled up with a physical Temperature Sensor that works on Celsius (which I need) and a Fahrenheit Macro on the Flowchart which I only just noticed.

I am getting a variable ReadADC by sampling ADC(0) ReadAsInt

Then...

Fahrenheit = ReadADC * 50 / 102
Celsius = (Fahrenheit * 10 - 320) / 18


I get the conversion from F to C but how can I read the integer directly into Celsius please? It works as 10mV / Degree C...


Best regards,


James Dexter :-}

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Reading LM35 Temperature IC

Post by medelec35 »

Hi James,
It's the same formula for Celsius.

If you're using a LM35 then each deg C rise increases voltage by 10mV
If you're using a LM34 then each deg F rise increases voltage by 10mV
Hence the same formula can be applied to both!

You only need the C to F conversion if you want the display in F (or both C and F) but you only have a LM35
Or
You only need the F to C conversion if you want the display in C (or both F and C) but you only have a LM34

Martin
Martin

Sparkoids
Posts: 267
Joined: Mon Sep 14, 2009 10:34 am
Has thanked: 30 times
Been thanked: 19 times
Contact:

Re: Reading LM35 Temperature IC

Post by Sparkoids »

Martin I'm about to slap my forehead and shout "DOH of course it is!"

Why is the ReadADC * 50 / 102 part included though?

Elsewhere someone is reading it as a voltage - should I be doing that really?

James :-}

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Reading LM35 Temperature IC

Post by medelec35 »

Hi James,
Sparkoids wrote:Martin I'm about to slap my forehead and shout "DOH of course it is!"
No worries that could me off guard at first!
Sparkoids wrote:Why is the ReadADC * 50 / 102 part included though?
I posted about that here:
http://www.matrixmultimedia.com/mmforum ... 20&#p53036
Sparkoids wrote:Elsewhere someone is reading it as a voltage - should I be doing that really?
The reason ReadAsVoltage is not used is because that uses a float variable.
Using Float variable my make the result more accurate (remember there are tolerances within LM35) at the sacrifice of using loads more RAM and ROM
For the lower memory 8bit microcontrollers floats are not recommended.
Using ReadADC * 50 / 102 then since ReadADC will be using Integer and not 32bit float, then much less room is taken up.

Hope this helps

Martin
Martin

Bobw
Posts: 157
Joined: Sat Jan 22, 2011 10:39 pm
Location: Michigan
Has thanked: 6 times
Been thanked: 27 times
Contact:

Re: Reading LM35 Temperature IC

Post by Bobw »

James,
I ran into the same dilemma as you.
I am using an LM35 equivalent that reads -40C to 125C 10mv per degree C.
I do not know the PIC you are using, but going on the assumption that you have a 10 bit ADC 0-1023
If using a 5 volt supply, each ADC step will be worth 4.88MV
If using a 3.3 volt supply each ADC step will be worth 3.22MV
The LM35 can give a resolution of 0.1 degree C if each ADC step = 1MV
For better accuracy, I used a 5K 15 turn trim pot and fed it into my +VREF pin, I also fed this into my AN0 pin. I then selected read the ADC value as voltage (ReadVolt)
Multiplied that by 1000 (NO FLOATS REQUIRED) and printed the ReadVolt to the LCD. Adjust the trim pot so that the display reads 2048 which would = 2048 MV.
Now disconnect the input to AN0 and place the LM35 Vout there. Your sensor will now read with a resolution of 0.2 degrees per step of the ADC.
Do not for get to take into account the negative readings.
My final formula looks like this: Temp_C= (((Volts_ADC*1000)-100)/10)+-40
It requires no floats, you can use string manipulation to give a more normal 23.6 C
If you read the LM35 often, you will see the display going from 23.4 to 23.6 and back to 23.4 Actual reading is probably 23.5.
I have tested mine with a laboratory calibrated thermometer and find it to be +- .5 not bad in my book.
My 2 cents
See also :http://www.matrixmultimedia.com/mmforum ... 46&t=14472

BOB

Sparkoids
Posts: 267
Joined: Mon Sep 14, 2009 10:34 am
Has thanked: 30 times
Been thanked: 19 times
Contact:

Re: Reading LM35 Temperature IC

Post by Sparkoids »

Thank you very much indeed guys. These fast responses are exactly why Flowcode is perfect for development of micro controller projects.

All I need to do now is *accurately* set up 20mS cycle started by a 2.8mS negative voltage drop to trigger a Triac on and off via a zero volt crossing Opto and I'm sorted ;-}

Thanks all.....

Post Reply