Continue to Site

# LM35 temp sensor project

Status
Not open for further replies.

#### jakeselectronics

##### Member
I know this has been asked about a number of times, but i cant be bothered syfering though past posts to find my answer.

This will be my first ADC.
I will use a PIC16F877A (because i have one handy) for the ADC.

I just have a question of reference voltages etc.

Well first, is it nesscessary to amplify the output from the LM35.
Or will the pic be able to pick up voltages as low as 10mV.

Back to reference voltages..
just for argument sake, If the Vref+ is 5 volts and Vref- is 0 volts, and i have 2.5volts on the analogue input, will i get (or close to it) 10000000.

I dont want to ask for any code, I want to learn by having to think hard about it, I will write the code myself...
I just need to understand a few things before i start...

I am new to ADC and Vref voltages.
I would appreciate a bit of an introduction.

10bit ADC quantizes the range from Vref+ to Vref- into 2^10 =1024 steps. 5/1024=4.88mV, so you will get approx. 2 steps per degC.

The 5V used as Vref+ had better be damn accurate, better than a LM7805. The ADC reading is ratiometric with the 5V supply, so if it changes, so will the reading.

Last edited:
10bit ADC quantizes the range from Vref+ to Vref- into 2^10 =1024 steps. 5/1024=4.88mV, so you will get approx. 2 steps per degC.
Ok, just let me make sure i understand this.

If Vref+ = 5,
and Vref- = 0.
Every increment of 4.88mV will increment the binary number (in the ADC) by 1.
So if its 9.76mV, i will get 00 00000010 ?

The 5V used as Vref+ had better be damn accurate, better than a LM7805. The ADC reading is ratiometric with the 5V supply, so if it changes, so will the reading.
Can i use the internal reference voltages?
or are they taken straight from the supply rails inside the PIC and just as bad?
What do people normally do to get a steady and constant voltage for the Vref+?

Can i use the internal reference voltages?
or are they taken straight from the supply rails inside the PIC and just as bad?
What do people normally do to get a steady and constant voltage for the Vref+?
Isn't the internal reference voltage just VCC & VSS?

The 7805 regulator tolerance is something like +/-10%. For a more accurate reference voltage use a dedicated reference IC. The TS(or TL?)431 is cheap and can have a base accuracy of something in the order of 0.5%.

If you use a 5v supply that is 5.12v then a LM35 or LM335 will put out exactly 0.5 degrees per ADC count. I usually dig through my bag of cheapass 7805's and find one that is about 5.08 or 5.09, that's close enough.

The output of a 7805 doesn't change much if the 7805 is kept anywhere near room temp (like indoors) they have some temp compensation for voltage. The 10% tolerance is per part, because some are high and some are low but once you pick a 7805 its voltage won't change much (unless you place big current loads on it).

Using Vref and 5V, thats a precession of ~ 0.5 degrees. What I did was put 0.5 volts onto vref and now have 0.05 Degree precession, but i round that up.

What I did was put 0.5 volts onto vref and now have 0.05 Degree precession, but i round that up.
Vref min voltage is 2V for 10-bit precision, not sure how much it degrades with lesser Vref though.

Really?
Uh oh
Where did you get that info from?

Last edited:
Its an analogue input, why min 2V?

Really?
Uh oh
Where did you get that info from?
It's in the datasheet I've got in the electrical specifications section.

Its an analogue input, why min 2V?
The Vref is different to an analogue input - it's the upper reference voltage of the ADC

Which datasheet, what page?
For the 16f877a?

A20 VREF Reference Voltage (VREF+ – VREF-) 2.0 — VDD + 0.3 V

I'll go fix my other project Op amp time!

What does AVdd mean?

Probably referrign to the power pin for the analog circuitry. Some of the PICs have multiple Vdd and/or Vss pins.

How well was your ADC working with a Vref of 0.5v?? I've wondered about that, I think the Vref limit is because the ADV accuracy gets funky below 2v Vref. Did you check the full range of the ADC (like with a pot?)

Since your curious, ill give it a try tonight before fixing it . Ah, it means Vdd A? Since theres only 1 Vdd that means AVdd = Vdd?

So will it work if I connect the lm35 straight to an analogue input, and use the internal ref's?

Of course, you will only get .5 Degree precision though. And since the ADC is +-1 bit, it will bounce up and down a bunch, which I found annoying

Ok so MR. Rb, here are the results :
Sample 1 :
With Vref at .5V Temp shown = 23.4
at Vdd = 22.0

Sample 2 (With a heater)
With Vref at .5V Temp shown = 32.4
at Vdd = 32.3
with digital thermometer = 38.5 <--- made in china So i dunno. lol
Sample 3:
While cooling back down
With Vref at .5V Temp shown = 26.4
at Vdd = 24.9

Ok so i didn't really do this too scientifically, but I think I proved that the readings are different at different voltages. I made the switch quickly with my ICSP (from Vref to Vdd) 0.5V to 5V, so my results were scaled by 10.

Thanks for that that's some good information. There seems to be a few counts error when the ADC voltage is very low (like in your first sample).

Maybe it's getting a non-linearity error because of the low Vref and low ADC input voltage.

Of course, you will only get .5 Degree precision though. And since the ADC is +-1 bit, it will bounce up and down a bunch, which I found annoying
ohhhh i see.

So if i want a display to go to 1 decimal place, (ie, 25.4) i will need to measure increments of 1 millivolt.
(becasue my LM35 measures 10mV/degree)

and to do that, i have to increase resolution.

And to increase resolution i have to make the ref range smaller.
To infact 1.024v.
So if my range is 1.024V;
1.024/1024= .001v
So i will get increments every 1 millivolt.

Is all this correct.
If so how to i go about making the ref range smaller.
Would i raise Vref- from 0,
or would i lower Vref+.
Which one would be better?

Is all this correct. If so how to i go about making the ref range smaller. Would i raise Vref- from 0,
or would i lower Vref+. Which one would be better?

I'd suggest amplifying the signal before feeding it into the ADC, and using a VREF >2V.

Status
Not open for further replies.