Introduction: Logic Gates With NPN Transistors

Hi guys, in this tutorial I will show you some NPN transistor based logic gates.

What you need
-A breadboard
-A bunch of 5k and 10k resistors, and transistors
-A LED
You can use any NPN type transistor (for example 2N3904, BC547, BC548, BC549 etc.)

These are basic circuits, so they can be improved (with diodes for reverse voltage protection, for example), or can be simplified (XOR, XNOR gates), but for start we will stick with these basic circuits.

These circuits are extremely easy to understand. I think if you know a little bit about NPN transistors, you will be fine.  The use of transistors for the construction of logic gates depends upon their utility as fast switches. When the base-emitter diode is turned on enough to be driven into saturation, the collector voltage with respect to the emitter may be near zero and can be used to construct gates for the TTL logic family.

I am going to show the logic gate's symbols, truth tables and schematics. I will also show this circuits on the breadboard. (As i mentioned before these are easy circuits, so on a breadboard I wont show them step-by-step) There is a small text and a gif for every logic gate.

I attached three images for beginners. The third image is the most important.

Step 1: NOT Gate

A NOT gate is often referred to an inverter. Inverters simply output the opposite as the input. When the input is forced to logic HIGH (1) the output is forced to logic LOW (0) and vice versa.

This is the easiest one.
For the NOT logic, there is only one transistor and the output is driven to the ground (LOW or 0) if it is conducting.

Step 2:

NOT gate on a breadboard

Step 3: AND Gate

The AND gate is a logic Boolean gate that represents multiplication in basic algebra. When both input to the AND gate are forced to a logic HIGH (1) level, the output will be forced to a logic HIGH (1) level. But if either of the inputs are forced to logic LOW (0) the output will be forced to a logic LOW (0). This is the equivalent of a multiplication statement where only Boolean variables are allowed.

For the AND logic, the transistors are in series and both transistors must be in the conducting state to drive the output high.

Step 4:

AND gate on a breadboard

Step 5: NAND Gate

A NAND gate is also referred to as a NEGATED AND gate. It is the opposite or inverse of a simple AND gate. With the AND gate the output was forced to a logic HIGH (1) only when both inputs where forced to logic HIGH (1), but with a NAND gate the output is forced to logic LOW (0) when both inputs are forced to logic HIGH (1) and the output is forced to logic HIGH (1) in all other situations.

For the NAND logic, the transistors are in series, but the output is above them. The output is high unless both A and B inputs are high, in which case the output is taken down close to ground potential.

In the simulator I accidentally used a 200Ohm resistor, but in reality you should use around 1K or something like that.

Step 6:

NAND gate on a breadboard

Step 7: OR Gate

The OR gate is a logic Boolean gate that represents addition in basic algebra. If either of the inputs or both inputs to a basic OR gate are forced to logic HIGH (1) the output is forced to logic HIGH (1). If both of the inputs are forced to a logic LOW (0) the output is forced to a logic LOW (0). This closely resembles the addition statement where only Boolean variables are allowed.

For the OR logic, the transistors are in parallel and the output is driven high if either of the transistors is conducting.

Step 8:

OR gate on a breadboard

Step 9: NOR Gate

A NOR gate is also referred to as a NEGATED OR gate. It is the opposite or inverse of a simple OR gate. With the OR gate the output was forced to logic LOW (0) when both inputs were forced to logic LOW (0) and the output was logic HIGH (1) in all other situations, but with a NOR gate the output is forced to logic HIGH (1) when both inputs are forced to logic LOW (0) and the output is forced to logic LOW (0) in all other situations.

For the NOR logic, the transistors are in parallel with the output above them so that if either or both of the inputs are high, the output is driven low.

In the simulator I used a 200 Ohms resistor, but you should use one around 1K.

Step 10:

NOR gate on a breadboard

Step 11: XOR Gate

A XOR gate is also referred to as EXCLUSIVE OR. With a XOR gate the output is forced to logic HIGH (1) when one input is exclusively forced to logic HIGH (1). If both inputs are forced to either logic LOW (0) or logic HIGH (1) the output is forced to logic LOW (0). This is similar to the OR gate with the exception of both input being logic HIGH (1).
As you can see I constructed this one with other gates. In this circuit I used a NAND, OR and an AND gate.

Step 12: XNOR Gate

A XNOR gate, like the XOR gate, is also referred to EXCLUSIVE NOR. With the XNOR gate the output is forced to logic LOW (0) when one of the inputs are exclusively forced to logic HIGH (1). If both of the inputs are forced to either logic LOW (0) or logic HIGH (1) the output is forced to logic HIGH (1). This is similar to the XOR gate but is inverted.
As you can see I constructed this one with other gates. I used two inverter, two AND and an OR gate in this circuit.

Step 13: Build Something! - SR Flip-flop

Now we know the transistor gates, lets make something with them. :) For example, here is an SR flip-flop. (SR latch)

When using static gates as building blocks, the most fundamental latch is the simple SR latch, where S and R stand for set and reset. It can be constructed from a pair of cross-coupled NOR logic gates. The stored bit is present on the output marked Q.
The output usually marked as Q, but sometimes it is marked as X, Y or F.

While the S and R inputs are both low, feedback maintains the Q and Q' outputs in a constant state, with Q' the complement of Q. If S (Set) is pulsed high (=when you push the button) while R (Reset) is held low, then the Q output is forced high, and stays high when S returns to low; similarly, if R is pulsed high while S is held low, then the Q output is forced low, and stays low when R returns to low.

Step 14:

First of all, build two independent NOR gate on your breadboard. (step 9) Do not connect both of their inputs the the push buttons, you only have to connect the A inputs of each gate.

Step 15:

Now connect the B inputs to the other NOR gate's output trough a 10k resistor.

Now we are ready, you made an SR flip-flop or SR latch.

When you press the button one, the Q LED goes out, and the Q' LED lights up. Then if you press the button two, the Q LED light up, and the Q' goes out. Technically you can store data with it, this is why we call it "latch".
You shouldt press the two buttons at once, its a forbidden state, it can make the flip-flop unstable.

Comments

author
whitsona made it! (author)2017-08-02

Thank you!! Wanted to show my Computer Science class how logic gates worked, but it has been 30 years since I did resistor sizing for a circuit in Freshman Physics. You saved the day. :-)

Instructable.png
author
PhạmL (author)2017-07-30

SR latch is different from flip-flop.

they are level-triggered, flip-flops are edge-triggered.

author
Fizik66 (author)2017-04-19

Hi,

Nice tutorial, but there are a few things that I think should be mentioned here.

1.) AND gate, also XOR and XNOR where AND gate is used.

there can be a problem when only B input is active
-
when this happens, the "base-emitter" of the "B" transistor acts like a
diode, so there is current flowing through emitter resistor (5k)
creating a voltage drop. In the example above we can calculate
approximate voltage drop:

typical base-emitter voltage drop of
saturated transistor is around 0.7V, so the remaining voltage (4.3V = 5V
- 0.7V) is distributed on base resistor (10k) and emitter resistor
(5k), which means approx. 1.43V voltage drop on emitter resistor which
is also the output voltage in this example and this is not close to
desired 0V for output in OFF state.
Now this example may work, but
it's not a good practice to do it like this. If done like in example,
then the emitter resistor should be smaller (1k) or the base resistor
should be larger - anyway, the resistors should be somewhere 10x size
difference (base vs emitter) or more to ensure the output voltage stays
low enough that the possible next logic gate input doesn't go ON when it
shouldn't.
An even better way is to use NAND gate and add a NOT gate to its output which also creates an AND gate.

2.) AND gate and OR gate.

There should be current limiting resistor for the LED diode.
when
output state is ON in these two examples, the only outcome here can be
either burned transistor or burned LED, unless you have a limited
current power supply which is low enough to not burn these elements.
for
most LED diodes a good value is 200 ohms (more is also ok, it's just
less bright). this resistor should be placed between gate output and LED
or between LED and ground - either way is fine.

Best regards

author
FelixN13 (author)2016-12-22

You ca use parity gates (I do believe that's what they're called) to construct an XOR.

The parity gate would be similar to the NAND, only the output being placed in between the two transistors, effectively giving you an AND gate with one inverted input. Two of these, each providing one of the two high outputs can then be piped through and OR gate. In fact I don't even know if the OR gate is needed, as, ut at the very least you could just use two diodes if need be.

As already mentioned, an AND gate with both inputs inverted is effectively a NOR gate. Likewise an XOR with one input inverted is and XNOR an vise versa, an AND gate with all inputs inverted is an OR gate, a NAND gate with one input inverted is and OR gate with one input inverted, and vise versa, and so on and so forth. Not really that complicated when everything is said and done.

Anyway, that's about it. Apart from a few slip ups, nice walk through.

author
SimoneBigMac (author)2016-11-14

instead of putting inverters in front of the two inputs of the AND, you could just use a NOR. also, on the XOR the bottom square is labeled as an AND, when it is actually an OR. My question is: What would you need to change if you were to power this with a 9v battery?

author
handrrez (author)2016-10-22

Hi! I was wondering how did the selection of the resistor values worked out?

author
SwathisriV (author)2016-10-12

very nice...can anyone say what should i do for the 5v power supply??

can i use 9v instead??

author
AliX2 (author)2016-10-04

Super.You have done great job.Easy to understand.

author
neumanngregor (author)2016-02-24

Very, very good instructable and with the Yenka simulation is easy to understand, you did a excellent job.

author
JRV31 (author)2015-11-02

Great instructable, I enjoyed building all the gates.

In you picture on the intro page you show the emitter and the collector reversed.

See the 2N3904 datasheet here: http://pdf.datasheetcatalog.com/datasheet/stmicroelectronics/8850.pdf

author
AjekiigbeD (author)2015-10-27

wonderful

author
zork the destroyer (author)2015-07-23

Your XOR is the only working configuration I have found. Now I may continue to build an ALU. Thank you.

temp_1124071305.jpg
author
CelloC (author)2015-05-29

I really like this instructable! The schematics are great! Just one thing though...I noticed that in the drawn picture you correctly labeled EBC but in the schematic/example at the top you swapped the emitter and the collector (if I'm not mistaken, the arrow pointing outwards is the emitter).

author
DanielSala (author)2015-04-30

Hi!

I only signed up to Instructables so I could thank you for a great logic gate collection.

You deserve a medal for this Instructable page! Thanks for a really great tutorial on logic gates. Not only are your gates minimal component, but also you don't use PNPs, which I personally appreciate. Many schematics I've seen on the Internet require PNPs and NPNs in large amounts - double or triple what you have used to achieve the same result... And something else to be equally appreciated is that the instructions and the diagrams are very clear and helpful to follow - you have no obscure connections with missing dots or those "Guess what pole you need to connect it to" style inputs or outputs, which can be quite frustrating for beginners.

I made all your gates from this Instructable two months ago, and have kept the breadboard as a reference, and also just because it was such a good experience - thank you.

Today I have started to do these gates using Mosfets (I need an NMOS XOR for something I want to make), and so far they all transfer with little effort (some resistor values change).

Thanks for your great Instructable.

author
Ploopy (author)2015-04-11

Cool!

Did you now that you can build RS-NOR Latches(SR latches) even in Minecraft using redstone!?

th (1).jpegth.jpeg
author
ac.ananya (author)2015-01-25

how do i earth the wire? i am not using a breadboard! please i need to know this urgently!

author
Marzogh (author)ac.ananya2015-04-08

Take the ground/earth wire and connect it to your battery's negative terminal.

author
HOWITZER (author)2015-01-23

wow!! this is so cool, i´m electronic engineering student (10°) and also i've never built transistor-based-gates, it's more fun to do while vacations ^_^ .

author
JRV31 (author)2015-01-23

Great instructable, I built all the gates. I have used the ICs but I had never built them from transistors before. I made a mistake wiring the XNOR gate. I connected the output of the inverter to both and gates. It took me a long time to find it. it's 2:30 AM, I'm going to bed. I'll make the latch tomorrow. Thank you.

author
loukas.logginos (author)2014-09-25

I made the not gate but I don't understand why the led is turning off, we haven't got voltage at led when closing the base? If no why? By the way very good project and usefull. Thanks

author
Shmueli (author)2014-08-02

You never know when your project might need one or two bits of memory.

author
iruwl (author)2014-07-05

this is what I need,, thk..

author
lwoollett (author)2014-03-24

I was wondering what software you used for your circuit diagrams? I'm sure I've seen it before but can't remember the name of it. Great instructable, I'm just getting started with electronics and it's an interesting read.

author
Szabolcs (author)lwoollett2014-03-25

Hi! I used Yenka. It is free for home use.
http://www.yenka.com/

About This Instructable

150,936views

147favorites

License:

More by Szabolcs:Logic Gates with NPN transistorsDIY mini drill
Add instructable to: