Electronic – Correct way to drive an LED using 74HCxx logic

digital-logicled

What is the correct way to connect an LED to a logic circuit?

The obvious thing to do is this:

schematic

simulate this circuit – Schematic created using CircuitLab

I have two concerns:

  • Can the logic gate's output actually deliver enough power to drive the LED? (Sure, LEDs are very low-power. But so are logic gates!)
  • Will the load from the LED distort the output so much that I can't connect it to any other gates?

The second problem looks like it ought to be trivial (if inconvenient) to solve:

schematic

simulate this circuit

Now only the output of the buffer has to deal with the load from the LED; the AND gate is blissfully unaware that anything has happened.

Trouble is, I'm planning to use 74HCxx logic running at 5 V, whereas it looks like most LEDs want to run at ~2 V. Also, it appears 74HCxx can only supply up to 4 mA, whereas most LEDs seems to draw drastically more current than that.

So now what?

Perhaps I could use a resistor to work around the voltage difference. (My knowledge of analogue electronics is far too weak to know if that would work.) Alternatively I could just run all the logic at 2 V instead. (The 74HCxx series seems to support that.) All of which does nothing to solve the current problem.

Do I need one of the level-translating logic gates? Or do I need to build something even more elaborate than that?

Best Answer

The circuits you propose won't work (the LED will not light up) because you're trying to make the current flow through the LED in the wrong direction (reverse mode).

Also it is a must to use a series resistor. Yeah sure, it will work without a series resistor but that puts a lot of stress on the logic gate and the LED. Also without the resistor the current through the LED is very uncontrolled and that should be avoided.

Let's cut to the chase and let me show you how it is done:

schematic

simulate this circuit – Schematic created using CircuitLab

For this circuit D1 and D2 will light up when "signal" is high (one = 1 = +5 V)

Resistors R1 and R2 limit the current to about 3 mA when using a 5 V supply. For modern LEDs 3mA will be enough current. If you're using old LEDs you might need up to 20 mA and then it is better to use an additional transistor to make that current flow as logic gates aren't designed to supply such a current.