That measures the LM35 against the potentially unstable default Aref.
And default Aref (5volt) of a Nano on USB power is only ~4.6volt.
The solution is to measure the LM35 with the internal 1.1volt Aref.
This example sketch also uses averaging.
Change your code to this once you onderstand it.
Leo..
// LM35 temp sensor connected A0
unsigned int total; // A/D readings
float tempC; // Celcius
float tempF; // Fahrenheit
void setup() {
analogReference(INTERNAL); // use the internal ~1.1volt reference | change to (INTERNAL1V1) for a Mega
Serial.begin(9600);
}
void loop() {
// read the sensor
for (int x = 0; x < 64; x++) { // 64(max) analogue readings for averaging
total = total + analogRead(A0); // add each value
}
// temp conversion
tempC = total * 0.001632; // Calibrate by slightly changing 0.0016xx
tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit
Serial.print("The temperature is ");
Serial.print(tempC, 1); // one decimal place
Serial.print(" Celcius ");
Serial.print(tempF, 0); // no decimal places
Serial.println(" Fahrenheit");
total = 0; // reset total
delay(1000); // slows readings
}
Hmn, further investigation is showing that sensor is still prone to give erratic readings once I connect the I2C 128x64 OLED screen.
Anyone else has come across sensor and I2C device interference?