Pages: [1]   Go Down
 Author Topic: Lilypad Temperature Sensor. Help  (Read 337 times) 0 Members and 1 Guest are viewing this topic.
Offline
Newbie
Karma: 0
Posts: 5
 « on: March 28, 2011, 01:48:18 am » Bigger Smaller Reset

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!

Code:
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);
}
 Logged

Netherlands
Offline
Tesla Member
Karma: 90
Posts: 9393
In theory there is no difference between theory and practice, however in practice there are many...
 « Reply #1 on: March 28, 2011, 06:52:54 am » Bigger Smaller Reset

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

Quote
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?

Code:
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.
 Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

0
Offline
Tesla Member
Karma: 71
Posts: 6611
Arduino rocks
 « Reply #2 on: March 28, 2011, 02:01:44 pm » Bigger Smaller Reset

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

Offline
Newbie
Karma: 0
Posts: 5
 « Reply #3 on: March 28, 2011, 11:34:31 pm » Bigger Smaller Reset

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 : )
 Logged

Netherlands
Offline
Tesla Member
Karma: 90
Posts: 9393
In theory there is no difference between theory and practice, however in practice there are many...
 « Reply #4 on: March 29, 2011, 05:53:35 am » Bigger Smaller Reset

Quote
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

 Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

 Pages: [1]   Go Up