Controlling Two LEDs per uC pin

Introduction

Sometimes you just run out of pins to control your LEDs.

There are lots of options open to you, not limited to:

This tutorial hopes to show you another option; Hang 2 LEDs from each I/O pin of your uC. It's effectively the very simplest form of charlieplexing.

1. Fundamentals:

An LED will light if the voltage differential across it is greater than the Forward Voltage (usually labelled VF in the LED's documentation). Because it's a diode, it will only light when it's connected one way...

Examples:

This circuit will not light the LED.
WARNING: Do not use this circuit.

circuit with reversed LED

Circuit Diagram 1.1

The LED will not light because the cathode of the LED is more positive than the anode; the diode is reversed. The warning about not using this circuit is because if Vcc is greater than the reverse breakdown voltage of the LED (see its datasheet), you may damage the LED.

Assuming that the supply voltage (Vcc) is greater than the LED's VF then the following circuit will light the LED. Very brightly. For a short while.
WARNING: Do not use this circuit.

simplest LED circuit

Circuit Diagram 1.2

"Why not use this circuit?"

Because it's likely that the LED will burn out rather quickly.

LEDs do not, usually, limit the current that flows through them. It'll attempt to carry all the current that the supply will give. If the supply is really weedy, like a button cell, then you'll get away with it because most button cells can only supply a few milliamps. If the supply is more beefy, like a 10A bench power supply, then the LED won't last more than a brief flash [...you have burned so very, very, brightly, Roy...] . If it's something in between, like a couple of AA batteries, then the LED might last anything between a few seconds and a few years. You might get lucky.

To prevent the LEDs burning out, a current limiting resistor is needed. This is just a normal resistor that is used to limit the current that flows though the LED. For the moment, I'm going to skip the calculation of the value needed and where to place it; it'll be covered later (see section 5). All you need to know is that a current limiting resistor will probably be needed somewhere. If you do decide to live life on the edge and use an LED without a current limiting resistor, then you'll be tutted at by many electronics professionals. They might even leave you off their christmas card list.