Simplest possible “traffic light” circuit?
August 10, 2022 7:12 AM   Subscribe

Would like to make an led lamp with one each of red, orange and green. Pressing one of three buttons would switch to that light and turn off the other two. I could do this easily enough in code with an arduino, but it feels it should be simple enough to do with just a raw circuit. How please?

Googling traffic light circuits has mainly given me ones to function as actual lights, like with red following orange on a timer etc.
posted by Iteki to Technology (20 answers total)
 
Best answer: The simplest possible would be to use a triple-throw switch. There are probably better options, but from a quick search.
posted by primethyme at 7:40 AM on August 10, 2022 [3 favorites]


This instructable looks like what you want. Note: it uses a 74-series logic IC (a 74HC174, in this case. You could almost certainly build a circuit out of discrete transistors/resistors/caps with the same functionality, if you want to use the building blocks of logic as part of your push away from microcontrollers, but at higher part count.
posted by Alterscape at 7:40 AM on August 10, 2022 [2 favorites]


If you trying to do it at 120 Volts, you could do it with two timers and a relay for each light.
posted by drezdn at 7:55 AM on August 10, 2022 [1 favorite]


Triple pole triple throw switch is your search term. Probably even find a push button version.
No need for circuitry.

Primethyme got it in one.
posted by lothar at 9:42 AM on August 10, 2022


Yeah, if you’re willing to go to a switch instead of push-buttons, primethyme is 100% correct and my answer is over complicating things.
posted by Alterscape at 10:30 AM on August 10, 2022


Response by poster: I am such a dope, of course a three-way switch. Thanks! I'd have preferred buttons but it looks like there isn't a dummy easy way to do it. Will go with a lil arduino if needed otherwise so, thanks!
posted by Iteki at 10:52 AM on August 10, 2022


Response by poster: Hmm, although that does require going past the middle (orange) every time though.
posted by Iteki at 11:05 AM on August 10, 2022


I imagine it could be done with relays. This isn't much cheaper than an arduino, but it's not overkill and it's easy to troubleshoot.
posted by AugustusCrunch at 11:28 AM on August 10, 2022


Best answer: Pretty sure this will work.

The transistors are general purpose small signal types, like a BC548 or 2N3904. Any small NPN transistor should work. The diodes are all small signal general purpose types like 1N4148 or 1N914.

The way the circuit works is as follows:

Pushing a button connects the cathode of the associated LED to ground, lighting it. It also pulls down the cathodes of both the signal diodes connected to the same point. This, in turn, pulls both their anodes down to a diode voltage drop above ground, and diverts all the current that would otherwise be flowing through the associated 4.7k resistor into the base of a transistor.

Removal of their base current turns both of those transistors turn off. That makes their associated LEDs turn off too (unless somebody happens to be mashing their buttons as well), and floats the cathodes of all their connected signal diodes so they stop drawing any current.

That, in turn, allows the 4.7k resistor connected to those diodes' anodes to pull that point up enough to forward bias both the third diode in the group and the base of the transistor it's connected to - that is, the one in parallel with the pushbutton - and supply enough base current to saturate it. The button can now be released and the transistor will keep the associated LED lit.

You could probably leave out the 10k resistors from transistor bases to ground; they're there for mostly superstitious reasons. The theory is that when one of the LED-monitoring diodes in any group of three gets pulled down, the junction of the three (where the 4.7k resistor connects) will go to one transistor saturation voltage plus one diode drop above ground. That's not high enough to forward bias both the third diode in the group and the base-emitter junction it's feeding, so there will be no current delivered to the base and the transistor will turn off. However, under those conditions the base is effectively floating. I don't like input nodes that float, so I put the 10k resistor there to give noise a path to ground.

If you end up building this, I would appreciate knowing whether it did in fact work.
posted by flabdablet at 1:03 PM on August 10, 2022 [3 favorites]


Sounds like the type of push button switch on an old car radio. Something like this.
posted by Sophont at 1:30 PM on August 10, 2022


Little handful of transistors and diodes and a bit of perf board should be obtainable for rather less than $43.
posted by flabdablet at 1:33 PM on August 10, 2022


Another mechanical switch option here if you scroll down to “4 Button Bank 3 Position + "Off"”
posted by doctord at 2:37 PM on August 10, 2022


Best answer: Each of the transistor plus three diode plus two resistors groups in the design above implements a two-input open-collector NAND gate, and having just found out that the 7403 open-collector quad NAND gate IC is still a thing (just), the design is now down to three resistors, three LEDs, three buttons and a 14 pin IC that costs forty cents. Doesn't get much simpler and cheaper than that.

Circuit operation is as before: the NAND gates have open collector outputs that go open instead of driving high, so shorting them to ground with pushbuttons is quite OK. Each gate monitors the outputs of the other two, and will set its output transistor open to turn off its associated LED if either of the others is on. Pushing a button forces the issue, making the NAND gate whose own output is being driven low by a button the only one that's allowed to keep itself low, which it will continue to do even after the button is released.

The 7403's outputs are only good to sink 16mA, which is why the LED current limiting resistors are a bit higher in this version.

Logic levels could be an issue. If it turns out that a 180 ohm resistor in series with a LED is in fact not capable of pulling up a 7403 input high enough to register as logic high, you might need a bypass resistor around each LED. 1k should be about right. This will cost the LED a bit of current and might also blow the 7403's current output budget unless you increase the 180 ohm resistors a bit as well.
posted by flabdablet at 3:30 PM on August 10, 2022 [1 favorite]


The 74LS38 exists too, and is not only is it cheaper than the 7403 at 29 cents and not yet classed as superseded, it has gruntier output transistors good for 24mA.
posted by flabdablet at 4:09 PM on August 10, 2022


Response by poster: That sounds perfect flabdablet, thank you! Am trying to build it in tinkercad right now to test if I understand, will report back here if I get it working virtually or physically!
posted by Iteki at 12:12 PM on August 11, 2022


Was previously unaware of tinkercad, looks like a fun tool. I couldn't find any open-collector NAND gates in the components library for its Circuits section, so I've tried building up the transistor version on a virtual breadboard instead. It doesn't work properly: pushing a button does light the associated LED and turn off the others, but releasing it makes them all revert to On. There's clearly some logic level funkiness going on, but I also can't find any data sheets or specs for its virtual transistor or diode components, so working out exactly what is going to be a bit of a trial and failure slog. I'll keep tweaking and let you know if I can get one to go.

Pretty sure the 74LS38 design would just work, given either a real breadboard and components or a virtual 74LS38.
posted by flabdablet at 11:15 PM on August 11, 2022 [1 favorite]


Best answer: Here's a working Tinkercad simulation.

The design is essentially the 74LS38 one, except that because Tinkercad doesn't offer open collector NAND gates I used the 74HC08 quad AND gate it does offer, then fed the gate outputs via resistors into discrete transistors to invert them and switch enough current to drive the LEDs. Which is good practice anyway, because a LED can load an HC family logic gate output enough that its voltage wouldn't read reliably as either logic 0 or logic 1.

I added 10k resistors across the LEDs to maintain a reliable logic 1 at the AND gates' inputs when the LEDs are off.

The little 100pF capacitor across the red light's button is there to add just enough asymmetry to stop the simulator losing the plot at startup. Without it, the circuit fibrillates and shorts out the power supply instead of dropping into one of the three available stable states. It comes good when you press any button and I don't believe it would do that in the real world, but having a repeatable startup state is nice.
posted by flabdablet at 12:12 PM on August 12, 2022


Best answer: Got a version of the transistors and diodes design to work as well. This one uses power MOSFETs rather than jellybean bipolar junction transistors, and actually gets away with one less diode per LED.

MOSFETs are controlled by gate voltage rather than base current, and they don't turn on until their gate to source voltage is over a diode's forward voltage, and when they do turn on the drain to source voltage is ones to tens rather than hundreds of millivolts as for a BJT, and all these things mean that the somewhat anaemic Low delivered by one resistor and two diodes worth of wired-AND is still enough to turn one off.

The little drain-to-source capacitors are once again only included to stabilize the simulator - I am almost sure that the real world would have more than enough stray capacitance to do whatever the hell they're achieving here - and I made them different values so that it would always start up on Red.
posted by flabdablet at 4:12 AM on August 13, 2022


Response by poster: WOW! That's such a smart idea to use the breadboard in tinkercad, I don't know why I've never tried that, my wild-builds get very messy. Thanks once again!
posted by Iteki at 12:24 PM on August 13, 2022


I've been thinking about why those capacitors seem to matter, and it seems to me that because there exists one signal path through what I've built that could amount to a ring of three inverters if you squint just right and do a bit of handwaving about propagation delays, and because rings of three inverters are a fairly classic design basis for crystal-locked oscillators, that there might be some genuine real-world way for the ring of gates to find its way into a self-sustaining oscillatory mode as well as locking into the one LED on, two LEDs off stable states.

The classic RS flip-flop design of which this is an extension has only two inverters in its ring, and therefore no potential oscillatory modes.

I don't think that's much of an issue for a tinkering project, but it's not something I'd design into any real product without further analysis and testing.
posted by flabdablet at 1:13 PM on August 13, 2022


« Older Long-term yoga practice = failed epidural?   |   Tips for writers with ADHD Newer »
This thread is closed to new comments.