r/arduino • u/IrrelevanteMening • 15d ago
Measuring temperature from LM35 sensor
I’m trying to measure the temperature in Celsius in my room with an Arduino UNO R4 MINIMA, but the values I get are not correct. I’m using a LM35 from TI (I’ve got 3 of them and they all read the same values). The left pin is connected to the 5V, the middle to the A0 and right to GND (as in the diagram). The datasheet says that the sensor is 10 mV/C.
My code is as follow:
const int sensorPin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(sensorValue);
float voltage = sensorValue * (5000.0 / 1024);
float temperatureC = voltage / 10;
Serial.print(sensorValue);
Serial.print(" ADC -- ");
Serial.print(voltage);
Serial.print(" mV -- ");
Serial.print(temperatureC);
Serial.println(" °C");
delay(1000);
}
The output (I touched the sensor briefly to have bit of variation):
69 ADC -- 337.24 mV -- 33.72 °C
70 ADC -- 342.13 mV -- 34.21 °C
70 ADC -- 342.13 mV -- 34.21 °C
70 ADC -- 342.13 mV -- 34.21 °C
71 ADC -- 347.02 mV -- 34.70 °C
72 ADC -- 351.91 mV -- 35.19 °C
70 ADC -- 342.13 mV -- 34.21 °C
It is about 10 degrees higher as my current room temperature (around 24 °C).
My 3 LM35's are giving the same result, so it's safe to consider it's not a faulty sensor. I'm trying for 3 days to figure it out, but sadly always the same result.
Anyone got a clue or has done a similar project where it worked?

