Example Code

Measure Current Using NI myDAQ

Code and Documents

Attachment

Download All

Overview


This document explains using a National Instruments myDAQ to measure a current in LabVIEW. The current will be acquired on the myDAQ DMM channel using a DAQ Assistant that is installed into LabVIEW with the NI DAQmx driver.

Objective: 

Use the DMM terminals on the NI myDAQ to acquire a current signal from a AAA battery 

 

What You Need:

  1. NI myDAQ
  2. LabVIEW
  3. AAA 1.5V Battery
  4. DMM Banana Cables

 

Wiring Instructions:

Simply connect the DMM positive input terminal to the positive side of the battery and the negative DMM input terminal to the negative side of the battery using the banana cables.

 

Figure 1: Wiring Diagram

 

LabVIEW User Interface:

The user interface we created has a both graph and numeric indicator.  The numeric indicator will display the instantaneous value and the graph will display a voltage history.

Figure 2: LabVIEW Front Panel

 

Coding Strategy:

In LabVIEW we need to create a front panel to display the voltage values in a numerical and graphical indicator.  We will acquire the data using the DAQ Assistant and then pass the data to the indicators.

 

Figure 3: Coding Block Diagram

 

The LabVIEW diagram looks very similar to the coding block diagram, except the battery is not included.

Figure 4: 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 used to input the voltage data from the DMM terminals. The voltage values are indicated on the front panel with both a numeric indicator and the waveform chart indicator.

In this VI the DAQ Assistant is configured for on-demand input on the analog 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. Current
    4. Dev 1 (NI myDAQ) *Note: If you have other NI hardware installed, the myDAQ will not be Dev1.
    5. DMM
    6. Finish
  6. Leave Timing Settings to
    1. 1 Sample (On Demand)
  7. Press OK


Figure 5: DAQ Assistant Current Configuration

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

 

Tips and Tricks

  • Expand your knowledge and application by completing the more in-depth examples for the NI myDAQ.

 

Related Links

» NI myDAQ Getting Started and Support

 

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

Contributors