LM35 + Arduino uno not giving correct reading

i am trying to LM35 temprature sensor with arduino uno with this sketch to read tempratue.

const int inpin = 0;

void setup ()
{
  Serial.begin(9600);
}
void loop ()
{
  int value = analogRead(inpin);
  Serial.print(value); Serial.print(">");
  float millivolts = (value / 1024.0)*5000;
  float celsius = millivolts / 10;
     Serial.print(celsius);
     Serial.print("Degree celsius,  ");
     Serial.print((celsius * 9)/ 5 + 32  );
     Serial.println("Degree Farnheat");
     delay(1000);
}

but it is not giving correct reading

Please find it why??????????

Post a wiring diagram! Which type of LM35 are you using?

lm35-1.png

Working alright for my LM35+NANO under your program. Please, check wiring for loose/missing connections.

lm35-1.png

Just as a wild guess, I'd guess you're missing a ground connection between the LM35 and the Arduino.

Or...

const int inpin = 0;

Does that work??? Try reading pin A0.

DVDdoug:
Does that work??? Try reading pin A0.

Yes it does. The compiler is clever enough to work out that you meant A0 instead of D0 after an analogRead call.
But it's indeed better to use A0 to stop confusion, and to use better names and const byte for pin numbers.

const byte tempPin = A0;

An LM35 has an output of 10mV/degreeC, and Arduino's A/D with default Aref is ~5mVper step.
That means you can only have a resolution of 0.5C at best.
A two decimal place readout (0.01C) is wishful thinking.
You can improve resolution by using 1.1volt Aref in setup().
That increases resolution to 0.1C.
Then use Serial.print(celsius, 1); // one decimal place

But don't start improving things if you haven't got it working yet.
The LM35 might need a 100n cap between 5volt and ground, right next to the chip.
And some (fake) chips will never work.
One day you will discover the much easier to use DS18B20.
Leo..

Try this sketch if your have your LM35 working.
Leo..

// LM35_TMP36 temp
// works on 5volt and 3.3volt Arduinos
// connect LM35 to 5volt A0 and ground
// connect TPM36 to 3.3volt A0 and ground
// calibrate temp by changing the last digit(s) of "0.1039"

const byte tempPin = A0;
float calibration = 0.1039;
float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
  analogReference(INTERNAL); // use internal 1.1volt Aref
  Serial.begin(9600);
}

void loop() {
  tempC = analogRead(tempPin) * calibration; // use this line for an LM35
  //tempC = (analogRead(tempPin) * calibration) - 50.0; // use this line for a TMP36
  tempF = tempC * 1.8 + 32.0; // C to F
  Serial.print("Temperature is  ");
  Serial.print(tempC, 1); // one decimal place
  Serial.print(" Celcius  ");
  Serial.print(tempF, 1);
  Serial.println(" Fahrenheit");

  delay(1000); // use a non-blocking delay when combined with other code
}

DVDdoug:
Just as a wild guess, I'd guess you're missing a ground connection between the LM35 and the Arduino.

Or...

const int inpin = 0;

Does that work??? Try reading pin A0.

I suspected so; but, it works well with inpin=0, A0, and 14.

thanks to all for reply me..
i have also try int inpin = A0; ,int inpin = 0;
now
i am sharing my wiring & reading of LM35 in serial monitor,,
...... please see in attachment..
reading data is not increasing in sequecne here..., it is increasing & decreasing in random...
i think ,in correct result reading should be increasiing low to current (slowly),
now you are requested to tell me , what is wrong in this project

Hi,
OPs picture;


How long are the wires to the LM35?

Tom.. :slight_smile:

6 or 8 inch long

Did you already try a 100n ceramic cap on the two outside pins of the sensor (5volt and ground).
Leo..

Wawa:
One day you will discover the much easier to use DS18B20.
Leo..

Best advice so far in this thread :slight_smile:
I've been struggling a long time to get the analog readings right with LM35 sensors. Use a OneWire device instead. Considering the code size I spent to catch fluctuating reference voltage and/or one-time spikes when switching heavy loads there is not much overhead if you are just using the Onewire library functions

Wawa:
Did you already try a 100n ceramic cap on the two outside pins of the sensor (5volt and ground).
Leo..

Tell me details wiring of 100n cap. Where to connect+. Where to - of capistor to where?????

Cap the cap+ to signal wire and cap- to ground. You could have a bad and crappy sensor.

Also you are using sending a calculation of a float value which could come across funky thru usb. Try declaring the value of "(celsius * 9)/ 5 + 32 " in a variable first.

Finally make sure your baud speed on the PC side is set to 9600. The amount and frequency of the zeros make me think data translation issue.

thank to all of you ,
on your advice, i tried capistor. electronic store keeper gave me 10uf instead of 100n because of lack of 100n
in local store. after connecting it in circuit , i saw it is working. but reading is not crossing (8.30 Degree) where my room temp is great than 20 Degree.
i think use of capistor is better than alone LM35.
actually , i want to use this project in a heating theorapy machine. which will auto on/off by relay according to given temperature limit. so....
For correct reading
should i replace 10uf cap with 100nf.????? or any more