/// <summary> /// The Beta model is a simple but not-so-accurate way of calculating a temperature from a thermistor's resistance. /// Steinhart-Hart is better, but Beta will have to do if we only know the Beta parameters for our thermistor. /// </summary> /// <param name="betaModelParameters"></param> /// <param name="resistanceOhms"></param> /// <returns></returns> public double ConvertResistanceToTemperatureCelciusUsingBetaModel(ThermistorBetaModelParameters betaModelParameters, double resistanceOhms) { // T = [(1 / β) ln(RT / RT0) + 1 / T0 ] ^ - 1 // From: https://www.thermistor.com/sites/default/files/specsheets/Beta-vs-Steinhart-Hart-Equations.pdf var celciusToKelvin = 273.15; var oneOverBeta = 1/betaModelParameters.BetaValue; var logResistanceOverReferenceResistance = Math.Log(resistanceOhms/betaModelParameters.ReferenceResistanceAt25DegC); var oneOverReferenceTemp = 1/(25 + celciusToKelvin); var resultKelvin = Math.Pow((oneOverBeta * logResistanceOverReferenceResistance) + oneOverReferenceTemp, -1); var resultCelcius = resultKelvin - celciusToKelvin; return resultCelcius; }
/// <summary> /// The Beta model is a simple but not-so-accurate way of calculating a temperature from a thermistor's resistance. /// Steinhart-Hart is better, but Beta will have to do if we only know the Beta parameters for our thermistor. /// </summary> /// <param name="betaModelParameters"></param> /// <param name="resistanceOhms"></param> /// <returns></returns> public double ConvertResistanceToTemperatureCelciusUsingBetaModel(ThermistorBetaModelParameters betaModelParameters, double resistanceOhms) { // T = [(1 / β) ln(RT / RT0) + 1 / T0 ] ^ - 1 // From: https://www.thermistor.com/sites/default/files/specsheets/Beta-vs-Steinhart-Hart-Equations.pdf var celciusToKelvin = 273.15; var oneOverBeta = 1 / betaModelParameters.BetaValue; var logResistanceOverReferenceResistance = Math.Log(resistanceOhms / betaModelParameters.ReferenceResistanceAt25DegC); var oneOverReferenceTemp = 1 / (25 + celciusToKelvin); var resultKelvin = Math.Pow((oneOverBeta * logResistanceOverReferenceResistance) + oneOverReferenceTemp, -1); var resultCelcius = resultKelvin - celciusToKelvin; return(resultCelcius); }
public void GivenBetaModelParameters_WhenIHaveAResistance_ThenICanCalculateTemperature() { // Arrange // Values for my thermistor, from http://www.surplustronics.co.nz/products/2140-ntc-thermistor-10k-ohms var betaModelParameters = new ThermistorBetaModelParameters { BetaValue = 4100, ReferenceResistanceAt25DegC = 10000 }; // Act/Assert _thermistorCalculator.ConvertResistanceToTemperatureCelciusUsingBetaModel( betaModelParameters, 10000).Should().BeApproximately(25, 0.01, "because that's the reference temperature"); _thermistorCalculator.ConvertResistanceToTemperatureCelciusUsingBetaModel( betaModelParameters, 1000).Should().BeApproximately(84.96, 0.01, "because that's the the value I get from the online calculator at http://www.thinksrs.com/downloads/programs/Therm%20Calc/NTCCalibrator/NTCcalculator.htm"); _thermistorCalculator.ConvertResistanceToTemperatureCelciusUsingBetaModel( betaModelParameters, 28000).Should().BeApproximately(4.23, 0.01, "because that's the the value I get from the online calculator at http://www.thinksrs.com/downloads/programs/Therm%20Calc/NTCCalibrator/NTCcalculator.htm"); }