I am designing four traffic lights that I can control with a single digital switch. When the signal is 1, two traffic lights should be green, and the other two red, and they should reverse when the digital signal is 0. I'm using a simple transistor switch to achieve this:

This one works in the simulation, but I tried it on the breadboard, and it won't work properly unless I swap the green LED with the red one and vice versa.
Otherwise, the red LED stays on regardless of the applied base voltage, while the green one stays off.

Moreover, the whole implementation doesn't work in the simulation. Only the first and the third gates switch properly. The second and the fourth ones have the above-mentioned issue:

Now, I'm aware that the red and green LEDs have different forward voltages (1.7V for red and 2.2V for green), but I don't know how to fix this problem.

\$\begingroup\$It'll work for circuit one because the voltage at the anode of LG1 will dragged down below the turn on voltage for LG1 when Q2 is saturated.\$\endgroup\$
– DiBoscoNov 30 '17 at 15:39

\$\begingroup\$If you think about what the minimum voltage on the collector of Q1 can be, taking into account the voltage drop across the LED and the transistor, you will see why the red LED is always on.\$\endgroup\$
– evildemonicNov 30 '17 at 15:56

2

\$\begingroup\$"I'm using a simple TTL switch " no such thing....\$\endgroup\$
– Trevor_GNov 30 '17 at 16:37

\$\begingroup\$@MITURAJ there are numerous ways to do it.. two is my limit for freebies ;) Not sure what you mean though... I did it this way round so there is no shoot-thru and the LEDs are low enough Vf for 5V to cover the rail offsets.\$\endgroup\$
– Trevor_GNov 30 '17 at 16:08

1

\$\begingroup\$OH wait... YOu said TTL,, you are just using a switch...\$\endgroup\$
– Trevor_GNov 30 '17 at 16:32

1

\$\begingroup\$Maybe because the inputs to the transistors are floating at base. I think it has to be pulled up/down using resistors.\$\endgroup\$
– Mitu RajNov 30 '17 at 16:33

1

\$\begingroup\$@Trevor oh, it works now, thanks! but I'm still not sure by what you mean, isn't TTL just boolean logic with bipolar transistors? Isn't it the case here? (NOT gate)\$\endgroup\$
– user2210558Nov 30 '17 at 16:44

2

\$\begingroup\$@user2210558 A TTL signal is a very specific set of voltages and currents. What you have is just a floating line with a switched in pull-up.\$\endgroup\$
– Trevor_GNov 30 '17 at 16:47

Since the LEDs you are switching are different colours they have different forward voltages. We can do a nice trick with this.

Figure 1. Switching between two LEDs with an N.O. contact and the load-line explanation. Source: 1 GPIO, multiple LEDs.

The intersection of the load-line graph shows us what voltage and current we can expect on each LED type with that value resistor.

In Figure 1a the green LED is on by default and the load-line shows that we can expect about 16 mA through it and 2.1 V across it.

If we switch on the red the forward voltage will drop to 1.75 or 1.8 V. At that voltage the green will pass only a couple of mA and should turn off or go dim.

If you want the red on by default then we add in D1 to induce a little more voltage drop. D1 + L3 = 0.7 + 1.75 = 2.45 V. When the switch is closed the green LED will cause the LED voltage to drop to 2.1 V and the red will go out.

If S2 is replaced with a logic output the voltage might not be sufficiently high enough so additional diodes may be required in the default leg.