how to toggle two LEDS with transistors?

For my electronics class, we had to program an arduino and build a simple circuit. I opted for a traffic light that switches its lights when a bathroom is being occupied. For the real project I used a bipolar relay switch, which I can toggle with just one output from the arduino. This system is now built in in my local coffeeshop. The thing is, I have to do an assessment about this project, and  it is not possible for me to use the original system, and I don't have a relay laying around. I do however have multiple transistors. Since these are electronic switches, just like relays, it seems possible to me to use these to turn one LED on and the other off and vice versa, with only one signal.
I can't come up with the proper schematic for this.. can anybody help me?

sort by: active | newest | oldest
You guys are overthinking the whole project!!!
Have one LED with the Cathode tied to +v through a 100 ohm resistor (red)
Have the other LED anode tied to ground through a 100 ohm resistor (green)
Tie the red anode and green cathode to your output pin.
When the pin is HIGH, the green LED will light. when it's LOW, the red LED will light.
I know you might be thinking "but won't both LED's light up since they provide a path for each other" - the answer is NO - because the connect point between them will either be ground, bypassing the lower LED, or +V bypassing the upper LED. Whichever LED is bypassed, is off, while the other is on. You could technically turn both on by setting the output from the Atmega as a floating input (no pullup) or you could simulate both being on by toggling the output at a high frequency. The only thing you cannot do is have both LEDs off. Using transistors at all is overkill, and completely unnecessary.
LED toggle.jpg
bobiebob (author)  SuperTech-IT3 years ago
Well I be damned, that actually works! As I'm not that familiar with electronics, I din't totally understand how this works. I do get they when the pin is low, it is eccentially low, but what I don't get is why the upper led goes of when the pin is high. The Vcc is still providing power to it right?
I have to admit, your reaction gave me a chuckle! LOL!
I'm lazy, so if there's an easier way to do something, I'll usually find it.
bobiebob (author)  SuperTech-IT3 years ago
As Bill Gates once said: “I choose a lazy person to do a hard job. Because a lazy person will find an easy way to do it.”
Next time hold your phone sideways. Makes for better videos. Just a side note...lol.
bobiebob (author)  SuperTech-IT3 years ago
haha didn't think about it xD I too hate vertical video's :p
This eliminates the need for transistors altogether, and is the simplest way to toggle the lighting of 2 LEDs with 1 pin.
Hey. That is pretty clever. Maybe this should be best answer.

I do not have a good excuse for doing the hard way.  Maybe I was kinda thinking I had to use the given transistors.
LOL - Thanks Jack.
It's like that riddle - there's a bathtub full of water.
You have a coffee cup, a beer mug, and a bucket. What is the fastest way to empty the tub?

After several well thought answers are presented with proof as to their efficiency, I walk up and pull the plug from the drain!
iceng3 years ago
A simple circuit, That Works !

I can show a video of it running.

iceng iceng3 years ago
bobiebob (author) 3 years ago
I hope you didn't chuckle about the spelling mistakes, that was typed on my iPhone :p Gnd > led > pin LOW is no closed circuit, that's for sure, neither is V+ > led > pin HIGH. But for the first led, wouldn't the current flow through the second led and go to ground that way, closing the circuit?
no, because it encounters +V before it gets there, which is basically like putting a wire right over the top LED and resistor.
Imagine taking the +V that connects to the top circuit, and connecting a wire from there to the point between the 2 LEDs.
This is what happens when we place +V at that junction.
Since we have effectively put a wire from the +V at the top to the point between the 2 LEDs, the top LED cannot possibly light, it just provides the +V connection for the lower half of the circuit..

Conversely, when we put GND at that midpoint, it's like taking a wire from the GND at the bottom of the circuit and running it up to the midpoint between the 2 LEDs. In this case, the lower LED cannot possibly light - all we have done is provide the GND for the top half of the circuit..
bobiebob (author)  SuperTech-IT3 years ago
Clear as a button now. So may thanks SuperTech. If you ever are in the Netherlands, hit me up and I will take you out for a beer!
These boards...lol
3.7A Controller.jpgCIMG2811-2.jpg
If you ever decide to build one of those 8X8X8 LED cubes, let me know, and I'll make you a deal on the PC Boards.
yes, but look at it's path...+V goes to a resistor, then to an LED (the upper one) and when the pin is high, it then goes to ... +V.
Well, +V - resistor - LED - +V does not a circuit make. There is no ground for the upper LED, therefore no current flow, therefore no light.
Just like the lower LED when the pin is low
GND - resistor - LED - GND this also does not make a circuit because there is no path to the +V, therefore no current flow.
bobiebob (author) 3 years ago
Hello iceng,
I believe the Fairchild bs170's are MOSFET transistors and the Fairchild 8902 TIP30A's are Bipolar PNP's, but I am not that experienced in electronic components, so I could be wrong. I've added the links to the data sheets to both the components.

The datasheets I have don’t mention bipolar on either BS170 or TIP30, complementary is NPN TIP29 and PNP TIP30 however 30 watt transistors are a bit much just to drive an LED.
Here is my guess at how you could do this using two of your BS170 MOSFETS, and I built a simulation of it using that free simulator at falstad.com.

The link to it is big and ugly, because the arguments in the link somehow contain all the data needed to make that circuit.  Here:

Also you need to have your Java working in your browser, and probably some other things have to go right, for that link to actually work.  For that reason I captured a picture of the circuit I made, and then edited it a little bit, since nothing on it had any labels.

If the picture version attached to this reply is too small to read, the full sized one is here:

The way it works is that when Q1 is turned on, the voltage at its drain gets pulled low, since its on-resistance is a lot smaller than 10K.  Conversely, the voltage at its drain is high when Q1 is turned off, since its off-resistance is a lot bigger than 10K.

The second transistor, Q2, is wired as a "source-follower".  The voltage at its source "follows" the voltage at its gate.  The resistor and LED wired to Q2's source turn on when Q2 turns on.

Anyway, if that link, and that simulation actually work for you, you can actually flip that little switch open or closed, which makes the output from that CMOS inverter, (triangle with a small circle on its nose) go low or high respectively, and the little green and red LEDs turn on or off too. So that's kind of fun to play with, if it works. 

The reason I put that simulated inverter in there, was just to have something to simulate a generic digital signal.  For your circuit,  I am guessing you can just tie the gate of that first MOSFET to an output pin on your Arduino, or whatever it was that was making your digital signal.
You could have put the LED on the drain load on the first transistor, and buffered it perhaps.
Although I am driving this circuit with a 555 timer any gate like a hex inverter will run the transistors.
Pirate Pete 3a.bmp
iceng3 years ago
What resistors, transistors and switching components do you have for some one to help you ?
  • Bipolar PNP ?
  • MOSFET ?
  • Bipolar NPN ?
  • SCR ?
  • Thyratron ?
  • GTO ?
  • 4 layer Diode ?
  • Junction Fet ?
  • NE-4 ?
  • Triac ?
  • Tunnel Diode ?
  • Triode ?
  • Pentode ?
  • Op-Amp ?

bobiebob (author) 3 years ago
Hi jack, thanks for the reply. You are right, they are not just like relays, but serve a similar purpose, to make a low voltage switch a higher voltage.

The page you put in your reply makes some sense to me, but I can't figure out how to implement this in the system I'm trying to build, since the signal should give a high to the first led, and a low to the second.

The transistors I have laying around are three BS170's and two 8902 TIP30A's (I'm a product designer, so my junk box is not that big, at least not component wise :P) and yes, we are talking regular 5mm LED's.

The only IC I have is an H-bridge, so not much port wise.

Would you be able to sketch up a schematic that makes the LEDS switch states with only one signal and these few components?
Transistors are not "just like relays".  If they were you would have figured this out by now.

Working at the level of individual transistors is a little bit complicated, but do-able, if you only have to do like one thing, in this case, a logic inversion, convert a 0 to a 1, or a 1 to a 0. 

The name for that kind of thing, 0 to 1 or 1 to 0, as a kind of logic gate, is an inverter, aka NOT gate.  This page,
sort of shows you how such a gate can be built from discrete transistors.

I am hopeful that page will make sense to you.  If it does not, then just reply, and I, or some other regular on this form, will try to make a circuit diagram for you.

By the way, you did not mention what kind of transistors you have.  That information would be helpful in providing an answer specific to the transistors you have, in your junk box, parts collection. Also BTW, these are just ordinary LEDs, right?  I mean the current through them when turned on is less than like 50 mA, right?

Also BTW, gates like inverters, ANDs, ORs, NANDs, NORs, XORs, and everything else under the sun, are sold in IC form, and those can very convenient, if you happen to have some in your parts collection. The CMOS 4000 series (chip numbers CD40xx), gets used a lot in homebrew, and hobbyist type applications, or at least it used to before things like Arduino came along and made everything too easy.