Driving LEDs (App Note) | LabJack
« Close

Datasheets and User Guides

App Notes

Software & Driver


Driving LEDs (App Note)

This application note is about driving LEDs (light emitting diodes) from a U3/U6/UE9.  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:


1.  Sourcing current from a digital I/O line:  The idea is that you connect an I/O line (FIO or 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

... so since the U3/U6/UE9 has 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 resistance should be at least:

R >= 1.3/0.020 = 65 ohms

From Appendix A of the U3/U6/UE9 User's Guide, you can see that series resistance of an FIO line is about 550 ohms 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 an EIO/CIO line (~7.2 mA) is going to be brighter than when using an FIO line (~2.4 mA).


2.  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 an I/O line (FIO or 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 EIO/CIO lines are going to allow about 16.7 mA to flow, which should result in near maximum brightness from the LED.


3.  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 have a source resistance of about 50 ohms, 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.


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

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