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<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 < baselineTemp){
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
}else if(temperature >= baselineTemp+2 &&
temperature < baselineTemp+4){
digitalWrite(1, HIGH);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
}else if(temperature >= baselineTemp+4 &&
temperature < baselineTemp+6){
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
}else if(temperature >= 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.