Arduino Digital Output Drive vs. Direct-connected LEDs

What happens when you jam an LED into an Arduino digital output and turn it on?

Direct LED drive - no ballast resistor
Direct LED drive – no ballast resistor

This plot gives the load-line solution for that situation:

Arduino Pin Driver - Direct LED Load
Arduino Pin Driver – Direct LED Load

The dotted curve comes from Figure 29-22 of the ATmega168 datatsheet and shows the typical source current vs. voltage for a digital output pin on your favorite Arduino.

The cheerful colored curves show the current vs. voltage characteristics of some random LEDs, with data from the same curve tracer setup as those.

Given a particular LED directly connected between an Arduino output pin and circuit common (without the formality of a current-limiting ballast resistor), the intersection of the dotted output pin curve with the colored LED curve gives you the current & voltage at the pin. For example, the violet LED would operate at 4 V and 40 mA.

Some gotchas:

  • Typical 5 mm LEDs, of the sort one might use for this experiment, have a maximum DC current limit of 20 mA
  • Arduino output pins have an absolute maximum current limit of 40 mA

So all of the direct solutions drive too much current through the LED. Although the blue and violet LEDs don’t quite exceed the output pin limit, the others certainly do. Those old standby red & amber LEDs would have absurdly high intercepts, well beyond the limit of sanity, in the region where the data you see here breaks down, where the pin driver gives up and goes poof, not that that ever stopped anybody from trying.

You’ve probably seen somebody do it. Next time, aim ’em here in a non-confrontational manner… [grin]

My Arduino Survival Guide presentation has other info that may help that poor sweating Arduino survive. You don’t get my performance-art patter, but the pictures and captions should carry the tale…

As part of conjuring up this plot, I discovered that, for whatever reason, Gnuplot’s TrueType font rendering (via gdlib) no longer works in Xubuntu 12.04: the font name has no effect whatsoever, but the point size does.

The Gnuplot source code:

#!/bin/sh
#-- overhead
export GDFONTPATH="/usr/share/fonts/truetype/msttcorefonts"
Pinfile="ATmega Pin Driver Data - Source.csv"
LEDfile="LED Data.csv"
base="Arduino Pin Driver - Direct LED Load"
Outfile="${base}.png"
echo Output file: ${Outfile}
fontname="Arial"
echo Font: ${fontname}
#-- do it
gnuplot << EOF
#set term x11
set term png font "${fontname},18" size 950,600
set output "${Outfile}"
set title "${base}" font "${fontname},22"
set key noautotitles
unset mouse
set bmargin 4
set grid xtics ytics
set xlabel "Pin Voltage - V"
set format x "%4.1f"
set xrange [0:${vds_max}]
#set xtics 0,5
set mxtics 2
#set ytics nomirror autofreq
set ylabel "Pin Current - mA"
#set format y "%4.1f"
set yrange [0:80]
#set mytics 2
#set y2label "Drain Resistance - RDS - mohm"
#set y2tics nomirror autofreq ${rds_tics}
#set format y2 "%3.0f"
#set y2range [0:${rds_max}]
#set y2tics 32
#set rmargin 9
set datafile separator "\t"
set label "Pin IOH" at 3.0,70 center font "${fontname},18"
set label "Pin Abs Max" at 1.4,40 right font "${fontname},18"
set arrow from 1.5,40 to 4.75,40 lw 4 nohead
set label "LED Max" at 1.4,20 right font "${fontname},18"
set arrow from 1.5,20 to 4.75,20 lw 4 nohead
plot \
"${Pinfile}" using 1:3 with lines lt 0 lw 3 lc -1 ,\
"${LEDfile}" using (\$5/1000):((\$1>0)?\$2/1000:NaN) index 0:0 with lines lw 3 lc 1 ,\
"${LEDfile}" using (\$5/1000):((\$1>0)?\$2/1000:NaN) index 1:1 with lines lw 3 lc 2 ,\
"${LEDfile}" using (\$5/1000):((\$1>0)?\$2/1000:NaN) index 2:2 with lines lw 3 lc 0 ,\
"${LEDfile}" using (\$5/1000):((\$1>0)?\$2/1000:NaN) index 3:3 with lines lw 3 lc 4 ,\
"${LEDfile}" using (\$5/1000):((\$1>0)?\$2/1000:NaN) index 4:4 with lines lw 3 lc 3 ,\
"${LEDfile}" using (\$5/1000):((\$1>0)?\$2/1000:NaN) index 5:5 with lines lw 3 lc 7
EOF

