输入温度时计算电压

时间:2018-03-12 05:31:16

标签: python

import math
#// resistance at 25 degrees C
THERMISTORNOMINAL = 10000
#// temp. for nominal resistance (almost always 
25 C)
TEMPERATURENOMINAL = 25
#// The beta coefficient of the thermistor (usually 3000-4000)
BCOEFFICIENT = 3950
#// the value of the 'other' resistor
SERIESRESISTOR = 10000

def calculate_temp(voltage):

    voltage = voltage / 1000
    # convert the value to resistance
    average = (SERIESRESISTOR / voltage) -  SERIESRESISTOR

    steinhart = average / THERMISTORNOMINAL            #// (R/Ro)
    steinhart = math.log(steinhart)                    #// ln (R/Ro)
    steinhart /= BCOEFFICIENT                          #// 1/B * ln(R/Ro)
    steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15)   #// + (1/To)
    steinhart = 1.0 / steinhart                        #//     Invert
    steinhart -= 273.15                                #// convert to C

    # print("Temperature:", steinhart, "C");
    return round(steinhart, 2)

以上是将电压转换为温度的代码。如何将温度转换为电压?

0 个答案:

没有答案