Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Taking a Measurement

Every day, scientists and engineers are required to perform tests. The signals that they measure are real-world analog signals that vary indefinitely with time. To automate and better visualize the data, you need to transfer the analog signal to the digital world to be viewed on a computer. Data acquisition devices, such as the NI myDAQ or NI Educational Laboratory Virtual Instrumentation Suite (NI ELVIS)  II, perform analog-to-digital conversion to accomplish this task. This module shows you how to acquire an analog voltage signal using a DAQ device and NI LabVIEW software.


Step-by-Step Procedure

Download the Step-by-Step Procedure PDF


  1. Connect the USB DAQ device to your PC
  2. Connect the signal of interest to the analog input channel 0 (ai0) terminal of your device
    1. You can locate the device pinouts for your DAQ device by searching for your device online at ni.com
    2. The user guide and specifications contain this diagram
    3. Right-click your device in NI Measurement & Automation Explorer (MAX) and select Device Pinouts
  3. Create a new VI in LabVIEW
    1. Open LabVIEW and select File»New VI
  4. Place a DAQ Assistant on the block diagram
    1. Right-click on the block diagram and select Express»Input»DAQ Assistant
    2. Place the DAQ Assistant on the block diagram by left-clicking
  5. Configure DAQ Assistant type
    1. Select Acquire Signals
    2. Select Analog Input
    3. Select Voltage
    4. Select Dev1 (or the name of your device if not Dev1)
    5. Select ai0 
  6. Configure acquisition settings
    1. Enter 1000 for Number of Samples
    2. Enter 10k for Sample Rate
    3. Click Run to test your settings
    4. Click OK to finish the DAQ Assistant
  7. Create the graph indicator to view data
    1. Right-click on the Data output terminal of the DAQ Assistant
    2. Select Create»Graph Indicator
    3. Run the VI by pressing the Run button and visualize the results
    4. Adjust Graph Indicator appearance as desired
  8. Change acquisition mode to Continuous
    1. Double-click the DAQ Assistant
    2. Change Acquisition Mode from N Samples (Finite) to Continuous
    3. Select OK to finish the DAQ Assistant
    4. Select Yes to auto place the While Loop around the DAQ Assistant
  9. Create the stop condition to include when the Stop button is pressed or an error is detected
    1. Unwire the Conditional Terminal from the Stopped output terminal of the analog input DAQ Assistant
    2. Right-click the block diagram and select Programming»Boolean»Or
    3. Wire the output from the Stop button control to the bottom input of the Or Boolean function
    4. Right-click the block diagram, select Programming»Cluster, Class, & Variant»Unbundle by Name, and place this to the right of the analog input DAQ Assistant
    5. Wire the Error Out output terminal of the analog input DAQ Assistant to the input of the Unbundle by Name function and ensure Status is selected to be unbundled
    6. Wire the output of the Unbundle by Name function to the top input of the Or function
    7. Wire the output of the Or function to the input of the Conditional Terminal
  10. Run the VI to visualize the data on the front panel

You can convert your DAQ Assistant Express VIs into low-level NI-DAQmx functions by right-clicking the DAQ Assistant and selecting Generate NI-DAQmx Code. The low-level NI-DAQmx API exposes more functionality and customization options for programming.

LabVIEW Example Code

Right-click on the above VI snippet and select Save Image As... Locate the file on your hard disk and click and drag the file icon onto your LabVIEW block diagram. LabVIEW automatically generates the code from the VI snippet. For more information, read VI Snippets.

For a low-level NI-DAQmx driver example for this concept, open the NI Example Finder and browse to Hardware Input and Output»DAQmx»Analog Measurements»Voltage»Cont Acq&Graph Voltage Wfm-Int Clk.vi. View the detailed help on using the NI Example Finder and help within LabVIEW.

Don’t have NI-DAQmx installed on your PC?

Download the latest version of NI-DAQmx.

Module Exercise: Taking a Measurement

Download the Module Exercise PDF

Exercise Goal
Use the NI myDAQ device to continuously acquire an audio signal from a sound device such as a microphone, CD player, or MP3 player. Then display the signal to a graph in LabVIEW.

Required Hardware
1- NI myDAQ
1- 3.5 mm audio cable with MP3 or CD player
or
1- computer microphone

Things to Consider

  • What is the audible frequency range of the human ear? Then what should the sampling rate be according to the Nyquist Theorem to capture all of the frequencies? What is the sampling frequency of a CD player? Therefore, what should you use for the sampling rate of your NI myDAQ?
  • Samples to Read should be 1/5 to 1/10 of your sampling rate. For example, Fs=10 kHz, Samples to Read = 1k or 2k samples. This is a good benchmarking relationship for buffered acquisition.
  • Use a voltage acquisition to read data from a microphone, CD player, or MP3 player on audioInputLeft and audioInputRight for a stereo input, or just one channel for a mono input.
  • The input range for the audio input is ±2 V.
  • Turn your sound device to about 30 percent volume to input a quality signal.

Here is an example of what the final signal should look like on a graph indicator:

View the exercise solution (Don’t cheat!).

Cumulative Exam:
LabVIEW and DAQ

Evaluate your understanding of LabVIEW and the basics of DAQ. This exam is recommended after you complete all of the modules for LabVIEW Basic Concepts and LabVIEW Basic Tasks. There are 26 multiple choice questions on the exam.

Take the exam


Cumulative Project:
LabVIEW and DAQ

Assess your working knowledge of building a complete system by acquiring, processing, and displaying data with LabVIEW and a DAQ device. This project is recommended after you complete all of the modules for LabVIEW Basic Concepts and LabVIEW Basic Tasks.

Start the project