LM35 thermometer


I got some LM35 temperature sensors. With this code it's easy to read out the temperature for 0-100C degree:

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?

Thx Geko

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).


So: 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?

Thx Geko

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?

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.

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?

Man, that was fast!! :slight_smile:

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):

/*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 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.


OK, after going round and round in circles for the last few days, I’m not getting any closer to getting acceptable results out of this LM335 chip - see http://www.jaycar.com.au/products_uploaded/LM135.pdf for the datasheet. I’m getting SOME change in voltage at the sensor, but it’s nowhere near the measured change in temperature.

For example, just sitting on the desk at 21.6 deg C, the sensor is passing 2.970 volts. Cranking up a small heater, the measured temp is 50.6 degrees and the voltage has increased to 3.210 volts, an increase of 240 millivolts. Since each 10mV represents 1 degree, the LM335 is measuring a 24 degree increase, as opposed to the actual 29 degrees. 5 degrees is a fairly big discrepancy but it’s probably one that I can live with.

What’s confusing me is trying to work out why, over the above temperature range, the analog pin readings only move from 590 to 626? My board’s 5V output is actually 5.22V, hence there should be 5.22/1024=5.098 millivolts per ADC value, correct? So, 626-590 = 36, times by the step value of 5.098, gives 183.5 or so millivolts, nowhere near the 240mV I measured with the multimeter.

This is how I’ve got my sensor wired up:

------------±-----<2K2 resistor>------<+5.22V>
<Analog pin 0>

I’ve searched everywhere I can think of for this LM335 interface, so if anyone has any ideas or can see where I’ve gone wrong, please let me know!

I’m not past trying something else either - initially I tried using some thermistors instead of the LM335, but I think that they may not be quite up to the task. If anyone can recommend exactly which type of thermistor I should be using that would also be appreciated…

Thanks for reading, again!! :slight_smile:

Hi again... :-[

Just a quick note to say that I've managed to get a 1k thermistor working - hooray! So, don't spend too much time thinking about the LM335 I've been on about... even though it would be nice to know what I was doing wrong with them, I'm not all that fussed about it with another solution working just fine.




Could u share the info on the thermistor. I am also stuck with an LM335. Its not sensitive at all.


Hi Bob,

I haven't touched on this subject for quite a long time! At the moment, I don't have the information/part numbers at hand; they are in the field at a location some 200km from my office. I will have to make a special trip out there to check this out for you, so I just wanted to warn you that it could be quite some time (maybe 2 months) before I'm able to give you any more info... sorry!

I loved working with the Arduino, but for this project it was over-kill. No, scratch that: it provided a great environment for development and testing, which then proved that having the microcontroller was like re-inventing the wheel, only exceedingly more complicated than the original design! :)

I'll do my best to get the details for you ASAP - I may be out that way before 2 months is up, but I make no promises... ;)




I have used a 10k NTC thermistor and it works well. My sketch below (actually, someone else’s sketch that I modified and built on). Happy coding!

// (Ground) ---- (10k-Resister) -------|------- (Thermistor) ---- (+5v)
//                                     |
//                                Analog Pin 0

#include <math.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

double Thermister(int RawADC) {
 double Temp;
 Temp = log(((10240000/RawADC) - 10000));
 Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
 Temp = Temp - 273.15;            // Convert Kelvin to Celcius
 Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
 return Temp;

void setup()
  pinMode(14, OUTPUT);
  pinMode(16, OUTPUT);
  digitalWrite(14, HIGH);
  digitalWrite(16, LOW);

void loop()
//  lcd.setCursor(3, 1);
  lcd.print("Temp = ");
  lcd.print(int(Thermister(analogRead(1))));  // display Fahrenheit
  lcd.write(0b11011111);                      //This line is important lcd.write sends data and not ascii to the LCD (for special characters)
  lcd.print(" F");