Using Labview To Measure Temperature With A Thermistor
Using Labview To Measure Temperature With A Thermistor
Using Labview To Measure Temperature With A Thermistor
November, 2009
For resources, see the LabVIEW Resources page on the UMN ME2011 course site.
Before starting this exercise, install LabVIEW and drivers following the instructions in the
LabVIEW Quick Start document, and connect and test the USB-68008 data acquisition unit
following the directions in the Connecting the USB-68008 document. The screen shots shown
in this document are from a Windows VISTA machine. Your setup may have slight differences.
Introduction
The purpose of the exercise is to give you some experience using LabVIEW for automatic,
computer-based data collection from an experiment. You will be measuring the internal
temperature of a grape or similar object as a function of time as it is plunged into a glass of ice
water. Using the collected data, you will determine the time constant of the heat transfer
dynamics that model the temperature drop.
Thermistor
USB-6008
Thermistors
Thermistors are resistors that vary with temperature.
temperature T can be modeled by
Page 1 of 18
1
1
R = RR exp B
T TR
(1)
where RR is the resistance at a reference temperature TR and B is a constant. In order for Equation
1 to work, absolute temperatures (Kelvin units) must be used. The thermistor used in this project,
(jameco.com PN 207037) has a resistance RR of 10,000 ohms at the reference temperature TR of
298 K (25 C) and a B value of 4038, with 10% tolerance on the resistance.
Try plunging your thermistor into ice water, which is approximately 273 K (0 C) and measure
the resistance across the leads using your DMM. (Hint: squeeze the DMM leads hard against the
thermistor leads for an accurate resistance reading.) See how close the measured value of R is to
the theoretical value from Equation 1. You may see the resistance measurement drifting due to
self-heating from the current through the thermistor provided by the DMM.
Rearranging Equation 1 for temperature as a function of resistance yields
1 1 R
T = + ln
TR B R R
(2)
Measuring Circuit
The data acquisition pod can only measure voltage, not resistance. You will construct a voltage
divider circuit to measure resistance. The schematic for a voltage divider is shown below
V_i is a fixed supply voltage, which for the experiment will be +5V. R1 is a 10K ohm resistor. R
is the thermistor whose resistance varies with temperature. V is the output voltage that will be
sampled by the data acquisition unit. The equation for V is
V = Vi
R
R1 + R
Page 2 of 18
(3)
R=
R1V
(Vi V )
(4)
Inserting Equation 4 into Equation 2 gives the equation for temperature as a function of the
voltage measured by the data acquisition unit
1 1
R1V
T = + ln
(
)
T
B
R
V
V
R
R
i
(5)
For the setup in your experiment, the values for the constants in this equation are
T_R [deg K]
R_R [ohms]
B [unitless]
R_1 [ohms]
V_i [volts]
298
10,000
4038
10,000
5
Equation 5 gives you the temperature in Kelvin. For convenience, the output should be in
Fahrenheit or Celsius. Here are the conversion formulas
[deg F] = [deg K] * 1.8 460
[deg C] = [deg K] 273
Suggestion: Give yourself an engineering challenge and see if you can derive Equations 2-5 on
your own. Equation 3 can be derived using Ohms Law, V = I*R.
LabVIEW VI
The first step in the experiment is to program a custom LabVIEW VI to sample the voltage from
the voltage divider and convert it into a temperature reading. You will do this in two steps, first
creating the conversion section then creating the data acquisition setting. This way you can
proceed with a good portion of the experiment setup without needing the data acquisition
hardware. It is assumed that you have read the LabVIEW Quick Start document that describes
the basics of LabVIEW.
Start LabVIEW and create a new blank VI.
On the Front Panel, place two Numeric Indicators and a Gauge.
Change one of the indicators to a Control (R-click > Change to control) and change its label to
Reading [V] (R-click > Properties). The indicator is a placeholder for the voltage reading that
later will come from the data acquisition unit. On the other indicator, suppress the label (R-click
> Visible Items > Label) and align under the gauge (alignment tool button is at the top of the
Page 3 of 18
window). Using the Properties function, change the gauge label to Temp [F] and change its
min and max to 20 and 100. Your front panel will look something like this1
Return to the front panel and run the application with the Run Continuously button. Change the
value in the reading indicator and confirm that the gauge and second indicator follow. Stop the
application with the Abort button.
1
You might like the Meter or Thermometer numeric indicators more than the Gauge. Feel free to explore and
modify the instructions to suit your taste.
Page 4 of 18
The next step is to add the conversion between voltages read by the data acquisition unit and
temperature read by the gauge. Return to the block diagram and delete the wire connections.
Ctrl-B is useful for clearing dangling wires.
Place a Formula block on the diagram. (Forget how? Consult the LabVIEW Quick Start
document.) In the Configure Formula dialog box (if it doesnt appear, R-click > Properties),
change the label on Input X1 to V.
Starting with Equation 5, substituting the constants from the table, noting that R_1 and R_r
cancel in the ln function, adding in the Kelvin to Fahrenheit conversion and expressing in plain
text format, the formula for temperature [F] from voltage is
((1/298)+(1/4038)*ln(V/(5-V)))**(-1) * 1.8 - 460
Type this into the Configure Formula box. If the box to the right of the formula turns green, the
formula is syntactically correct. The Configure Formula box will look like this
Back on the block diagram, wire the Reading indicator to the input V of the formula block and
wire the output Result of the formula block to the gauge and the second indicator blocks. (The
Edit > Clean Up Diagram, Ctrl-U, function is useful if the diagram gets messy.) Your Block
Diagram will look like this
Page 5 of 18
Return to the Front Panel and run the application, entering voltage readings between zero and 5
volts. If everything is correct, you will get these pairs of values from your VI.
Volts
3.87
0.31
Temp [deg F]
31.7
210.9
For the remainder of this exercise, you will need the USB-6008 unit.
Measuring Voltages
The next step is to use the USB-6008 and modify the VI to collect samples from it.
Connect the USB-6008 to your computer with the USB cable. The green LED on the device will
blink.
Go to the Front Panel of your VI and delete the reading indicator. Switch to the Block Diagram.
Open the Functions Palette. Navigate to Express > Input. Insert the DAQ Assistant block onto
the diagram. If you are prompted about licensing restrictions, click the box that says you
understand then click Next. The Create New Express Task box is next. Select Acquire Signals >
Analog Input > Voltage
Page 6 of 18
In the next box, select ai0 as the channel to read from. This corresponds to one of the screw
terminal connections on the device. Click Finish.
Page 7 of 18
Click OK to finish the process of inserting the DAQ Assistant into the block diagram.
Add a Numeric Control to the Front Panel, change it to an indicator and change its label to
Volts.
In the block diagram, wire the output of the DAQ Assistant to the volts indicator and to the input
of the formula block. It will look like this
Move to the Front Panel and run the VI, which will look like this
Page 8 of 18
Strip about 3/8 of insulation from both ends of a 22 g solid wire that is about 5 long. Connect
one end to terminal AI0 (pin 2) of the USB-6008. To connect a wire, place in the hole and then
tighten down the corresponding screw. If you dont have a tiny screwdriver that fits, be
inventive.
Touch the other end of the jumper to the GND terminal (pin 1) and to the +5V terminal (pin 31)
and watch the Volts indicator on your VI. If you run the screw down all the way on those
terminals, you can touch the screw heads with the jumper. You may also want to measure
between +5V and GND terminals using your DMM to see if it agrees with the reading on the VI.
Run the VI. You have a computer-based thermometer. Blow on the thermistor or squeeze
between your fingers and watch the gauge go up. Dunk it in ice water and watch it go down.
Find the Write To Measurement File block in the Functions Palette (Express > Output > Write
To Measurement File) and place on the block diagram. A dialog box will appear. In the dialog
box, pick a convenient directory for the output file. Choose File Format = Text (LVM), X Value
Columns = One column only, Delimiter = Comma, and If a file already exists = Overwrite file.
Wire the Result output of the Formula block to the Signals input of the Collector block and wire
the Collected Signal output of the Collector block to the Signals input of the Write To
Measurement File block.
Run the VI for a few seconds then quit. With a plain text editor such as Notepad, open the data
file that you specified in the Write To Measurement File dialog. The data file will look
something like this
Page 10 of 18
The last ten lines are the collected data with the X_Value column being time in seconds and the
Voltage column being the temperature data. Because the sample rate in the DAQ Assistant block
is set to 1 KHz, the time interval for the data is 0.001 s (1 ms). There are only 10 data points
because the Samples to Read setting in the DAQ Assistant is 10.
The sampling rate of the DAQ Assistant block is 1000 Hz, or one sample every millisecond.
Because temperature changes slowly and because sampling at 1000 Hz would result in massive
and unnecessary amounts of stored data, the sampling rate needs to be lowered to 10 Hz. This
will result in a manageable 600 data point set for every minute of data collection.
The current VI runs the DAQ once, saves the data to file, and stops. The VI will be much more
useful if it can be run for arbitrary time periods and then save the collected data to the file. The
most convenient way to make this happen is to use a While loop.
First, open the properties dialog for the DAQ Assistant on the block diagram. Under the
Configuration tab, Timing Settings (you may have to scroll down to reveal), set Acquisition
Mode = N Samples, Samples to Read = 10, Rate = 10.
Page 11 of 18
If a dialog box appears asking if you want to create a While Loop, answer no because you will
do this manually.
In the Functions Palette, find the While Loop (Express > Exec Control > While Loop). To place
on the block diagram, click once in the upper left corner, and then again in the lower right,
enclosing all elements on the block diagram except the Write To Measurement File Block, like
this
Page 12 of 18
Notice that a STOP button was automatically placed on the front panel. Use it to stop the loop,
which will stop data collection and write the data to the file.
Run the VI. Wait about 10 seconds and then click STOP. Examine the data file. It will have
about 100 data points (10 seconds of data collected at 10 Hz). If you click STOP again, new data
will be stored, which is the data between successive STOPs. To abort operation, click the Abort
button as usual.
Note that while running, the indicators and dial gauge update once per second. This is because of
the Samples To Read = 10 and Rate = 10 settings in the DAQ Assistant. The indicators are only
updated after 10 samples are read.
Page 13 of 18
Open Excel and then open the file. Depending on your version of Excel, the Text Import Wizard
may appear. In successive dialog boxes, select Delimited, to indicate data is in columns and
select that the delimiter is a comma. When successful your spreadsheet will have the data in two
columns, like this
Page 14 of 18
Hint: On a Windows computer, another way to achieve the same goal is to rename your data file
from grape-data.lvm to grape-data.csv. Double-click the file and it will open directly in Excel.
Temperature (deg F)
From here, you can create a nice temperature-time plot like this, which shows what happens to
temperature when the thermistor is brought up close to the bulb of a halogen desk lamp.
120
115
110
105
100
95
90
85
80
75
70
0
10
15
Time (s)
For continuous time plots where there are many data points (100 for every 10 s in this plot),
show the line that connects the data points but do not show markers at the points.
Now you are all ready to do the grape experiment, but first a little theory is needed.
T T
= e (hA / cV )t
T0 T
(1)
where A and V are the surface area and volume of the object, and c are the density and specific
heat, and h is the convection coefficient of the fluid. We will not be determining all the material
properties in this experiment; therefore, for our purposes, Equation (1) can be re-written as
2
The theory presented in this section is adapted from: Holman, J.P. 2002. Heat Transfer, Ninth Edition. New
York, McGraw-Hill.
Page 15 of 18
T T = (T0 T )e t /
(2)
The quantity = cV/hA is known as the time constant of the system. The time constant is a
measure of how quickly the system responds to changes in temperature. In this case, the
difference between T and T decreases by a factor of e1 (~63%) every time constant. After 4
time constants, the difference is decreased by 98% from its original value. Exponential decay is
typically considered complete after 45 time constants.
Thats all for the theory, now it is on to the experiment.
Page 16 of 18
y = 43.825e
30
-0.0064x
R = 0.9929
25
20
15
10
5
0
0
50
100
150
Time (s)
Page 17 of 18
therefore 1/0.0064 = 156 seconds. Your time constant will be different, perhaps by a
lot, because your fruit will be larger or smaller or a different material than the grape
used in the example.
If you wish, repeat the process using a different grape, one that is a bit larger or smaller than the
first. How does the time constant of the second grape compare to that of the first? Larger?
Smaller? The Same? If it is different, what are some possible reasons for the difference?
Lab Report
Prepare a lab report using the standard Introduction, Methods, Results, Discussion format. Two
or three pages should be sufficient, if you write and format with care.
Page 18 of 18