Thermistor help need
#1
Posted 19 May 2012 - 05:42 PM
#2
Posted 19 May 2012 - 06:49 PM
Mike,Hello,
I have a NTC thermistor R(25C):10kΩ - Β(25C/50C):3950.
I am trying to convert the readings of Analog0 into temperature.
If I use AnalogInput.Read I get values from 0.0 to 1.0
If I use AnalogInput.ReadRaw I get values from 1 to 3000
I connected the thermistor using voltage divider like :
GRD --- Resistor 10KΩ --- Thermistor --- 5V
...................................|
...................................|
..........................NetGo Analog 0
Please help,
Thanks.
First off I would recommend that you connect the components:
5vdc
|
10kΩ Resistor
|
—> A0 Netduino Shield Base
|
Thermistor
|
Ground
From the data sheet -40° C. = 277.2 kΩ and 200° C. = 61.9 Ω at 25° C. = 10kΩ.
Since the thermistor's resistance is not linear you will need to do some math to find the temperature for a given resistance. See the attached link you should be able to change the code to either C# or visual basic, which ever you prefer.
Thermistor Tutorial
It looks like the minimum temperature that you can read using the 10kΩ resistor will be about 10° C. or 50° F., any lower and the thermistor voltage drop will be > 3.3 volts. I think the the Shield base AIOs are tolerant of 5vdv. but I don't like to test them.
Also the shield base ADC is 12 bit resolution so intead of using 1023 you will need to use 4095 instead (this is if you use .ReadRaw) if you use .Read instead it is 0.0 to 1.0. I did not check but watch for divide by zero errors in the formulas.
That should get you started,
Chuck
#3
Posted 19 May 2012 - 11:37 PM
I didn't have a thermistor to test it, but did makeup a bread board with 1/4 watt resistor and it seems to work okay. I tried about 6 different resistors total.
Accuracy seems to fall off in the Stienhart formula at lower temperature. It may still be good enough depending on the acccuracy that you are looking for and the range that you want to monitor.
Still think you will do best with a TMP35, 36 or 37 depending on the range you want, plus with a linear output (I think its 10 mv / °C. for the TMP36) you can scale, span or calbrate the output.
Look at the data sheet for the TMP36 also it gives some circuits for Longer distance connections and also a current loop connection.
Imports Microsoft.SPOT Imports Microsoft.SPOT.Hardware Imports SecretLabs.NETMF.Hardware Imports SecretLabs.NETMF.Hardware.NetduinoGo Imports NetduinoGo Imports System.Math Module Module1 Dim SB As ShieldBase Dim TempSensor As AnalogInput Sub Main() SB = New ShieldBase(GoSockets.Socket2) ' Plug into Socket 2 or change to suit TempSensor = New AnalogInput(SB.AnalogChannels.ANALOG_0) ' 10K Precision Epoxy Thermistor - 3950 NTC While True Debug.Print("Output of .ReadRaw = " + TempSensor.ReadRaw.ToString("n0")) Debug.Print("Average Resistance = " + GetAverageResistance.ToString("n2")) Debug.Print("Temperature in ° Centigrade = " + Steinhart(GetAverageResistance).ToString("n1")) Debug.Print("") Thread.Sleep(5000) End While End Sub Function GetResistance() As Double Dim Reading As Double = TempSensor.ReadRaw If Reading >= 4095 Then ' prevents a divide by zero error, also you are feeding greater than 3.3 vdc into the analog input Reading = 4090 End If Dim Resistance As Double = 10000.0 / ((4095.0 / Reading) - 1) ' R = 10K / (4095/ADC - 1) Return Resistance End Function ' The function GetAverageTemperature takes 10 samples and averages them. ' May not be necessary with Netduino Go, the AIO seems to be very stable. Function GetAverageResistance() As Double Dim TotalResistance As Double = 0.0 Dim AverageResistance As Double = 0.0 For i = 0 To 9 Step 1 TotalResistance += GetResistance() Thread.Sleep(50) Next AverageResistance = TotalResistance / 10 Return AverageResistance End Function Function Steinhart(InputReading As Double) As Double Dim TempReading As Double = InputReading TempReading = InputReading / 10000.0 '(Thermistor Resistance / Resistance at 25° C.) TempReading = Log(TempReading) ' ln(R/Ro) TempReading /= 3950 ' 1/B * ln(R/Ro) TempReading += 1.0 / (25.0 + 273.15) ' + (1/To) in ° Kelvin TempReading = 1.0 / TempReading ' Invert TempReading -= 273.15 ' Convert from Kelvin to Centigrade Return TempReading End Function End ModuleYou may owe me 2 beers.
Have fun with it,
Chuck
#4
Posted 20 May 2012 - 04:24 AM
#5
Posted 20 May 2012 - 03:38 PM
This Steinhart function is a little closer to the data table, it is real close at normal temperatures. I also add a debug.print for Farenheit, Celsius was cooking my brain.
Imports Microsoft.SPOT Imports Microsoft.SPOT.Hardware Imports SecretLabs.NETMF.Hardware Imports SecretLabs.NETMF.Hardware.NetduinoGo Imports NetduinoGo Imports System.Math Module Module1 Dim SB As ShieldBase Dim TempSensor As AnalogInput Sub Main() SB = New ShieldBase(GoSockets.Socket2) ' Plug into Socket 2 or change to suit TempSensor = New AnalogInput(SB.AnalogChannels.ANALOG_0) ' 10K Precision Epoxy Thermistor - 3950 NTC Dim CTemp As Double = 0 Dim FTemp As Double = 0 While True CTemp = Steinhart(GetAverageResistance) FTemp = (CTemp * 9) / 5 + 32 Debug.Print("Output of .ReadRaw = " + TempSensor.ReadRaw.ToString("n0")) Debug.Print("Average Resistance = " + GetAverageResistance.ToString("n2")) Debug.Print("Temperature in ° Centigrade = " + CTemp.ToString("n1")) Debug.Print("Temperature in ° Farenheit = " + FTemp.ToString("n1")) Debug.Print("") Thread.Sleep(5000) End While End Sub Function GetResistance() As Double Dim Reading As Double = TempSensor.ReadRaw If Reading >= 4095 Then ' prevents a divide by zero error, also you are feeding greater than 3.3 vdc into the analog input Reading = 4090 End If Dim Resistance As Double = 10000.0 / ((4095.0 / Reading) - 1) ' R = 10K / (4095/ADC - 1) Return Resistance End Function ' The function GetAverageTemperature takes 10 samples and averages them. ' May not be necessary with Netduino Go, the AIO seems to be very stable. Function GetAverageResistance() As Double Dim TotalResistance As Double = 0.0 Dim AverageResistance As Double = 0.0 For i = 0 To 9 Step 1 TotalResistance += GetResistance() Thread.Sleep(50) Next AverageResistance = TotalResistance / 10 Return AverageResistance End Function Private Function Steinhart(InputReading As Double) As Double Dim Vref As Double = 5 Dim ThermRefResistance As Double = 10000 Dim ThermResistance As Double = InputReading Dim a As Double = 3.354016 * Pow(10, -3) Dim b As Double = 2.56985 * Pow(10, -4) Dim c As Double = 2.620131 * Pow(10, -6) Dim d As Double = 6.383091 * Pow(10, -8) 'Convert resistance to temperature in degrees C (Steinhart equation) Dim Celcius As Double = 1 / (a + b * Log(ThermResistance / ThermRefResistance) + c * Pow(Log(ThermResistance / ThermRefResistance), 2) + d * Pow(Log(ThermResistance / ThermRefResistance), 3)) - 273.15 Return Celcius End Function End Module
#6
Posted 29 May 2012 - 03:21 AM
http://diybrewery.com
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users