Example Code

Wheatstone Bridge Based Measurements with myDAQ and LabVIEW

Code and Documents

Third-Party Code Repository

Some users manage their code in repositories outside of ni.com. Use your best judgment when following links to third-party sites. http://zone.ni.com/devzone/cda/tut/p/id/3642

Description

Overview


This document explains using Wheatstone Bridge to make a precise measurement for sensors such as strain gauges and load cells. The data will be acquired using the DAQ Assistant that is installed into LabVIEW with the NI DAQmx driver as a voltage and converted to a strain, force, or other engineering unit using basic programming in LabVIEW.

Objective: 

Measure the voltage differential across a Wheatstone Bridge with the analog input terminals of the myDAQ and convert the voltage to the desired engineering unit in LabVIEW.

 

Background:

Certain sensors and gauges, such as a strain gauge, output a very small change in resistance; this makes the task of detecting the changes in the sensor difficult.  To measure such small changes in resistance or voltage, these sensors are almost always used in a bridge configuration with a voltage excitation source. The general Wheatstone bridge, as seen in Figure 1 below, consists of four resistive arms with an excitation voltage, VEX, that is applied across the bridge.  We can then calculate the change in resistance of R3 by comparing VO to VEX, provided that the resistance of the other resistors are known, using the following equation:

 

Figure 1: Vishay NTCLE-100E-3103 10kΩ Thermistor

 

 

What You Need:

  1. NI myDAQ
  2. LabVIEW
  3. A Balanced Wheatstone Bridge with Sensors
  4. Wire 

 

Wiring Instructions:

The Wheatstone Bridge is wired to your myDAQ as 2 analog inputs, one to measure VO and the other to measure  Vex. We also must connect the +5V output pin of the myDAQ to the top of the bridge to serve as the excitation voltage high, and connect the Digital Ground (DGND) to the bottom of the bridge to serve as the excitation voltage low.  This will allow us to measure the excitation voltage in case it is not exactly at a constant 5VDC.  This will serve as a Remote Sense of the excitation voltage.

 

Figure 2: Wiring Diagram

 

LabVIEW User Interface:

The user interface we created shows the Voltage Drop, VO, the measured Excitation Voltage, Vex, and the ratio of the two.  

Figure 3: LabVIEW Front Panel

 

Coding Strategy:

In LabVIEW we need to measure the voltage drop across the terminals, as well as the excitation voltage applied to the bridge. The voltage drop is then divided by the excitation voltage to find the ratio between the two.  This value is very useful in bridge-based measurements and more logic can be built in to tailor the application as needed.  Finally, we will output the results to numeric indicators on the front panel.

 

Figure 4: Coding Block Diagram

 

The LabVIEW block diagram looks very similar to the coding block diagram

Figure 5: 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.  It’s configured to read a single value from the myDAQ ai0 and ai1 terminals each time it executes.  Once a value is read for each channel it is passed down the wire and then split out into each value.  Both the VO and Vex values are displayed on the front panel, and then the ratio of VO/Vex is calculated and displayed on the front panel.  All of the code inside the While Loop continues to run until the Stop button is pressed on the front panel.  The Wait VI (top right) delays execution of the while loop to every 100ms.  Therefore the sampling rate is 10 samples per second, or 10 Hz.

In this VI the DAQ Assistant is configured for on-demand sampling of the analog resistance input 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. Voltage
    4. Dev 1 (NI myDAQ) *Note: If you have other NI hardware installed, the myDAQ will not be Dev1.
    5. ai0 and ai1 (Use Ctrl+Click for multiple selections)
    6. Finish
  6. Change Timing Settings to
    1. 1 Sample (On Demand)
  7. Press OK


Figure 6: DAQ Assistant Analog Input 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

  • You can modify the VI to log the data to file using a ‘Write To Spreadsheet File.vi’ express VI if you wish to save the data.  Be sure to place it in the loop and be sure to append new data to the spreadsheet file.
  • Use ‘From DDT’ to turn the blue Dynamic Data Type wire into an orange double precision number.  This allows the data from the DAQ Assistant to be used with standard LabVIEW VIs.
  • Expand this application by using the setup with any bridge based sensor to acquire data.
  • Clean up your input signal by adding a low-pass filter in software using the Filter Express VI.

 

Related Links

» Measuring Strain with Strain Gages

» NI myDAQ Getting Started and Support

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

Comments
ProfHanson
Member
Member
on

The wiring diagram doesn't seem to be displaying properly, no matter the browser. Does anyone have a copy of the image?

markwni
Community Team
Community Team
on

Hello @ProfHanson - we were able to find the image and update this document.

Community Manager
NI Community
alexwp7
Member
Member
on

The greatest sample rate that I can achieve is 10Hz (loop wait of 100ms). Lowering this wait amount doesn't increase sample rate, but increasing the wait lowers sampling rate. Am I missing something that is inhibiting a large sampling rate?

Eugene-RMD
Member
Member
on

Maybe a Real-Time controller will give high sample rates?