# Controling 3 LEDs using only 2 IOs

I once saw somewhere that it is possible to control 3 LEDs with 2 IOs and only using LEDs and resistors. The high state is 5v and low state is 0v.

With 2 digital IOs, we can have 4 different possible situations for LEDs.

00 -> all off
01 -> LED1 on, others off
10 -> LED2 on, others off
11 -> LED3 on, others off

So it is logically possible using logical gates and mixing them. but How could it be done only with resistors and LEDs? and I am sure this method exists.

If they were 2 It was so easy. we connected them the in opposite to each other in parallel with a series resistor and 01 would light the first one and 10 would light the other one. like this :

If both IO lines have the same logic level then neither of the two LEDs would light so you use this to control a 3rd LED but I think you need two diodes acting as a sort of AND gate: -

simulate this circuit – Schematic created using CircuitLab

If either GPIO line is low then the LED won't light. If both GPIO line is high then the LED lights.

• why not replace one of the diodes with LEDs? they are anyhow a kind of diode!
– AHB
Jan 4, 2016 at 9:19
• @BlueSky The diode needs to have a much lower volt drop than the LED to prevent the LED from illuminating. Jan 4, 2016 at 9:21
• For the other 2 LEDs can I use the schematic in my question?
– AHB
Jan 4, 2016 at 9:27
• @BlueSky yes you can. Jan 4, 2016 at 9:32
• @BlueSky, ... and set R1 to match the R in the other pair to give same brightness - 330R in your example. Jan 4, 2016 at 9:40

if you want to use only resistors you can do it like this.

simulate this circuit – Schematic created using CircuitLab

as VCC is 5V the bleed resistor parallel with D3 is needed suffifient that it does not light.unless both in0 and in1 are high.