Electronics ru
Advanced Search +


Single-port pin drives dual LED

Siemens » BSS101

Tom Gay


Most current microcontrollers offer I/O ports that can change their functions during program execution. As outputs, the circuits can sink and source reasonably large amounts of current. This Design Idea shows three alternative methods for driving a two-pin, two-color LED from a single I/O pin. Figure 1 illustrates one possible approach that uses external inverter IC1 to drive D1, a red/green bidirectional LED. A logic-high output on the port pin forces current through the green (upper) LED and pulls the inverter's input high, which drives the inverter's output low and sinks current from the green LED. A logic-low output on the port pin raises the inverter's output high, delivering current to the red (lower) LED; the microcontroller's output sinks current from the red LED.

Single-port pin drives dual LED
Figure 1. An inverter can drive a bidirectional, two-color LED
but applies the same amount of current to both LEDs.

To turn off both LEDs, you reconfigure the microcontroller's port pin from output to input or switch the pin to tristate mode, either of which prevents the microcontroller's port pin from sourcing or sinking current. This circuit's primary disadvantage is that it yields no control over each LED's brightness; instead, resistor R5 determines forward current for both LEDs.

Figure 2 presents an approach that also involves a major disadvantage. Zener diodes D3 and D4 and resistors R3 and R4 form a low-impedance voltage divider that applies VCC/2 V to one end of LED D5. The value of VCC drives the selection of the zener diodes' voltage, VZ, with lower voltage zener diodes allowing more LED current and higher voltage ones limiting maximum LED current. Given that the microcontroller's outputs can deliver rail-to-rail voltages, the difference between VCC and VZ limits maximum forward current for both LEDs. For example, if VCC is 5 V and VZ is 3 V, the forward voltage across either LED is less than 2 V. Once a designer selects the zener-diode voltage, only small variations in VCC can occur; otherwise, the LEDs' brightness would fluctuate.

Single-port pin drives dual LED
Figure 2. A zener-diode and resistor voltage divider exhibits sensitivity to
supply-voltage variations and allows LED brightness to vary.

Using discrete components, another circuit offers an inexpensive approach that avoids the other circuits' disadvantages (Figure 3). When the microcontroller's output port goes high, current flows through the green (upper) LED, R2, D2, and FET Q2, which the port's high level turns on. When the microcontroller's output port goes low, transistor Q1 turns on and delivers current to the port pin through R2 and the red (lower) LED. The circuit operates symmetrically because silicon diode D2's forward-voltage drop is present regardless of whether the microcontroller's port pin goes high or low. VCC may vary during operation but must remain higher than 3 V.

Single-port pin drives dual LED
Figure 3. This circuit provides immunity to supply-voltage fluctuations and more uniform
LED brightness.

You can individually adjust the LEDs' currents to equalize brightness or compensate for a difference between the microcontroller's power-supply voltage and the LED-driver circuit's VCC. Replace R2 with two resistors connected in series between Q1's emitter and D2's anode. Connect the midpoint of the two resistors to the LEDs.

With the microcontroller's port pin configured as an "input with pullup," the port delivers a small current to the green LED. However, pullup-resistor values of 22 kΩ or higher do not cause misleading light output from LEDs in the off-state. When the input signal from the port pin floats – that is, with VCC at 5 V and the port configured as an input with no pullup resistor – the circuit draws no additional current, and the quiescent current, which R1 determines, averages less than 100 µA.

Материалы по теме

Slices ↓
Radiolocman facebook Radiolocman twitter Radiolocman google plus