A few early risers got to see a completely broken listing, with all the quotes and brackets and suchlike reduced to the usual HTML escaped gibberish…

11 thoughts on “Arduino Digital Output Drive vs. Direct-connected LEDs

  1. Hmm, back in the stone ages (1970s), HP’s OptoElectronics Division made a bunch of R-LEDs with integrated resistors. Our department did the resistors and these were sold in a few varieties (5V and 12V, red, yellow and green) at least until OED got folded into the LumiLeds joint venture around Y2K.
    I suspect the R-LEDs were too expensive for OED to do them with the higher intensity technologies (at least, we never heard of the super-bright LEDs combined with our resistors), but it might be worth looking to see if these might exist.
    For what it’s worth, I think these went into the older style T1-3/4 package, though they might have fit the 5mm quasi-surface mount packages. We got the resistor die size down small enough so they should have fit. (10 x 14 mils).

    1. we never heard of the super-bright LEDs combined with our resistors

      My LED collection has some SOT-23 red LEDs with internal resistors, so somebody still makes them. Of course, they’re surplus with no pedigree, so they may have teleported directly from your stone age. [grin]

      These days everybody uses constant-current chopper drivers with high-intensity LEDs; resistors being so 20th Century.

      You probably can’t even get an Energy Star rating if you have a ballast resistor on an indicator LED…

      1. Not so sure about the Energy Star rating. Remember the kerfuffle about the feather duster/space heater and similar frauds getting a rating? At least back in 2010, you could get away with murder, er, feathers!… (try a search on “energy star feather duster” for links to the story of the GAO sting).
        I’ll stay with stone knives and bearskins if it’s cost effective.

        1. Not so sure about the Energy Star rating

          Ouch!

          All I know: complex stuff costs more and fails sooner than simple stuff. All the energy savings seem to happen way down the calendar… maybe a simple resistor wins over a complex current source that you replace twice?

  2. Out here (40 miles from a town of 20K people, with 60K in a large county), I’ve learned that simple and robust can be a lot better than lighter/cheaper/more elegant. It doesn’t help that the closest thing to an electronics distributor is Radio Shack, or what I can get on line. (“Overnight Delivery” isn’t. Not out here.) Not like hopping in the car and getting ICs a couple of miles away, as in my former life.

    1. or what I can get on line

      Even though we have a bit more population around here, I’ve pretty much given up on local sources: there aren’t any, at least for the things I use.

      Used to be you could get good industrial surplus, but those days are done.

  3. The sources were drying up in San Jose when we moved in 2003. Shifting from Silicon Valley to Ebay/Google meant a lot of the small machine shops closed, and the equipment manufacturers saw the writing on the wall.

    I can get some metal stock locally, with more when we do that Costco run, but for things like motors, I have to be really creative or very patient. (I’m told “liability” keeps motors from getting sold by the recyclers. Sigh.) My drum sander is mis-powered by a lawn-mower grinder motor with no thermal cutoff. Must Be Fixed.

    I’m doing a trip back to the Midwest next year, Surplus Center is on the route. Yeah!.

  4. So these aren’t actual measurements that take into account the inherent impedance of the output pin, right?
    That would be more interesting…

    1. So these aren’t actual measurements

      Yes, they are: the LED characteristics came from a simple homebrew curve tracer and the ATmega168 curve came from their datasheet’s graph of typical driver characteristics (which I presume they measured). Both of those sources have links in the post, so you can build an LED curve tracer, measure your own LEDs, and duplicate the results.

      the inherent impedance of the output pin

      That’s what produces the slanted IOH curve; otherwise, it would be a vertical line.

      The intersection of the pin and LED curves shows the point at which the pin sees exactly the same voltage and current as the LED, so it accounts for their internal behavior. That’s how a load-line analysis works!

Comments are closed.