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;
i开发者_运维知识库nt 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() {
}
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.
精彩评论