Phoxtane

temperature function

Mar 24th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. float getTemp(int tempSensorPin){ // converts from ADC reading to temperature
  2.  
  3. // takes pin number, reads an analog value from it, and converts that to temperature in C
  4.  
  5. const int B = 3470; // all-important B value from thermistor datasheet
  6. const float T0 = 298.15; // 'room temperature' in Kelvin (25C)
  7.  
  8. int ADCvalue = analogRead(tempSensorPin); // get the value from the ADC
  9.  
  10. float tKelvin = (B*T0)/(T0*log((1024.0/ADCvalue)-1)+B); // computer-simplified version of B parameter equation for NTCs
  11. // thermistors are non-linear devices, so this corrects for that
  12. // we don't have a 1:1 correspondence between temperature and resistance
  13. float tCelsius = tKelvin - 273.15;
  14.  
  15. //Serial.println(tCelsius); // debug - shows current value of tCelsius
  16.  
  17. return tCelsius;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment