LM35 Temperature Sensor

Hi guys,
I'm new in things like arduino and i've got problems how to convert informations from sensor into temperature

const int czujnikTemperatury =A0;

void setup() {
  Serial.begin(9600);

}

void loop() {
  int odczyt = analogRead(czujnikTemperatury);
  float napiecie = (odczyt/1024.0)*5.0;
  float temperatura = (napiecie - 0.5) *100;
  Serial.print("odczytana wartosc: ");
  Serial.print(odczyt);

  Serial.print("| napiecie: ");
  Serial.print(napiecie);
  
  Serial.print("| temperatura: ");
  Serial.print(temperatura);


  Serial.println();

}

I found code in the internet but i don't know how it exactly works i mean the part with dividing by 1024 and other math actions. And temeprature is way too high when using it.

Thanks for help and please use simple english :slight_smile:

The output of the LM35 is 0.010V per °C. That's 1/100th of a volt per degree.

Calculate the voltage: (Analog reading / 1024.0) * aRef (default aRef is 5.0V)
Multiply voltage by 100 to get temperature.

Your sketch is subtracting 0.5V before multiplying by 100 so I would expect it to read 50°C too low.

If you are running on a 3.3V power supply the aRef should be 3.3 and using 5.0 would cause it to read high.

See also: Arduino Playground - LM35HigherResolution

When i multiply by 10 instead of 100 it shows the right temperature.

Calculate the voltage: (Analog reading / 1024.0) * aRef (default aRef is 5.0V)
Multiply voltage by 100 to get temperature.

Where did you get it? Should i remember it for another analog sensors?

Heads up,

I'm not sure why this happens, but if you are running other hardware on the arduino, it will cause the readings to go crazy. I tested this a little and found out that if you read the analog output voltage of the voltage going into a led, it will say 5, which it should be, but if you hook the analog pin to the ground pin of the led, and disconnect the actual ground, you will see the analog reading vary as other devices are powered. Pretty sure that's the reason the temp sensor goes crazy when other devices are used. I think it has something to do with current or amps supplied/used by the other devices but i'm not sure.

The only way I was able to get the temp sensor to work without any interference from powering other devices at the same time was to use a temp sensor that had its own independent power source.

Hope this helps, it was very frustrating for me to figure out.
Thomas

I've got some leds connected to digital inputs and that's all, when i multiply by 10 it show pretty good temp. Should sensor be very, very hot when it's working? can't even touch it?

Should sensor be very, very hot when it's working? can't even touch it?

disconnect it right now! You probably have the power and ground reversed. It will fry the sensor

Yeah i plugged it off. Any idea how can i check if it's a problem with temperature sensor?

The sensor outputs 10mV/degC, so you have to read 0.25V with a voltmeter at its output at room temperature (provided you room temperature is 25degC). Read the LM35 datasheet..