Created
September 12, 2017 11:04
-
-
Save tomeaton17/e5bbc236628e75243b15569e7322f2eb to your computer and use it in GitHub Desktop.
Calculates the Steinhart-Hart coefficients given 3 known resistance temperature pairs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Calculates the Steinhart-Hart coefficients for given resistance and temperature pairs. | |
""" | |
import sys | |
import math | |
titleString = """\ | |
______ _ __ __ __ __ __ _____ _______ _ __ | |
/ __/ /____ (_)__ / / ___ _____/ /_____/ // /__ _____/ /_ / ___/__ ___ / _/ _(_)___(_)__ ___ / /____ | |
_\ \/ __/ -_) / _ \/ _ \/ _ `/ __/ __/___/ _ / _ `/ __/ __/ / /__/ _ \/ -_) _/ _/ / __/ / -_) _ \/ __(_-< | |
/___/\__/\__/_/_//_/_//_/\_,_/_/ \__/ /_//_/\_,_/_/ \__/ \___/\___/\__/_//_//_/\__/_/\__/_//_/\__/___/ | |
""" | |
print(titleString) | |
t1 = float(input("Enter temperature of thermistor in Kelvins at first reading: ")) | |
r1 = float(input("Enter resistance of thermistor in Ohms at this temperature: ")) | |
t2 = float(input("Enter temperature of thermistor in Kelvins at second reading: ")) | |
r2 = float(input("Enter resistance of thermistor in Ohms at this temperature: ")) | |
t3 = float(input("Enter temperature of thermistor in Kelvins at third reading: ")) | |
r3 = float(input("Enter resistance of thermistor in Ohms at this temperature: ")) | |
if(abs(t3 - t2) < 10 or abs(t3 - t1) < 10 or abs(t2 - t1) < 10): | |
print("Readings are not far enough apart (< 10 degrees). Equation may be inaccurate due to this.") | |
valid = False | |
while (valid == False): | |
confirmation = input("Would you like to continue? Enter \'y\' to continue or \'n\' to exit: ") | |
if(confirmation == 'y'): | |
valid = True | |
break | |
elif(confirmation == 'n'): | |
valid = True | |
sys.exit() | |
else: | |
valid = False | |
l1 = math.log(r1) | |
l2 = math.log(r2) | |
l3 = math.log(r3) | |
y1 = 1.0/t1 | |
y2 = 1.0/t2 | |
y3 = 1.0/t3 | |
x2 = (y2 - y1)/(l2 - l1) | |
x3 = (y3 - y1)/(l3 - l1) | |
c = ((x3-x2)/(l3-l2))/(l1+l2+l3) | |
b = x2 - c*((l1**2) + (l1*l2) + (l2**2)) | |
a = y1 - (b + ((l1**2)*c))*l1 | |
print("A: ", a) | |
print("B: ", b) | |
print("C: ", c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment