Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float getTemp(int tempSensorPin){ // converts from ADC reading to temperature
- // takes pin number, reads an analog value from it, and converts that to temperature in C
- const int B = 3470; // all-important B value from thermistor datasheet
- const float T0 = 298.15; // 'room temperature' in Kelvin (25C)
- int ADCvalue = analogRead(tempSensorPin); // get the value from the ADC
- float tKelvin = (B*T0)/(T0*log((1024.0/ADCvalue)-1)+B); // computer-simplified version of B parameter equation for NTCs
- // thermistors are non-linear devices, so this corrects for that
- // we don't have a 1:1 correspondence between temperature and resistance
- float tCelsius = tKelvin - 273.15;
- //Serial.println(tCelsius); // debug - shows current value of tCelsius
- return tCelsius;
- }
Advertisement
Add Comment
Please, Sign In to add comment