LM35 readings are erratic My son just did the Love-o-meter project in the Arduino Start Kit. However, the sensor readings of the LM35 temperature control vary widely. Below is a sample. What could be wrong?

Sensor Value: 217, Volts: 1.06, degrees C: 105.96
Sensor Value: 587, Volts: 2.87, degrees C: 286.62
Sensor Value: 125, Volts: 0.61, degrees C: 61.04
Sensor Value: 320, Volts: 1.56, degrees C: 156.25
Sensor Value: 445, Volts: 2.17, degrees C: 217.29
Sensor Value: 141, Volts: 0.69, degrees C: 68.85
Sensor Value: 510, Volts: 2.49, degrees C: 249.02
Sensor Value: 247, Volts: 1.21, degrees C: 120.61
Sensor Value: 168, Volts: 0.82, degrees C: 82.03
Sensor Value: 595, Volts: 2.91, degrees C: 290.53
Sensor Value: 125, Volts: 0.61, degrees C: 61.04
Sensor Value: 206, Volts: 1.01, degrees C: 100.59
Sensor Value: 606, Volts: 2.96, degrees C: 295.90
Sensor Value: 125, Volts: 0.61, degrees C: 61.04
Sensor Value: 290, Volts: 1.42, degrees C: 141.60
Sensor Value: 487, Volts: 2.38, degrees C: 237.79


Here's the code:

const int sensorPin = A0;
const float baselineTemp = 25.0;

void setup(){
  Serial.begin(9600); // open a serial port
  for(int pinNumber = 2; pinNumber&lt;5; pinNumber++){
    pinMode(pinNumber,OUTPUT);
    digitalWrite(pinNumber, LOW);
  }
}

void loop(){
  int sensorVal = analogRead(sensorPin);
  Serial.print("Sensor Value: ");
  Serial.print(sensorVal);
  // convert the ADC reading to voltage
  float voltage = (sensorVal/1024.0) * 5.0;
  Serial.print(", Volts: ");
  Serial.print(voltage);
  Serial.print(", degrees C: ");
  // convert the voltage to temperature in degrees
  float temperature = (voltage) * 100;
  Serial.println(temperature);

  if(temperature &lt; baselineTemp){
    digitalWrite(1, LOW);
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
  }else if(temperature &gt;= baselineTemp+2 &amp;&amp;
    temperature &lt; baselineTemp+4){
    digitalWrite(1, HIGH);
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
  }else if(temperature &gt;= baselineTemp+4 &amp;&amp;
    temperature &lt; baselineTemp+6){
    digitalWrite(1, HIGH);
    digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
  }else if(temperature &gt;= baselineTemp+6){
    digitalWrite(1, HIGH);
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
  }
  delay(1);
}


The GND is connected to the left most connector in the LM35, the A0 to the middle, and the power to the right most connector.
I've had a look round and spotted this:

https://electronics.stackexchange.com/questions/117970/why-is-my-analog-temp-sensors-signal-so-unstable

In summary it says that the fault maybe that the Arduino's 5V isn't stable enough, so you need to decouple it.  For once it seems that running from batteries may have been a better idea.

I've also seen posts saying there should be a 500Ohm resistor between the Ground of the LM35 and Ground.  Apparently it says 499Ohm on the datasheet.

And as a final resort I saw said that the 'Data Direction Register' influenced the analog pins.  If it was set to digital output this could lead to unstable readings for the ADC.  Basically it implied you needed to set the analog pin's to pinMode (A0, output). But I really don't think this will work