LM35CZ reading or calculation errors

Heya all,

Ive got an Arduion Uno and I've hooked up a LM35CZ +5, GRD, and Analog1.

Below is the code I'm using to produce a Celsius printout to the serial monitor

int sensorPin = A1;

void setup()
{
  Serial.begin(9600);  
                       
}
 
void loop()                     
{
 
 int reading = analogRead(sensorPin);  
 float voltage = (reading * 5) / 1024.0; //voltage calculation
 float temperatureC = (voltage-0.5) * 100 ;  // temp calculation (-500mV for offset)
 
 Serial.print(voltage); Serial.println(" Volts ");
 Serial.print(temperatureC); Serial.println(" degress C");
 Serial.println();
 
 delay(1000);   
}

This is the serial output

3.07 Volts 
256.64 degrees C

3.07 Volts 
256.64 degrees C

3.07 Volts 
256.64 degrees C

Also if i put my finger on the sensor to warm it the voltage drops and the temp decreases and the opposite for cold
???

Im rather new to the Arduion and am probably missing something simple, but any guidance would be appreciated

Can you post a diagram or describe how you have the LM35 connected? Your results are consistent with seeing a 3V reading from the LM35 but you should not be seeing such a high value.

My best guess is that you have it connected incorrectly. With the flat side facing you the pins should be: +5, output, Gnd

I also could not find the part of the datasheet that mentions the offset voltage. The diagrams and tables seem to show that the reading only goes down to 0 unless you provide a negative current of 50 microamps to the output. Then the voltage can go to -550 millivolts but the Arduino can't read negative voltages.

thanks for the response,

@john, ive just had a look at the datasheet and your right about the offset. I was working off altered code and didn't double check.

ive attached a picture showing how i have the lm35 setup with my Arduino. As far as i am aware its connected correctly?? I just dont understand the high voltage output?

Those look like the right connections so the only other possibility is the your chip is fried.

I recommend the Maxim (formerly Dallas Semiconductor) DS18B20 thermometer chip. You can hook as many as you want to a single pin and use the OneWire library to talk to them. They give direct binary temperature from -55 to +125 in 16ths of a degree.