Go Down

Topic: LM35 thermometer (Read 16835 times) previous topic - next topic



I got some LM35 temperature sensors.
With this code it's easy to read out the temperature for 0-100C degree:
Code: [Select]
temperature = (5.0 * val * 100.0)/1024.0;
But how can I measure minus temperatures? I don't get the idea from the data sheet so could you please help me?



Looks like it needs a negative voltage to measure negative temperature.  Figure 2 on the National datasheet shows the example circuit and paramters for a negative supply, Figure 7 shows a way to do it without a negative supply (Iwould guess this changes the formula for converting voltage to temp, but I didn't look that closely).



But arduino analog pins don't support reading negative voltages, do they? Is it any way to push to Vout of LM35 to ground levels?


Correct, no negative voltage reading on the Arduino ADC.

Look at figure 7 on the datasheet.  I believe they offset the 0 voltage and accomplish the full range without negative voltage outputs (at the cost of a modified conversion equation).



Oct 19, 2008, 08:09 am Last Edit: Oct 19, 2008, 08:13 am by GekoCH Reason: 1

From the LM35 I need two 1N914 Central Semiconductor and then to the GND.
From the OUT I just need a 18k 10% resistor to the GND.
And the put the - and + to the same Arduino pin.

This should be right or not?



I'm afraid that connecting Vout+ and Vout- to the same Arduino pin would cause a short, am i wrong?

My question now is:  in this circuit, could be  Vout+ to ground negative?


Oct 19, 2008, 10:37 am Last Edit: Oct 19, 2008, 10:39 am by ecerulm Reason: 1
Ok I found this article in the net http://www.hometoys.com/htinews/dec99/articles/hansen/hansen.htm

From the article, I understood that the Vout+ will be always positive when using two 1N914 to the ground. That actually raises the ground reference of the lm35 0.9v to all measures are shifted 0.9v.

Vout will give me the temperature in positive voltage always, but since 1nN914 voltage drop is heavily dependent on temperature itself I need to read Vout- using another analog input pin to know how much shift. The shift at 25C will be 0.9V but it will be maybe 0.7V at -5C  so in order to take accurate measures two analog pins are required, one for Vout- and one for Vout+, after doing the analog to digital conversion those must substracted to get the actual measure. The substraction must be done in software after analog-digital conversion because if we do it before we end up again with a negative voltage that cannot be connected to the Arduino pins


Try ignoring the Vout- shown, just hook Vout+ to the ADC input.  Make a new equation with an offset to allow for the 0.9V voltage difference across the diodes.  I haven't read the article carefully, so I don't know if it as simple as subtracting 900mV/10mV/C from the original equation, but that's my guess.

Also, there probably isn't anything special about those diodes, if you have some other diodes lying around they will likely work just as well.  Just use a meter to check the voltage drop across them (or read the datasheet for the diode).

FYI, there is a different analog sensor, the AD22100, that gives you -50C to +150C with a single 5V supply.  The negative offset is built in.

These little interfacing issues are why I like integrated devices.  The DS1621 and DS1722 measure -55C to over 100C and have I2C and SPI interfaces respectively.



I cannot agree more, I used DS1620 before (http://rubenlaguna.com/wp/tag/arduino-ds1620-digital-temp-temperature-sensor/) and although it's propietary 3-wires interface may look frightening at the beginning it's way simpler to use. I just wanted to experiment with analog LM335 but it seems harder than expected.  


Oct 29, 2008, 12:17 am Last Edit: Oct 29, 2008, 12:19 am by jbennett Reason: 1
Hi everyone,

I've been trying to implement this type of LM35 temperature sensor into my project but I'm getting some really erratic output. Using either a 5V or 10V input (and adjusting the conversion equation as required) I get output like this:

LM35 Thermometer    
analog value - computed temp
1013 - 49.4
835 - 40.7
312 - 15.2
879 - 42.9
93 - 4.5
842 - 41.1
87 - 4.2
882 - 43.0
87 - 4.2
880 - 42.9
107 - 5.2
918 - 44.8
93 - 4.5
930 - 45.4
50 - 2.4
1020 - 49.8
721 - 35.2
419 - 20.4
905 - 44.1
26 - 1.2
970 - 47.3

And these values are the averages of 10 readings. If I remove the sensor, the readings stabilise, but not in a useful fashion, plus I need the sensor located away from the board. Any ideas as to what may be causing these fluctuating readings?  :-?


JB, are you using a pulldown resistor?


Oct 29, 2008, 12:22 am Last Edit: Oct 29, 2008, 04:30 am by jbennett Reason: 1
Man, that was fast!! :)

No, I wasn't aware that I needed one... I'm pretty new to all of this electronics stuff! Can you advise me how to work out what type I need?


- EDIT -

OK, so I've solved the fluctuating readings problem - the 5V / 10V power supplies I was using seem to have caused them. As soon as I used the Arduino's 5V supply I got good steady readings.

Now my issue is that the readings seem to be WAY off the mark. Here's the code I'm using (slightly modified from this thread - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1203159459):
Code: [Select]
/*LM35 Thermometer
*LM35 simply connected to:           5+
*                             0V
*                             Analog Pin 0

int potPin = 0;                             //input read pin for LM35 is Analog Pin 0
float temperature = 0;                      //variable which will be calculated in process

void setup()
 Serial.println("LM35 Thermometer    ");       //Print "LM35 Thermometer" once at start

void  printTenths( int value){
  // prints a value of  123 as 12.3
     Serial.print(value / 10);
     Serial.println( value % 10);              

void loop ()                              
 int span = 20;
 int aRead = 0;
 for (int i = 0; i < span; i++) {        //loop to get average of 20 readings
   aRead = aRead + analogRead(potPin);
 aRead = aRead / span;

 temperature = (5.220*aRead*100/1024);           //convert voltage to temperature
 Serial.print ("Analog in reading: ");
 Serial.print (long(aRead));       //print temperature value on serial screen
   Serial.print (" - Calculated Temp: ");

At room temp (around 22 degrees C), I get a fairly steady output of:

Analog in reading: 927 - Calculated Temp: 47.2
Analog in reading: 927 - Calculated Temp: 47.2
Analog in reading: 928 - Calculated Temp: 47.3
Analog in reading: 927 - Calculated Temp: 47.2

Firstly, I thought that there must be a problem in the equation which calculates the temperature, but then I realised that the analog readings were way too high to be correct on this scale in the first place. I'd be expecting readings somewhere around 140 for room temperature..? From the LM35 datasheet, the LM35 should give a temperature range of +2 to +150 deg C in the Basic configuration, so a reading of 927 works out at around 136 degrees!! Can anyone help me get the correct numbers from the analog input?!?

Thanks for reading!


Unless you are trying to measure below 0C, a  pulldown resistor is not necessary.

Why are you multiplying by 5.22?  Aref should be 5V.

Why are you converting the variable aRead to long before printing?

I suggest:  1) do a
Code: [Select]
Serial.print(analogRead(potPin)); and perform the ADC -> voltage -> temperature conversion by hand to check the results; and 2) use a meter to check the voltage on the LM35 output pin and see if it's sane; 3) forget about floats, and use integer readings; 4) forget about averaging.

Once you get sane readings, then go back and add averaging, fixed/floating point (hint, accuracy of the device is only +/- 0.5C), etc.



Hi kg4wsv,

Glad to hear about the pulldown resistor, I'm not worried at all about low temperatures.

I was in the middle of writing a big reply to your post, when I went back to the spec sheets & discovered that I'm not using an LM35 sensor, I'm using an LM335 sensor!  :-[ This has raised lots of different issues which I'll plug away at, but certainly explains why my readings weren't making much sense!!

I'll post back here when I have (a) solved my problems or (b) need more help!!

Thanks, JB.

PS - 5.22 is the measured voltage from my 5V output.


I'm not using an LM35 sensor, I'm using an LM335 sensor!

That would make a difference. :)  The 335 looks a bit more complex to use.  Good luck with it.


Go Up