Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Thermistor help need


  • Please log in to reply
5 replies to this topic

#1 PhillipMorris

PhillipMorris

    Member

  • Members
  • PipPip
  • 17 posts
  • LocationSerres, HELLAS

Posted 19 May 2012 - 05:42 PM

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.

#2 carb

carb

    Advanced Member

  • Members
  • PipPipPip
  • 352 posts
  • LocationCrystal River, Florida

Posted 19 May 2012 - 06:49 PM

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.

Mike,

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 carb

carb

    Advanced Member

  • Members
  • PipPipPip
  • 352 posts
  • LocationCrystal River, Florida

Posted 19 May 2012 - 11:37 PM

Mike,

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 Module
You may owe me 2 beers. :D

Have fun with it,
Chuck

#4 PhillipMorris

PhillipMorris

    Member

  • Members
  • PipPip
  • 17 posts
  • LocationSerres, HELLAS

Posted 20 May 2012 - 04:24 AM

Thanks for your support Chuck. The code works fine. Finally. I get readings +/-1 C but I am very satisfied so far. The other thing that I noticed is that the thermistor is not very responsive. When the temperature is dropping rapidly, I gets 1 minute to return to normal. I will get a TMP36 but I cant find waterproof version (or steel head) over the internet. I dont have a display but I will order one from here : http://shop.microfra...ctOut.aspx/8656 Now, I owe you 3 beers.

#5 carb

carb

    Advanced Member

  • Members
  • PipPipPip
  • 352 posts
  • LocationCrystal River, Florida

Posted 20 May 2012 - 03:38 PM

Mike,

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. :blink:

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 Coding Smackdown

Coding Smackdown

    Advanced Member

  • Members
  • PipPipPip
  • 78 posts
  • LocationLewisville, TX USA

Posted 29 May 2012 - 03:21 AM

I've been working on an Electric Brew System Controller that I used to replace the controller in a Cajun Injector Electric Turkey Fryer. I've been using a TMP36 sensor along with the built in thermistor that is built into the heating element. I water proofed the TMP36 sensor by using a 1 foot length of 1/4 OD copper tubing and a 1/4 copper cap. I used Marine Epoxy on both ends to help keep the water out. I really did not notice that big of a lag in the thermistor compared to the TMP36 sensor. They both seemed to be pretty accurate side by side once I figured out the proper coefficients for the Stein-Hart Calculations. I also found a simpler version of the Stein-Hart Calculation over at http://thermistor.sourceforge.net/ that might cut down on the CPU a bit. There is also a nice little program that will calculate the coefficients based on a series of resistance and temperature measurements in case you can't find a part number or coefficients for a thermistor you might be using. I know it helped me out quite a bit since the manufacturer does provide enough detail about the parts used to put together their unit. If you are interested in the source for the controller you can find the source at https://github.com/l...TempController. Currently it is for a Netduino Plus, but I'll more than likely be converting it over to a Gadgeteer device soon, since things are getting pretty cramped.
Brewing Award Winning Beer with a Netduino!
http://diybrewery.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.