Python Forum
Problem with one set of data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with one set of data
#1
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...

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()
Reply
#2
Look at column A. Every value there is basically right around 10^-3... except for this one, which is 10 times lower. *sniff*... *sniff*.... smells like a typo.

Try A = 1.068981*10**-3
Reply
#3
Thanks for looking through it, but if you look closer, you'll notice that from 30K5A onwards, the powers are **-4, **-4 and **-8. I even tried with C being to **-7, but it does not work either.
Reply
#4
(Jan-04-2021, 02:52 AM)alloydog Wrote: Thanks for looking through it, but if you look closer, you'll notice that from 30K5A onwards, the powers are **-4, **-4 and **-8.

Yes, but those are 9x10^-4 and 8x10^-4, which are very close to 1x10^-3. They're not 1x10^-4.

Anyway, that change works for me...

...
    a = 1.068981*10**-3
    b = 2.120700*10**-4
    c = 9.019537*10**-8
...
Output:
Resistance to temperature convertor for Betatherm 30K6A1* thermistor ==================================================================== 19:37:22 03/01/2021 Enter the measured resistance value (Ω): 30000 Temperature = 25.0 °C Do you want to convert another value? Y/N:
Reply
#5
I don't know what happened, I tried it first thing this morning (like at half-past four!) and got a wrong answer. Now I retried it and it works! Thank you good sir! Maybe someone needs to tell the people who wrote the document that they have made an error...

Anyway, case closed! Thumbs Up
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Looking for data/info on a perticular data-proccesing problem. MvGulik 9 3,850 May-01-2021, 07:43 AM
Last Post: MvGulik
  Problem with serial data. How do I ignor incorrect data? donmerch 1 2,923 Jul-11-2017, 01:55 AM
Last Post: donmerch

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020