Pin 13 Considered Harmful

The scariest thing about teaching is the risk of being wrong.

Maybe you can relate? Written some blog posts, given a few talks, published an article, and then found out your spiel contained a piece of inaccurate—or even damaging—information? Hits right in the pit of your stomach, doesn’t it.

Yeah, well.

Please allow me to correct something I’ve learned since starting my Hello, Arduino talks and writing my Arduino article for CODE Magazine.

I’ve plugged an LED directly into pin 13 and GND. Don’t do this.

Although the leads of an LED fit conveniently into pins 13 and Ground, this can damage the LED.

Don’t plug an LED directly into pin 13.

An LED can handle only so much current. The limit is printed on the packaging, usually something like 20 mA (milliAmps). If you exceed that, you’ll either gradually or immediately burn out the LED, and possibly damage the pin on the microcontroller chip. Therefore, LEDs must always be put in-series with a current-limiting resistor. Like this:

A resistor should be included in-series with the LED.

Use a resistor to limit the current to the LED.

The formula for current is voltage divided by resistance. By convention, current is abbreviated as I, so you have: I = V/R. V is the 5 volts supplied by the Arduino, and you can see that if resistance (R) is really tiny (almost zero), current (I) gets huge! Followed by… bzorch.

Figuring out the right R value for your circuit is a blog post unto itself. In the meantime, there are plenty of online calculators, such as this current-limiting resistor calculator for LEDs.

The early-earliest revisions of the Arduino included a resistor on pin 13. Current versions do still have a resistor in series with the on-board LED attached to pin 13, but not with the pin itself. This was likely what confused me and keeps this incorrect advice bouncing around the ‘net. When a friendly electrical engineer at TechShop set me straight, it was, of course, after my article had hit the newsstands.

Ah, well. Another day, another chance to fry some components and become wiser. Forgive me, learn with me, use a resistor with your LEDs, and build great things!

About Sharon Cichelli

I am a Principal Technical Lead at Headspring, developing enterprise-changing software and coaching teams to deliver value without death marches. I am a .NET developer, open-source contributor, user group organizer, technical blogger, pinball fan, and Arduino enthusiast.
This entry was posted in arduino, electronics and tagged . Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Carlos Ribas

    Believe it or not, I learned about LEDs and using resistors to limit current way back in the “Nintendo Wii is new and cool” days. I built home-made “sensor bars” that actually worked properly with my front-projection setup. They are basically two tiny radioshack project boxes, 3 leds in each, placed 3-4ft apart above my screen and wired to a DC adapter. The sensor bar Nintendo ships works fine with smaller screens, but as the screen gets bigger (and thus your distance from it), their sensor bar turns out to be much too narrow. That leads to hyperactive aiming control and generally poor gaming experiences. Anyway, this is one of the few electronics posts of yours where I was like, “hey! yea, I know about this!” lol :)

    • scichelli

      :) Hee hee.

      That Wii sensor bar is a great home hack! Very cool.

      • Carlos Ribas

        I should mention that the LEDs are IR, and therefore invisible to the human eye, despite them being pretty darn bright (much brighter than the Nintendo ones).

        I might also mention that I tried IR Lasers (from laser mice) as well, so that I could bounce them off the screen from within the screen boundaries. That would work even better than placing custom LED arrays above the screen. But, it might also blind the players :)

        • scichelli

          Gradually, though, so they probably wouldn’t trace it to you.

  • Jon Polfer

    Great article! It reminded me of a few things…

    RadioShack used to sell a red LED which consumed a small amount of current (less than 10mA IIRC) at 5V forward voltage, which wouldn’t require a current-limiting resistor. My dad had them in his parts box when I worked on my first embedded system (a $7 BASIC interpreter chip I bought out of the back of the Circuit Cellar magazine), and we used them for the hello-world project.

    I did a quick search on DigiKey and it doesn’t look like they have any LEDs with those characteristics.

    If you use PWM to light the LED, you can get by without a resistor too, but that’s way too compilicated for a first Arduino program.

    • scichelli

      That LED with the built-in resistance would be so handy! Nifty to know that it exists.