Example Code

Measure Temperature using 10kΩ Thermistor, myDAQ, and LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Hardware

  • myDAQ Student Data Acquisition Device

Code and Documents

Attachment

Download All

Description

Overview


This document explains using a low-cost thermistor to measure temperature with your National Instruments myDAQ in LabVIEW. The data will be acquired using the DAQ Assistant that is installed into LabVIEW with the NI DAQmx driver and converted to a temperature using basic programming in LabVIEW.

Objective: 

Use a Vishay 10kΩ Thermistor to take a basic temperature measurement with the myDAQ DMM terminal and LabVIEW.

 

Background:

The Vishay NTCLE-100E-3103 10kΩ is a low-cost, high accuracy, resistive temperature measurement sensor that can be used in a wide range of temperature sensing environments and applications.  A constant, known current is applied across the thermistor and the voltage drop across the thermistor is recorded.  By using Ohm's Law, this voltage and current can be used to determine the resistance of the thermistor, which varies with temperature.  This resistance is then used to calculate temperature using the polynomial equation listed in the sensors specifications document.

 

Figure 1: Vishay NTCLE-100E-3103 10kΩ Thermistor

 

What You Need:

  1. NI myDAQ
  2. LabVIEW
  3. Vishay NTCLE-100E-3103 10kΩ Thermistor (Purchased from sparkfun.com for $1.95 )
  4. Wire (DMM Banana cables with clips are recommended)
  5. Breadboard (optional)

 

Wiring Instructions:

The thermistor is wired in a circuit as a resistor.  It requires a positive input on one side and a negative input on the other side; the orientation is not important.

 

Figure 2: Wiring Diagram

 

LabVIEW User Interface:

The user interface we created both shows the current temperature measurement taken as well as plotting the values over time on a waveform chart.  Temperature Chart stores previous values so that you can see the change in values over time. 

Figure 3: LabVIEW Front Panel

 

Coding Strategy:

In LabVIEW we need to measure the resistance signal coming from the thermistor from 100Ω to 100kΩ.   This value is converted to a temperature using the polynomial equation from the thermistor specifications referenced at the end of this document.  Finally, we will output the result to a numeric indicator and a temperature chart on the front panel.

 

Figure 4: Coding Block Diagram

 

The LabVIEW block diagram looks very similar to the coding block diagram

Figure 5: LabVIEW 2009 Block Diagram

(The attached LabVIEW code snippet can be dragged-and-dropped to a LabVIEW block diagram, use attached PNG file.  After locating the PNG file, just drag the file icon onto a blank block diagram, as if you were dragging the file onto your desktop.)

 

How It Works:

Inside the while loop on the left is the DAQ Assistant.  It’s configured to read a single value from the myDAQ DMM terminals each time it executes.  Once a value is read it is passed down the wire where it is divided by 10000 and then the natural log is taken of the quotient before being passed into the formula node.  The resistance is then further converted into a temperature in Kelvin using the supplied polynomial equation and constants from the sensor specifications sheet, referenced at the end of this document.  Finally, the temperature is converted to Celsius and displayed in the Temp (K), Temp (C), and Temp Chart indicators on the front panel.  All of the code inside the While Loop continues to run until the Stop button is pressed on the front panel.  The Wait VI (top right) delays execution of the while loop to every 500ms.  Therefore the sampling rate is 2 samples per second, or 2 Hz.

In this VI the DAQ Assistant is configured for on-demand sampling of the analog resistance input channel.  The following steps walk through the configuration of the DAQ Assistant from scratch:

  1. Be sure your myDAQ is plugged in
  2. Press Ctrl-Space to bring up the Quick Drop Window (takes a full minute to load on the first use)
  3. Search for DAQ Assistant and double click on it when it appears in the list
  4. Drop it on the Block diagram (white window)
  5. When the Create a New Express Task configuration pane appears, select
    1. Acquire Signals
    2. Analog Input
    3. Resistance
    4. Dev 1 (NI myDAQ) *Note: If you have other NI hardware installed, the myDAQ will not be Dev1.
    5. dmm
    6. Finish
  6. Change the Resistance input Setup to the correct Signal Input Range
    1. Max: 100k
    2. Min: 100
  7. Change Timing Settings to
    1. 1 Sample (On Demand)
  8. Press OK


Figure 6: DAQ Assistant Resistance Configuration

*Note that sample time is set by the Wait VI and is set to sample 2 times per second (every 500ms) in this VI

 

Tips and Tricks

  • You can modify the VI to log the data to file using a ‘Write To Spreadsheet File.vi’ express VI if you wish to save the data.  Be sure to place it in the loop and be sure to append new data to the spreadsheet file.
  • Use ‘From DDT’ to turn the blue Dynamic Data Type wire into an orange double precision number.  This allows the data from the DAQ Assistant to be used with standard LabVIEW VIs.
  • Use this document in conjunction with the Connect a LED to NI myDAQ document to display a light when a certain temperature threshold is met.  You can use a comparison operation to output a true or false if a value is greater than another number.

 

Related Links

» Vishay 10 kΩ Thermistor Datasheet

» Measuring Temperature with an RTD or Thermistor

» NI myDAQ

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.