LM35 and analogReference()

I have noticed that when people use the LM35 the conversion code is "temp = (5val100)/1024"
I read this as taking what percentage "val" is out of 1024, multiply that by the overall voltage range for the analog pin (5000 mV) and dividing by 10 (for the 10mV/deg C)
Could you increase the accurancy of the input by using analogReference(internal) to set the reference voltage range to 1.1 volts and not 5 volts? This would give better resolution in the range that the LM35 opperates (0-1000mV) right? So would the resolution would be 0.107 degs compared with normally 0.488 degs.
I know that the LM35 have an accuracy of about 0.5 degs so the resolution increase is somewhat trivial.
Also would doing it this way limit all other analog sensors to the 1.1V reference or would you just toggle the reference just before reading the sensor?
At the moment I am just trying to understand as much theory before I start tinkering as it looks like I am going to have to hope that Santa brings me an Arduino for Christmas ::slight_smile:
The first project I have lined up will be to build a temperature controller for a fermenting fridge complete with LCD display, then go from there.

Yes, you can use the 1.1V internal reference to improve resolution.
No, it doesn't limit other analogue inputs to using the 1.1V reference BUT you must allow settling time after switching the reference.
Check the datasheet.

I've spent some time reading those datasheets and implementation notes, though I am also learning and might be confused a lot.
You have to tweak the output of the LM35. The default resolution is .01v per degree so you 0 degrees Celsius will always be 2.73v and that means that if you use the internal 1.1V reference you will always read the maximum. As far as I understand you can make a voltage divider at the output to provide the required "squeezing".
Here is a note I've read that explains some of the things:
http://www.national.com/an/AN/AN-460.pdf

I though the LM35 range was 0 - 100 degs C, So 0 degs C would be 0 mV and 100 degs C would be 1000 mV (or 1 V). The LM335 works in Kelvin so this would be the 2.73 V at 0 degs C (273 degs K).
I am keen to sort out what the best sensor is for my project as I will only need to measure between 0 and 30 degs C max. I'll probably go with the LM35 as it is so simple to hook up and does not need a resistor between the source and sensor (am I right?).
Cheers

Reading that data sheet I noticed that the LM34 range in the basic circuit with only 1 positive power supply is 5 to 300 degs F or approx. -15 to 150 degs C. This would make for an easier alternative to the LM35 with a positive and negative supply for reading sub zero temperature, am I correct? :-? The tradeoff being that you would have to work in non SI units, but I think it would be worth it :slight_smile:

Very interesting! A few questions though. AWOL said:

No, it doesn't limit other analogue inputs to using the 1.1V reference

The thing is the analogReference() function DOESN'T take a pin number as a parameter. So how can you set the reference on a particular ADC pin and leave the rest with their default reference (5V)?

The documentation only mentions the Atmega8 (2.56V) and the Atmega168 (1.1V). I suppose the Atmega328 corresponds with the latter (1.1V)?

If an ADC is set to 1.1V reference and you "accidently" feed it 5V will that damage the board?

So how can you set the reference on a particular ADC pin and leave the rest with their default reference (5V)?

You can't; you have to switch the reference when you want to read a pin that requires the default reference, and allow some settling time.

Remember, there's only one ADC with a multiplexer on the input.

If an ADC is set to 1.1V reference and you "accidently" feed it 5V will that damage the board?

No, not at all; it will simply saturate. (assuming it isn't a 3.3V board!).
Think about it; you're only changing the input to a comparator - as long as neither input exceeds the supply voltage, you're OK.

...and allow some settling time.

OK?! How much time are we talking?

...it will simply saturate

I suppose that means it will simply read as max?

Think about it...

My understanding of electronics is still at a very infantile level, so these things are far from obvious to me.

Anyway thanks for the reply :slight_smile:

OK?! How much time are we talking?

You'll need to watch the output, and decide for yourself when the output has become constant. A temperature sensor can take minutes to become stable. Once it does, though, switching the Vref value should stabilize at the new voltage in a few milliseconds.

I suppose that means it will simply read as max?

Yes, it does.