Real-time temperature in LabVIEW

31 December 2012

In this example we are going to show how to build a simple application for openDAQ using LabVIEW.

We will generate a simple Virtual Instrument (VI) to log the ambient temperature in the room, using some of the sub-VIs available in the LabVIEW repository for openDAQ. Using a similar scheme, you will be able to generate many different and much more complex applications with openDAQ and LabVIEW.

The hardware connection that we need for this experiment is very simple: The only external component that we need is a temperature sensor with analog output, in this case a LM35 (TI). You can find it easily in any shop for electronic components. The LM35 are precision temperature sensors IC, whose output voltage is linearly proportional to the ambient Celsius (Centigrade) temperature. The LM35 does not require any external calibration and it provides typical accuracies of ±¼°C at room temperature.

We have connected the sensor IC directly to the openDAQ, supply pins to +5V and GND terminals, and the output voltage pin directly to input A6.

We have selected a +-2V analog input range to make the readings through A6, but the +-400mV range would be enough if the ambient temperature is not likely to go over 40ºC (400mV output).

We start building the software application by opening LabVIEW 2011 and creating a blank VI. Then we start to work on the block diagram, on which we will place several sub-VI's (right click>> select VI) from the repository of OpenDAQ.

The first one will be OPENDAQ_CONNECT [1]. The main goal of this VI is to create a VISA serial port connection with the device. We also placed a connection prompt to know when our Open-DAQ is ready to work. We selected a "square led" indicator to show if the device is already connected.

Next step will be getting the appropriate calibration constants, because we will need them to convert the results. The OPENDAQ_CONNECT VI returns an array of values corresponding to the respective gains and offset of the different scales available in the device. In this example we will lock openDAQ in +-2V range, so we will use Index Array operators [2] (right click>>Array) with index ‘2’ to get the specific values for that range (we would use index ‘3’ if we used +-0.4V range).

After it, it comes the main body of the application. The next step is to create a "Case Structure" (right >> Structures >> case structure) with a START button to control the flow of execution, when the device starts capturing temperature data (create >> control). We will use another button, a Stop button, to get out of the Loop. All of that is surrounded by another bigger While loop. This loop takes control of the full program flow, allowing multiple executions of Start and Stop buttons.

Within the while loops we will insert the main sub-VI for this program, AIN_CFG [3], which has 5 inputs and three outputs (we only use one of these). Of course, the VI is also connected to the VISA descriptors. We use four numerical constants to configure the VI:

  • P-input: ‘6’. Because we are using input A6
  • N-input: ‘0’. This is because we are measuring SE (input vs. GND).
  • Nsamples: 10. The greater the number of samples is, the lower the noise.

We used a Tab Control in our Front Panel to keep everything a little organized, here is where you place all the buttons and graphics of our VI (right click on front panel >> classic >> classic >> Tab Control containers).

In the inner while loop we have used AIN sub-VI [4] to extract the data of temperature. The device has already been configured by the first AIN_CFG, after pressing Start button, so there is no need for additional configuration.

Finally we perform the necessary operations to get the data of temperature in the graph showing it in the way we want:

  1. We use a Timer that controls that data is taken every 1000ms, 1 second (right click>> Programming >> Timing >> wait).
  2. We use a Graph chart to represent the results (ºC versus real time) in the Front Panel (right >> silver >> graph >> waveform chart)
  3. We modified the chart properties to show us a real-time measurement (right click the waveform chart>>Create>>property>> node >> X scale display format >> format).
  4. We perform the necessary operations [5] with the raw ADC data that the device returns to us by AIN function, applying the calibration constants that we explained before and some operations to convert the voltage into temperature (V->ºC).

The result of all this is a simple application that allows us to read the ambient temperature and show it in a graph of temperature versus the time of the day: