11
\$\begingroup\$

I'm building an AND gate out of transistors. Knowing how the basics work, I built my own (naive) circuit using the following design.

Simple 2 transistor circuit

In testing, it didn't work like an AND gate.

A B LED
0 0 Off
1 0 Off
0 1 Weakly on
1 1 Strongly on

I googled around the internet, and found another circuit that had two grounds.

better and gate with transistors

In testing, it worked like I'd expect an AND gate would. The LED only shining when both A and B are pressed. But if either were off, the LED was dark.

Why was the second ground needed to make my AND gate function correctly?

For my first circuit, when A was off and B was on, where was the current/voltage to power the LED (weakly) coming from? Since the path from +5v to ground was (seemingly) blocked by transistor A?

\$\endgroup\$
7
  • \$\begingroup\$ I think typically a gate like an AND gate has a clearly defined output (to be standardized and easy to work with), and in the second schematic you see that output with a diode LED that is then connected to its own ground unrelated to the gate. In your own design, you instead attach the output in series with the ground for the gate, rather than in parallel to it. \$\endgroup\$
    – BipedalJoe
    Aug 3 at 1:51
  • \$\begingroup\$ @BipedalJoe Is the clearly defined output a matter of convention? Or does it fundamentally change the design of the circuit? And what about connecting it in series rather than in parallel cause it to give a different output? \$\endgroup\$ Aug 3 at 2:01
  • 1
    \$\begingroup\$ Probably both. In your design, the current is coming from the base that B is connected to, so, it is coming from B. Typically gate current is very weak. The reason the diode turns on, is because it acts as a strong resistance until it becomes forward biased, and there is nowhere else for the current to go. In the other schematic, the current can escape down to the ground of the transistor. Does that seem like it may be why? \$\endgroup\$
    – BipedalJoe
    Aug 3 at 2:11
  • \$\begingroup\$ Yes, that makes sense. I had assumed that my diode wouldn't leak current, so I was baffled about the result. But knowing now that it does, it makes sense why having the straight to ground is helpful in my circuit. Thank you. \$\endgroup\$ Aug 3 at 2:15
  • 1
    \$\begingroup\$ the battery is connected backward in both circuits ... the battery is also missing a ground connection ... the circuits will not work when only the negative battery terminal is connected ... also, the two inputs do not connect to anything \$\endgroup\$
    – jsotola
    Aug 3 at 4:21

3 Answers 3

19
\$\begingroup\$

In your first circuit, when A was off and B was on, the LED is weakly ON because of the base current of the BJT (flows from base to emitter to the LED).

In your second circuit, when A was off and B was on, the 5k resistor provides the path to the base current; provided it was designed such that the voltage across the 5k resistor is less than the diode cut-in voltage. This is the advantage of the second circuit which cuts off the LED current for this scenario provided the resistor values are designed correctly.

P.S: Note that the second circuit has only 1 ground. The correct terminology to use to describe it is that the 5k resistor and the LED are in parallel here.

\$\endgroup\$
5
  • \$\begingroup\$ So the BJT transistor "leaks" some current through the emitter when the base is on? (excuse my terminology if that's not the correct to describe it) Okay, I had assumed no current flowed from the base to emitter. Thank you for your answer. \$\endgroup\$ Aug 3 at 2:10
  • 5
    \$\begingroup\$ Base-emitter is a diode. So, when base-emitter voltage is higher than the cut-in voltage, a base-emitter current will flow. \$\endgroup\$
    – sai
    Aug 3 at 2:12
  • 1
    \$\begingroup\$ @MorganKenyon You misunderstand how a BJT transistor operates: the BE potential difference causes current to flow through the emitter, but most of that current usually travels right through the base and gets sucked up by the collector instead, leading to current amplification because the BE voltage causes much less actual base current than collector current. If the collector is disconnected, all of the emitter current does go through the base. Or viewed the other way round: the base current is not amplified but instead is identical to the emitter current. \$\endgroup\$
    – user107063
    Aug 3 at 11:56
  • \$\begingroup\$ @MorganKenyon All of the base current must go somewhere. It has two choices: collector or emitter. Given that the emitter is at the lower potential, it flows there. That transistor doesn't leak "some" base current. It has to "leak" all of it. If a current flows into a box, it must flow out of that box on some other terminal, or the currrent wouldn't flow to start with. \$\endgroup\$ Aug 4 at 18:05
  • \$\begingroup\$ @MorganKenyon So the BJT transistor "leaks" some current through the emitter when the base is on? In a MOSFET, the gate is insulated and the transistor is controlled by a voltage alone. In a BJT, the base is not insulated and it always looks like a diode. To control the BJT, you must "push" a small current into it. Since bipolar logic is largely obsolete, most digital logic books are written with MOSFET in mind, not BJT. If you want to go retro and learn the basis of bipolar logic, a good book is the RTL Cookbook from the 1970s. \$\endgroup\$ Aug 6 at 0:21
19
\$\begingroup\$

There is no "second ground". The ground symbol is a way of de-cluttering schematics. When you see the same symbol used in multiple places in a schematic, they are indicating the same electrical connection, or "node". The ground node has so many connections to it (perhaps hundreds) that a dedicated symbol is used instead of many of connection lines to a single point, which would make a schematic very difficult to read and understand.

We interpret that symbol to mean that it is physically connected to every other point in the circuit with the same symbol, and it is declared to have zero volts (0V) of potential. Every other node's potential in the circuit will be measured and quoted with respect to this "ground" reference point.

It is possible to have multiple independent grounds in a single circuit, but they will each use their own symbol to distinguish them from the others, such as these:

enter image description here

In your circuit, there is only one electrical node in the circuit which we call "ground" or zero-volts, because there is only one ground symbol repeated twice. They both refer to the same point in the circuit, because they are the same symbol, and they are physically joined with wires or PCB traces or other conductive path. These two circuits are identical:

schematic

simulate this circuit – Schematic created using CircuitLab

The above circuit (which is your second design) is bad, and can damage the LED or transistors. When both transistors are on, LED D1 will effectively be connected directly across the power supply, with nothing in the loop to limit current. Your first design is better, since current is always constrained by the 5kΩ resistor.

It's still not great though. The base-emitter junction of a bipolar junction transistor (BJT) behaves just like a diode (because that's what it is). In your schematic, when the lower input B rises in potential, that transistor will conduct current entering via its base, and leaving via the emitter, regardless of the state of the upper transistor:

schematic

simulate this circuit

That means a high input at B, to the lower BJT in your schematic, will cause the LED to glow regardless of the state of the upper transistor, which is not ideal if you are trying to implement an AND gate. It still amazes me that people publish this design claiming that it will work as an AND gate. It nearly does, and I suppose it illustrates the working principle of an AND gate, but it is a deeply flawed design.

It can be made to work, but one must take great care to ensure that base current is very, very small, compared to load (LED) current that would flow if both transistors were switched on. That is, R2 and R3 should be much greater than R1, greater by a factor of at least 10. Just be aware that an LED will glow even if the current through it is mere microamps, and therefore doesn't make a very good indicator of "on" or "off" state in this application. The circuit would work, however, with careful choice of resistor ratios. I recommend that you determine output state by measuring output potential (with respect to ground), instead of using an LED:

schematic

simulate this circuit

This design does have one redeeming feature: it forces you to consider and study the caveats of using BJTs, such as:

  • The difference between common-collector (used here, otherwise known as "emitter follower"), and common-emitter configurations.

  • The often inconvenient diode behaviour of the base-emitter and base-collector junctions.

  • The usefulness of Kirchhoff's Current Law (KCL), which you have experienced here as collector current and the problematic base current, both of which emerge at the emitter, as the sum of the two.


Update

There are plenty of sites covering implementation of TTL and DTL logic gates, which you can find with a Google search for "DTL logic" or "TTL logic" such as:

Transistor–transistor logic on Wikipedia

TTL Logic Circuit Operation

DTL on Electrical4U

A search for "CMOS logic" will yield sites like this, showing how to implement logic gates using MOSFETs:

CMOS Gate Circuitry (AllAboutCircuits.com)

Here are some other answers that I have written covering quite a lot of material with regard to building discrete BJT logic units like yours:

Integrating an AND gate into another logic gate

Logic gate: electricity, voltage and meaning

Probably the most apposite: How do I make an AND gate from transistors?

\$\endgroup\$
4
  • \$\begingroup\$ Yes, I was curious about the LED not being protected by a resistor, but that is what I had found in multiple places, thanks for pointing that out. The only one ground also makes sense now that you say it, I just haven’t had as much electronics experience so was explaining my circuit poorly. Thank you. \$\endgroup\$ Aug 3 at 11:44
  • \$\begingroup\$ Do you know of a site/resources that does a good job of presenting how to build basic logic gates? \$\endgroup\$ Aug 3 at 11:48
  • \$\begingroup\$ @MorganKenyon I have updated the answer with some links to other answers I wrote on this site, which address this topic, and some example pages I found using Google. \$\endgroup\$ Aug 3 at 12:34
  • \$\begingroup\$ Thank you for including the links. \$\endgroup\$ Aug 3 at 15:08
4
\$\begingroup\$

As drawn, the behaviour of the circuit is not well defined, because when the switch is open, the base of the transistor just floats. Usually this will cause the device to be weakly off, but you might get enough current to have the LED glow dimly. It can vary from one device to the next of the same type.

To make sure that it really turns off, you want a pull down resistor on the base. Then you will get proper AND behaviour. (Also, what are the left hand side of the switches connected to? I assume +5V.)

Also note that the second circuit has problems (no LED series resistor) as others have already pointed out.

\$\endgroup\$
4
  • \$\begingroup\$ Yes, A and B are connected to 5v as well. I get now that the circuit design can be improved. But all across the internet that is generally how I’ve seen AND gates written, so followed that circuit design. \$\endgroup\$ Aug 3 at 11:49
  • \$\begingroup\$ I can assure you that this is the problem. If you want to find out using your own eyes, try connecting another resistor (47k should work) from the base of each transistor to ground, and test things again. Or of course, you can carry on believing "across the internet" if you wish, that's your choice. \$\endgroup\$
    – danmcb
    Aug 3 at 13:09
  • \$\begingroup\$ What resource would you recommend that teaches proper electronics? \$\endgroup\$ Aug 4 at 2:13
  • \$\begingroup\$ the best all round text I know is Horowitz and Hill. But for this you only need to know basic bipolar transistor operation. this is helpful electronics.stackexchange.com/questions/215110/… \$\endgroup\$
    – danmcb
    Aug 4 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.