Output Light Using a Basic 5mm LED, NI myDAQ, and LabVIEW

Publish Date: Jul 23, 2010 | 8 Ratings | 4.00 out of 5 | Print | 3 Customer Reviews | Submit your review

Overview

This document explains using a basic, low-cost 5mm LED to output light with your National Instruments myDAQ in LabVIEW. The digital output will be generated on the myDAQ digital line using the DAQ Assistant that is installed into LabVIEW with the NI DAQmx driver.

Table of Contents

  1. Objective: 
  2. Background:
  3. What You Need:
  4. Wiring Instructions:
  5. LabVIEW User Interface:
  6. Coding Strategy:
  7. How It Works:
  8. Tips and Tricks
  9. Related Links

1. Objective: 

Use a basic 5mm LED (Light Emitting Diode) to output light using digital line output on your myDAQ device.

 

Back to Top

2. Background:

A basic 5mm LED is a low-cost solution for emitting light for various applications.  LEDs are often used to indicate if something is turned on, what power level a machine is running at, and for low-cost lighting solutions in remote locations.  It is important to know that a LED is a diode, which only allows current to flow in one direction.  This means that we have to connect the positive input to the positive lead of the lead, and the negative input to the negative lead.  Also, a LED can only handle a certain amount of current, so it is necessary to connect a resistor in series to regulate the current flow. 

 

Figure 1: Basic Red 5mm LED and 330Ω Resistor

 

Back to Top

3. What You Need:

  1. NI myDAQ
  2. LabVIEW
  3. Basic 5mm LED
  4. 330Ω 1/6th Watt Resistor
  5. Wire
  6. Breadboard

 

Back to Top

4. Wiring Instructions:

The LED is wired in series with a 330Ω resistor.  Assuming the LED has negligible resistance, the total resistance of the circuit is 330Ω.  According to Ohm’s Law, the current drive with a 5VDC power supply from the digital line would result in 5V÷330Ω= 15.15mA.  As stated in the specification sheet for the LED that is referenced at the bottom of the document, the Led can handle a current up to 20mA, and is recommended to be used with 16 to 18mA; so at 15.15mA we will be safe.  The LED requires a positive input on the longer lead side and a negative input on the shorter side, as seen in Figure 1 above.  We will supply power to this circuit using Digital Line 0 of the myDAQ, and ground the circuit to Digital Ground of the myDAQ.

 

Figure 2: Wiring Diagram

 

Back to Top

5. LabVIEW User Interface:

The user interface we created has a Boolean push button switch, Light Control, to turn the LED light on or off.

Figure 3: LabVIEW Front Panel

 

Back to Top

6. Coding Strategy:

In LabVIEW we need to create a front panel Boolean array control to output a 5V digital signal on Line0 to our basic 5mm LED.   This Boolean value is input into our DAQ Assistant which will output the corresponding value to the NI myDAQ digital port.  In digital Boolean logic, a True corresponds to a 5V signal, and a False corresponds to a 0V signal.  Therefore, a True will turn on the LED.

 

Figure 4: Coding Block Diagram

 

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

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.)

 

Back to Top

7. How It Works:

Inside the while loop on the left is the Boolean Array Control used to send a True or False to the LED. The control is on the front panel, and can be seen to have only one element in the array.  This is because the DAQ Assistant is setup to only output to one line.  On the right is the DAQ Assistant.  It’s configured to output a single value from the myDAQ Digital Port0/Line0 each time it executes.  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 left) delays execution of the while loop to every 100ms.  Therefore the output rate is 10 samples per second, or 10 Hz.

In this VI the DAQ Assistant is configured for on-demand output on the digital 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. Generate Signals
    2. Digital Output
    3. Line Output
    4. Dev 1 (NI myDAQ) *Note: If you have other NI hardware installed, the myDAQ will not be Dev1.
    5. port0/line0
    6. Finish
  6. Leave Timing Settings to
    1. 1 Sample (On Demand)
  7. Do not Invert Line
  8. Press OK


Figure 6: DAQ Assistance Resistance 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

 

Back to Top

8. Tips and Tricks

  • Use this document in conjunction with the Measure Temperature using 10kΩ Thermistor, NI myDAQ, and LabVIEW document to display a light when a certain temperature threshold is met.  You can use a comparison to output a true or false if a value is greater than another number.
  • Expand your application by adding more than one channel to your DAQ Assistant and turn on multiple LEDs in with your VI in LabVIEW.
  • Further expand your application by integrating this logic to control a 7-segment LED to display integers.

 

Back to Top

9. Related Links

» Basic 5mm LED Datasheet

» NI myDAQ Getting Started and Support

Back to Top

Customer Reviews
3 Reviews | Submit your review

Wrong voltage from DIO ???  - Oct 6, 2013

If I measured correctly, there is only 3.3V coming from the DIO... So 3.3V / 330 Ohm = 10 mA .. But just something to keep in mind.. DI: 5V TTL DO: 5V TTL Kind regards Niels Göran

  - Mar 13, 2012

I think the resistor added to the led is more a matter of best practice than that of necessity.

Do we really need a resistor here?  - Oct 23, 2011

Specification sheet of MyDAQ says that the "Maximum Output Current per line = 4mA" for the 8 DIO lines. As it is much below the maximum current limit of the LED, do I still need to use a resistor?

Bookmark & Share


Downloads


Ratings

Rate this document

Answered Your Question?
Yes No

Submit