I am using the Lilypad Temperature sensor with the Lilypad Arduino w/ATmega328.
At this point I am having difficulties getting a consistent reading of the ambient temp. It jumps from as low as 15 degrees Celsius to 25 degrees Celsius. The actual temp should be 24 degrees Celsius.
My code is below. Any help would be really appreciated!
There is a math error in voltage = reading * (3300 / 1024); 3300/1024 = allways 3
so this line just states voltage = reading * 3;
to make it float voltage = reading * 3300.0 / 1024; // note the .0 to force float!
==> code below
The actual temp should be 24 degrees Celsius.
So 25 degrees is an acceptable measurement, but 15 is not. As the math does not fluctuate It could be a loose contact; Or maybe you need to do an averaging of the temperature. I added a RAW reading print in the code below.
Can you post e.g. 20-50 readings?
int tempSenPin = 0;
void setup()
{
Serial.begin(9600);
Serial.prinln("start"); // for debugging only to see it works.
}
void loop()
{
int reading = analogRead(tempSenPin);
Serial.print("RAW: "); Serial.println(reading);
float voltage = reading * 3300.0 / 1024;
float tempC = (voltage - 500)/10;
Serial.print(tempC); Serial.println(" degrees C");
delay(1000);
}