LM35 LCD Not reading the temperature properly

Hello.

I was using LM35 for my project to measure the water temperature.
The code was just like this from cricuitdigest.com

/-----------Digital Thermometer Using Arduino-------------/
#include<LiquidCrystal.h>
LiquidCrystal lcd(7,6,5,4,3,2);
#define sensor1 A0
byte degree[8] =
{
0b00011,
0b00011,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
void setup()
{
lcd.begin(16,2);
lcd.createChar(1, degree);
lcd.setCursor(0,0);
lcd.print(" Digital “);
lcd.setCursor(0,1);
lcd.print(” Thermometer “);
delay(4000);
lcd.clear();
lcd.print(” Circuit Digest ");
delay(4000);
lcd.clear();
}
void loop()
{
/---------Temperature-------/
float reading1=analogRead(sensor1);
float temperature1=reading1*(5.0/1023.0)*100;
delay(10);

/------Display Result------/
lcd.clear();
lcd.setCursor(2,0);
lcd.print(“Temperature”);
lcd.setCursor(4,1);
lcd.print(temperature1);
lcd.write(1);
lcd.print(“C”);

delay(1000);
}

But, when I applied it, the temperature just read 52C. The ambient temperature is actually 26C. If you don’t mind, please give me some solutions or advises to fix this problem.

Try this sketch to test your LM35 with serial monitor, no LCD.

/*
 LM35 thermometer, no floats, no delays

  http://www.ti.com/lit/gpn/lm35
*/


const byte sampleBin = 8, // number of samples for smoothing
           aInPin = A0;

const int calValue = 0; // adjust for calibration 

const int kAref = 1100, // analog ref voltage * 1000
                        // measured with accurate DMM
          kSampleBin = sampleBin * 1000,
          tEnd = 5000; // update time in mS
int tempC,
    tempF;
    
uint32_t total,  // sum of samples
         tStart; // timer start

void setup()
{
  Serial.begin(9600);
  analogReference(INTERNAL); // use 1.1V internal ref
  analogRead(aInPin);
  for(int i = 0;i < sampleBin;i++) // for smoothing, fill total
    total += analogRead(aInPin);   // with sampleBin * current
                                   // reading
}
void loop()
{
  if(millis() - tStart > tEnd)
  {
    tStart = millis(); // reset timer 
    total -= (total / sampleBin); // make room for new reading
    total += analogRead(aInPin); // add new reading
    tempC = total * kAref / kSampleBin + calValue;
    tempF = (tempC * 18 + 3200) / 10;
    Serial.print(analogRead(aInPin));
    Serial.print("\t");
    Serial.print(total); // sum of samples
    Serial.print("\t");
    prntTemp(tempC);
    prntTemp(tempF);
    Serial.println();
  }
}
    
void prntTemp(int temp){
  Serial.print(temp / 10); // whole degrees
  Serial.print(".");
  Serial.print(temp % 10); // tenths
  Serial.print("\t");
}

lm35_3.ino (1.41 KB)

Go back to the beginning.
You have three legs on the LM35, Vcc, GND, Vout.
Make sure you have them correct and any other bits like load resistors or caps if the datasheet calls for them.
Off the top of my head, I can't remember if the LM35 is a straight 10-mV per degree Celsius or not, but it is one of the easiest to implement. I seem to remember it needs a decoupling 0.1uF cap and a load resistor - it also needs extra precautions for long leads.
Connect a DVM to GND and Vout and see what you get with nothing else connected. If it is 10-mV/degree then you should see 300-mV thereabouts for 30-degrees.
Then check your code. Do a Serial.print of your raw analogue input and the value after scaling up etc.