lm35 spark read incorrect temperature

I found that code from instructables and tried use in a spark core. I received incorrect values.

 temperatura = analogRead(A0);
 val = analogRead(tempPin);
  float mv = ( val/1024.0)*5000; 
  float cel = mv/10;

So I change the code to following, but receive incorrect values. My question is what is the correct values to read the temperature in cº

temperatura = analogRead(A0);
 float mv = ( temperatura/4095.0)*3300; 
  float cel = mv/10;
  float farh = (cel*9)/5 + 32;

How have you powered the sensor?

3V3 -> GND or 5V -> GND


Are you sure you’re using a 3V3 sensor?

Since the standard LM35 requires a minimum if 4V supply

I tried with 5v but receive the incorrect values too

If you’re using 5V you have to make sure your temp never causes any voltage reading above 3V3, to prevent damaging the ADC.

But there are several threads on this forum dealing with this sensor - have a search :wink:
In some of them some hardware components are suggested.

A side note too.
When mixing integer and float variables also make sure your number literals don’t interfere.
I usually also tend to multiplying before dividing - despite compilers/optimizers are quite clever nowadays :wink:

float mv = temperatura * 3300.0 / 4095.0; 
float cel = mv / 10.0;