
Driving Two LEDs with a Single Microcontroller Port
Some boards may need many LEDs but the microcontroller doesn’t have enough ports for each LED. This forces the designer to either use an LED driver or use a microcontroller with more IO. Both of these options have an associated cost with it. The first option requires the designer to spend time choosing the LED driver and more time learning how it works. In addition the driver needs more space on the board. The solution to this problem is to use a single port of the microcontroller to drive two LEDs. This enables it to turn them off and on as they are connected each to one port.
Every engineering solution is not a perfect solution (gain some, loose some). This solution follows that concept. It requires a bit more programming which is harmless as the associated cost is incurred only once.
The following schematic shows the connection of the apparatus.

Figure 1: Schematic
Here is how it works:
The port is set as a general digital IO port. Therefore it can either be 0 or 1. Setting it to output and assigning 0 to it will turn on LED1 and turn off LED2. It should be clear how to turn on LED2 and turn off LED1. Setting the port to output and assigning 1 to it will do this. The challenging part is to make them both on or off.
To make both LEDs off, one should set the port as input. The high impedance state of this port will act as a virtual open between the port and where LEDs connect. As long as the Vss to ground voltage does not exceed the minimum voltages required to turn on both LEDs, LED1 and LED2 will stay off. For example, if the voltage drop of each LED is about 1.75V in on state, a minimum of 3.5V Vcc is required to turn on both LEDs. Now if the Vcc is only 3V, both LEDs stay off. If the Vcc exceeds the two voltage drops, two resistors can be added to do the job as depicted in figure 2.

Figure 2: Resistor added to increase drop voltage.
Assuming GND=0; ![]()
Now if the LEDs are identical and resistors are identical,
. Selecting R1 and R2 somehow that the above equation is always correct will keep both LEDs off at the same time. But the resistor value should be small enough to drive a single LED which means: ![]()
The last step is how to turn both LEDs on. This is where a little bit of programming comes into play. To keep both LEDs on, we set the port as output and send a pulse to it. This will cause both LEDs to blink and as long as the blinking is fast enough, they both appear to be on. One can get creative here and actually play with the brightness of both LEDs by changing the duty cycle. Slow blinking can be achieved by decreasing the frequency of the pulse.
The following table should summarize what was discussed above:
| Port direction | Port state | LED1 | LED2 |
| Output | 0 | ON | OFF |
| Output | 1 | OFF | ON |
| Input | X | OFF | OFF |
| Output | Pulse | ON | ON |
Table 1: LEDs Truth Table
Omid N. Tak
Astinco Inc.