Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Playground Wiki / Re: First posts on: November 29, 2010, 12:59:20 am
Yup, you guessed it.  My first post here.  8-)

drubdrub
2  Forum 2005-2010 (read only) / Interfacing / Re: LM335 temp sensor:  Calculate value in C on: November 30, 2010, 02:56:49 am
Just can't put this to rest without a better understanding.

The calculations have been broken out into separate, discreet steps.  It helps my simple mind get a grasp.  The relevant code section is included.

Code:
float sensor = 0.0;
float volt = 0.0;
float milivolt = 0.0;
float f = 0.0;
float c = 0.0;
char debug = 'F';      // 'T' or 'F'

// ------------------
    void loop() {
// ------------------

  // Take sample_count temperature readings.  Will calc the average.
  for (i = 1; i <= sample_count; i++) {

    sensor = analogRead(INPUT_PIN);
    volt = (VCC * sensor) / 1024.0;
    milivolt = volt * 100;
    c = milivolt - 273.15;
    f = (c * 9/5) + 32;

I'll spare you all the code for the debug output, but the output on the serial console also aided understanding.  Finally got an "ah hah" moment.

Code:
-- sensor : 593.00    volt: 2.90    milivolt: 289.55    C: 16.40    F: 61.52
-- sensor : 594.00    volt: 2.90    milivolt: 290.04    C: 16.89    F: 62.40
-- sensor : 593.00    volt: 2.90    milivolt: 289.55    C: 16.40    F: 61.52
-- sensor : 593.00    volt: 2.90    milivolt: 289.55    C: 16.40    F: 61.52
-- sensor : 593.00    volt: 2.90    milivolt: 289.55    C: 16.40    F: 61.52
-- sensor : 593.00    volt: 2.90    milivolt: 289.55    C: 16.40    F: 61.52
-- sensor : 593.00    volt: 2.90    milivolt: 289.55    C: 16.40    F: 61.52
-- sensor : 593.00    volt: 2.90    milivolt: 289.55    C: 16.40    F: 61.52
Temp: 61.63 F
-- min: 56   max: 70

I look forward to corrections, comments, suggestions, insight, and wisdom.  Oh, and world peace.   smiley-wink

I hope this is helpful to someone on a similar quest.
Cheers!
3  Forum 2005-2010 (read only) / Interfacing / Re: LM335 temp sensor:  Calculate value in C on: November 30, 2010, 01:45:40 am
Hey Richard.  Agreed.

temp = (VOLTAGE * analogRead(INPUT_PIN) / 1024.0 * 100.0 - 273.15

Adding parens and simplifying should result in:
temp = ((VOLTAGE * analogRead(INPUT_PIN) / 1024.0) * 100.0) - 273.15
temp = (VOLTAGE * analogRead(INPUT_PIN) * 100 / 1024.0) - 273.15
temp = (VOLTAGE * analogRead(INPUT_PIN) / 10.24) - 273.15

True?

BTW, just discovered another post on this topic.  See:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1285091539
4  Forum 2005-2010 (read only) / Interfacing / LM335 temp sensor:  Calculate value in C on: November 29, 2010, 01:40:36 am
Wow!  Arduino is fabulous!!  I've been wanting this kind of environment for years.  Great fun.  Great platform.  Huge thanks!!!

First project: Read LM335, display temp, max temp, min temp.
Status:  With the help of other posted projects, got it working.  Nice.

Background:  I am not clear about the temperature calculation in an example.  It appears to produce valid readings, but I want to understand the general case so the experience can be applied to my subsequent projects.

Formula:  temp = (VOLTAGE * analogRead(INPUT_PIN) / 1024.0 * 100.0 - 273.15

VOLTAGE = 5.0,  Vcc for the Arduino board
INPUT_PIN = 0, the Arduino pin attached to the LM335 ADJ pin
temp is a value in Celsius

I don't understand the formula and don't find very good explanations.  I've read the LM335 datasheet, and searched the web for quality references and coaching

Questions:
  • Why subtract 273.15?  C = Kelvin - 373, right?  Why not subtract 373?
  • Why divide by 1024.0?
  • Why the 100 term?
I believe this math is necessary because the analog read feature of the Atmega328 (Duemilinove) which converts the analog voltage reading to one of 1024 values.  True?

Has the formula been simplified, so some of the factors are obscured?  Would be nice to have the entire formula, for clarity.

Derive a Celsius value from the LM335 voltage: C = (V / 0.10) - 373
  • V is the LM335 voltage.  It is produced in 10 mv steps.
  • 0 V = 0 degrees Kelvin

Appreciate the assistance!  Many thanks!!
Pages: [1]