2 GPIO, 1 bi-colour 2-pin LED

2 x GPIO, bi-colour LED-1
2 x GPIO, bi-colour LED-1
A bi-colour 2-pin LED can easily be switched to either colour or any blend in between with two GPIO pins.

If two GPIO1 pins are available controlling a 2-pin bi-colour back-to-back LED is simple.

How it works

  • To light L1, green, switch GPIO1 high and GPIO2 low. Current will flow from left to right.
  • To light L2, red, switch CPIO2 high and GPIO1 low. Current will flow from right to left.
  • To cross-fade or mix colours toggle between the two states above. A smooth blend can be obtained by varying the duty cycle.
  • To fade the LED set both of the outputs high or low for part of the time.
  • To switch off the LED set both of the outputs high or low. No current will flow and the LED will be dark.

The resistor can, of course, go on either side of the LED.

2 x GPIO controlling a higher voltage LED from a 3.3 V GPIO.

This circuit works in a similar manner to the simple one at the top of the page. If the GPIOs are both off then both sides of the LEDs are pulled high and the LEDs are off. To switch on the green Q2 is turned on and R1 sets the current. To switch on the red Q1 is turned on. To blend the colour the GPIOs are toggled alternately.

Note that turning both GPIOs on will turn off the LEDs but waste power through R1 and R2 (but without damage).

The schematic shows a 5 V supply but this could  be used for 12 or 24 V LEDs provided the transistor is suitably rated for both voltage and current.

See all GPIO tricks.

Please link to us if you find the information helpful ...<br>Tweet about this on Twitter
Twitter
Share on Facebook
Facebook
Pin on Pinterest
Pinterest
Digg this
Digg
Share on LinkedIn
Linkedin
Share on Reddit
Reddit
Share on StumbleUpon
StumbleUpon
Share on Tumblr
Tumblr
  1. GPIO = general purpose input output. Most micros allow user configuration of the pins as either input or output or tri-state (disconnected).