Using Analog Temperature Sensors with HomeVision


The HomeVision Multifunction Expansion Board's analog inputs (and HomeVision-Pro's analog inputs) are commonly used with analog temperature sensors. This article explains how to read temperature with an LM34 temperature sensor. Other sensors can be used in a similar fashion.

Sensor Description

The LM34 is the most commonly used sensor, although other types are available. It can run off of 5-30 VDC, and the output is 10mV per degree F. It comes in several packages, although the three-lead plastic package (TO-92) is suggested. Three part numbers are available:

bulletLM34DZ
bulletLM34CZ
bulletLM34CAZ

The LM34DZ is adequate for most applications; the LM34CZ works over a wider temperature range; and the LM34CAZ is most accurate (but is considerably more expensive). They are available from a variety of sources, including Digi-Key (800-344-4539). An LM35 is also available, but will have lower temperature resolution (10mV per degree C).

 

horizontal rule

Electrical Connections

The LM34 requires three wires for power, ground, and signal. The following drawing shows the lead orientation as viewed from the bottom of the TO-92 package.



Connect the power and ground wires to the respective positions on the analog input terminal block. Connect the LM34 output to the desired analog input port. Twisted-pair wiring is recommended, with Cat5 cables preferred.

If you're driving a long cable (over 40 feet), use either of the following two circuits for better performance:


Circuit For Improved Performance



Circuit For Maximum Performance

The first circuit is adequate in most applications, but optimum performance is achieved with the second circuit. It provides a decoupling capacitor for the power supply, and allows the LM34 to easily drive a large capacitive load (i.e., a long cable). If you're using a pre-made temperature sensor assembly (commonly packaged in a wall outlet package), it probably contains circuitry similar to this.

 

horizontal rule

Software Setup

Use the HomeVision Analog Inputs Summary Screen under the Objects/Events menu to configure the analog input. The analog inputs work from 0 to 5 volts, and are read as 256 discrete voltage levels (or 255 "steps"). Each step is 19.6078mV (5V / 255). You will need to set the "Gain" and "Offset" factors to match the input to the sensor's output. With the proper settings, the value read by HomeVision (0 to 255) will equal the temperature. This process is described below.

Gain

Select the correct gain factor with the following equation:

     Gain = 19.6078 / XX

     where XX = the sensor's output in mV per degree F

The LM34's output is 10mV per degree F, resulting in a gain of 1.96, as shown:

     Gain = 19.6078 / 10 = 1.96078 (rounded off to 1.96)

Here's how this will work: The input value read by HomeVision increases by 1 each time the input voltage increases by 19.6mV, and 19.6mV corresponds to a temperature rise of 1.96 degrees F. Thus, we use a gain of 1.96 to multiply the input value change by so that it matches the temperature change. HomeVision will round off the final result to the nearest integer, but you should still use a gain of 1.96 and not 2.00 to minimize the error.

Because the analog input resolution (19.6mV) is coarser than the temperature sensor's (10mV), you will usually see the temperature change in 2 degree increments. This is shown below, where the right-hand column indicates the final value read by HomeVision and equals the reported temperature. Note the this value is never more than 1 degree off from the actual temperature.

Actual Temperature

LM34 Output

Input Value

With 1.96 Gain

0
1
2
3
4
.
.
.
50
51
.
.
.
100

0.000
0.010
0.020
0.030
0.040
.
.
.
.500
.510
.
.
.
1.000

0
0
1
1
2
.
.
.
25
26
.
.
.
51

0
0
2
2
4
.
.
.
49
50
.
.
.
100

 

Offset

For the LM34, set the offset factor to zero. Since the LM34 outputs 0 volts at zero degree F, there is no need for an offset. Other sensors may output a different voltage at 0 degrees, necessitating an offset factor. Offset is simply an addition to or subtraction from the value read in.

Calibration

You may want to use a thermometer or other temperature sensor to calibrate the LM34's temperature reading. If you need to adjust the LM34's reading, change the offset factor to make the temperature correct. Do not adjust the gain factor.

 

horizontal rule

Using the Temperature in Your Schedule

First, create a variable to hold each temperature value. If you have multiple sensors, use consecutive variables so they can all be viewed on the same TV screen page.

Anywhere in your schedule you want to read the current temperature from the sensor, use this variable command:

   Var #1 (Outdoor Temp) = Analog input #1 (Outdoor Temp Sensor)           

This command reads in the analog input and puts it into the specified variable. Since we set the input's Gain and Offset factors properly, variable #1 now equals the actual temperature. You can read the analog input each time you need to know the temperature, or you can read it periodically. We recommend creating a periodic event that performs the above command. Set the event's rate to "every loop" or "every minute", depending upon how rapidly the temperature might change.

After putting the analog input into a variable, you can use the variable anyplace you want to know the temperature. For example, if you want to turn on a fan when the temperature exceeds 90 degrees, you could do this:

   If
      Var #1 (Outdoor Temp) > 90
   Then
      X-10: A1 (Ceiling Fan) ON
   End If
          

That's all there is to it!

 

Back Up Next

Last updated:
01 October 2013

Copyright © 1996-2013, all rights reserved, by:
Custom Solutions, Inc.
1705 Canterbury Drive, Indialantic, FL 32903

HomeVision® is a registered trademark of Custom Solutions, Inc.