# Lilypad Temperature Sensor. Help

Hi,

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!

``````//analog input 0/digital 14
int tempSenPin = 0;

void setup()
{
Serial.begin(9600);
pinMode(tempSenPin, INPUT);
}

void loop()
{

float voltage = reading * (3300 / 1024);

float tempC = (voltage - 500)/10;

Serial.print(tempC); Serial.println(" degrees C");

delay(1000);
}
``````

Analogpins don't need a pinMode to be set,

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()
{

float voltage = reading * 3300.0 / 1024;
float tempC = (voltage - 500)/10;

Serial.print(tempC); Serial.println(" degrees C");
delay(1000);
}
``````

There is also some code on - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1262208606 - it uses different math.

How is this wired up? The conductive thread used for the lilypad is not electrically ideal BTW, it might be the problem.

Thanks so much,

My temp sensor is returning much more consistent and accurate readings now using the code changes you suggested.

It may also be that I am now in an airconditioned office where the temperature is regulated.

Now to write some code to do something with my temp inputs : )

Now to write some code to do something with my temp inputs : )

• red led is the temperature is hot, blue if too cold, green = perfect
• monitor max and min value during a day (optional with timestramp)
etc