Skip to main content
Skip table of contents

Driving LEDs (App Note)

This application note is about driving LEDs (light emitting diodes) from a U3, U6, UE9 or T-Series device.  In addition to actual light emitting devices, you will find LEDs inside of solid state relays and optocouplers.

The key specs for an LED are the forward voltage (Vf) and max current.  A typical LED might have a forward voltage of 2.0 volts and a max forward current of 20 mA.

An LED is generally driven from a voltage source, with enough resistance put in series to make sure the resulting current is less than the max rating of the LED.  A few configurations are described below:

Sourcing current from a digital I/O line

The idea is that you connect a digital I/O line (FIO/EIO/CIO/MIO) through some resistance to the anode of the LED, and connect the cathode of the LED to GND.  We will call the voltage sourced by the I/O line Vio, and know that the voltage dropped across the series resistance (Vr) is:
Vr = Vio - Vf

Since most LabJacks have 3.3 volt logic and Vf is 2.0 volts, we get Vr = 1.3 volts in this case.  To keep the current created by that 1.3 volts at 20 mA or less, the source resistance (aka series resistance or output impedance) should be at least:
R >= 1.3/0.020 = 65 ohms

From Appendix A of the device datasheets, you can see that series resistance of an FIO line is about 550 ohms (180 for the T8) while the series resistance of an EIO/CIO line is about 180 ohms. So all digital I/O lines have plenty of resistance and none additional is needed. You can directly drive the LED positive from a digital output. The output when using a 180 ohm line (~7.2 mA) is going to be brighter than when using an 550 ohm line (~2.4 mA).

Sinking current into a digital I/O line

The idea is that you connect VS (5 volts) through some resistance to the anode of the LED, and connect the cathode of the LED to a digital I/O line (FIO/EIO/CIO/MIO).  The LED will turn on when the I/O line is set to output-low, while the LED will be off if the I/O line is set to input or output-high. In this case, the voltage across the series resistance is:
Vr = VS - Vf

... or about 3.0 volts. For a minimum resistance value we now get:
R >= 3.0/0.020 = 150 ohms

... so all digital I/O lines still have enough resistance without having to add any. The 180 ohm lines are going to allow about 16.7 mA to flow, which should result in near maximum brightness from the LED.

Sourcing current from a DAC (analog output) line

The idea is that you connect a DAC line through some resistance to the anode of the LED, and connect the cathode of the LED to GND.  The DAC lines on the U3/U6/UE9/T7/T8 have a source resistance of about 50 ohms (110 for the T4), so to keep the LED current at 20 mA or less the voltage across that resistance (Vr) should be:

Vr <= 50 * 0.020 = 1.0 volts

Thus with just the internal source resistance, for max rated current we want to set the DAC voltage to:

Vdac = Vr + Vf = 1.0 + 2.0 = 3.0 volts

So you can directly drive the LED from a DAC line, and in this case a voltage of 2.0 to 3.0 volts will vary current from roughly 0 to 20 mA.

Using an LJTick-RelayDriver or other switch

If you use the LabJack I/O to control some sort of external switch, such as the LJTick-RelayDriver, you can now control much higher currents and voltages.  You will likely need to add a series resistor to control how much current flows through the LED.

LED Polarity Identification

When looking at a through-hole LED, the positive or anode is the longer lead which connects to a smaller plate internally. The negative or cathode is the shorter lead and connects to a larger plate internally.  The plastic LED housing generally has a flat spot on the negative or cathode side.  To light the LED, current should flow from the anode to the cathode.

Example code

Here's how to toggle an LED on a U3 using LabJackPython. Using method 1 above, wire the anode of an LED to FIO4 and the cathode to GND. Open your Python interpreter and type

Toggle LED Example - python

import u3 d = u3.U3() d.writeRegister(6004, 1) # Turn LED on d.writeRegister(6004, 0) # Turn LED off

U12 Notes

The above information applies to the UD-series (U3/U6/UE9) and T-series. Following are some extra notes for our original U12 device which was released in 2001. See the U12 Datasheet for more details.

The LJTick-RelayDriver, PS12DC, and RB12, are not designed for the U12. The RB16 relay board is a U12 accessory similar to the RB12.

AO lines:  Like the DAC lines on our other devices, the AO (analog output) lines on the U12 can source substantial current.  They have a typical source impedance of 20 ohms.

D lines:  The D lines on the DB25 connector have a typical source resistance of 80 ohms when set to output-high and 30 ohms when set to output-low.

IO lines:  The IO lines have a typical source resistance of 1500 ohms.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.