wizztjh
wizztjh

Reputation: 7041

how to get Celsius as output from LM335Z with arduino?

the firstsensor is my lm335z output.

int firstSensor = 0; 
int secondSensor = 0;
int thirdSensor = 0;
int inByte = 0;   

void setup()
{
  Serial.begin(9600);
  establishContact();  // send a byte to establish contact until receiver responds 
}


void loop()
{
  if (Serial.available() > 0) {
    inByte = Serial.read();
    firstSensor = analogRead(0);
    delay(10);
    secondSensor = analogRead(1);
    thirdSensor = analogRead(2);
    Serial.print(firstSensor, DEC);
    Serial.print(",");
    Serial.print(secondSensor, DEC); 
    Serial.print(",");
    Serial.println(thirdSensor, DEC); 
  }
}

void establishContact() {

}

Upvotes: 2

Views: 1694

Answers (1)

gary
gary

Reputation: 4255

Based on its datasheet, the temperature output will vary at 10mV/K. But if you find a reference voltage at a known reference temperature, you can use this helpful equation from the datasheet:

V_out = V_ref * T_out/T_ref which is equivalent to T_out = T_ref * (V_out/V_ref)

So say your voltage is 2.982V at 25 degrees C or 298.15 degrees Kelvin (this is suggested in datasheet), then you can set your equation to:

T_out = (298.15 Kelvin)(V_out/2.982V)-273.15

So assuming you already can convert an analog reading into a voltage*, just plug in the measured voltage and this should give you your temp in degrees C.

*The Arduino has a built-in 10-bit ADC and the maximum voltage it can read is 5v. Therefore, you can factor in 5v/1024 ADC steps = 0.00488V per ADC step. (i.e. V_out = firstSensor*0.00488). So plugging in for V_out, the equation becomes:

T_out = (298.15)(firstSensor*0.001637)-273.15 where 0.001637 = 0.00488/2.982.

Upvotes: 6

Related Questions