Jan-03-2021, 07:37 PM
I wrote a script to convert the measured resistance of the Betatherm thermistor 30K6A1 to temperature. I initially thought I had done something wrong, as it kept returning the wrong answer. The correct answer is 25 °C at 30000 ohms. My script returns 144.92 °C.
To help me fault find, I used the constant values from another thermistor of the series. It worked - I got the correct answer. I then tried the constant values for all other thermistor models in the series. All but one were spot-on correct. One, was about 0,5 °C out.
The constants, A, B and C, where taken from page 14 (it is numbered 19 in the document) of this PDF:
https://www-zeuthen.desy.de/~wischnew/pa...tailed.pdf
The correct resistance verses temperature table for the can be found at:
https://www.te.com/commerce/DocumentDeli...AT-NTC0007
I just cannot now work out what I have done wrong. The script is below, but please note that all the sets of data for the other thermistors are for test purposes and are not intended to be in the final script. Pulling data from lists and arrays is another lesson...
To help me fault find, I used the constant values from another thermistor of the series. It worked - I got the correct answer. I then tried the constant values for all other thermistor models in the series. All but one were spot-on correct. One, was about 0,5 °C out.
The constants, A, B and C, where taken from page 14 (it is numbered 19 in the document) of this PDF:
https://www-zeuthen.desy.de/~wischnew/pa...tailed.pdf
The correct resistance verses temperature table for the can be found at:
https://www.te.com/commerce/DocumentDeli...AT-NTC0007
I just cannot now work out what I have done wrong. The script is below, but please note that all the sets of data for the other thermistors are for test purposes and are not intended to be in the final script. Pulling data from lists and arrays is another lesson...
print("Resistance to temperature convertor for Betatherm 30K6A1* thermistor") print("====================================================================") print("") def main(): import math import datetime # 0.1K1A OK # a = 1.942952*10**-3 # b = 2.989769*10**-4 # c = 3.504383*10**-7 # 0.3K1A OK # a = 1.627660*10**-3 # b = 2.933316*10**-4 # c = 2.870016*10**-7 # 1K2A OK # a = 1.373168*10**-3 # b = 2.772261*10**-4 # c = 1.997412*10**-7 # 1K7A OK # a = 1.446059*10**-3 # b = 2.683626*10**-4 # c = 1.643561*10**-7 # 2K3A OK # a = 1.498872*10**-3 # b = 2.379047*10**-4 # c = 1.066953*10**-7 # 2.2K3A OK-ish - Gives 25.53 °C @ 2200 Ω # a = 1.471388*10**-3 # b = 2.376138*10**-4 # c = 1.051058*10**-7 # 3K3A OK # a = 1.405027*10**-3 # b = 2.369386*10**-4 # c = 1.012660*10**-7 # 5K3A OK # a = 1.287450*10**-3 # b = 2.357394*10**-4 # c = 9.505200*10**-8 # 10K3A OK # a = 1.129241*10**-3 # b = 2.341077*10**-4 # c = 8.775468*10**-8 # 10K4A OK # a = 1.028444*10**-3 # b = 2.392435*10**-4 # c = 1.562216*10**-7 # 30K5A OK # a = 9.331754*10**-4 # b = 2.213978*10**-4 # c = 1.263817*10**-7 # 30K6A NOK /!\ Gives 144.92 °C @ 30000 kΩ a = 1.068981*10**-4 b = 2.120700*10**-4 c = 9.019537*10**-8 # 50K6A OK # a = 9.657154*10**-4 # b = 2.106840*10**-4 # c = 8.585481*10**-8 # 100K6A OK # a = 8.271111*10**-4 # b = 2.088020*10**-4 # c = 8.059200*10**-8 # 1M9A OK # a = 7.402387*10**-4 # b = 1.760865*10**-4 # c = 6.865999*10**-8 x = datetime.datetime.now() print(x.strftime("%X %d/%m/%Y")) # Input measured resistance value while True: try: r = float(input("Enter the measured resistance value (Ω): ")) except ValueError: print("Must be a numeric value...") continue else: break # Calculate temperature # This calculator uses the Steinhart-Hart equation # Formual: 1/T = A + B(ln(R)) + C(ln(R))³ t = (1/(a + b*math.log(r) + c*math.log(r)**3))-273.15 t = round(t,2) print(f"Temperature = {t} °C") # print("Resistance at 25 °C should be 30 kΩ") print("") # Restart? yay or nay? restart = input("Do you want to convert another value? Y/N: ") print("") if restart.lower() == 'y': main() else: print("Goodbye") main()