# Gates, Build Gates not Bill Gates

The basis of building any logic circuit (even one as complex as a computer) comes down to logic gates. I will be discussing the 2 most basic logic gates today, an AND gate and an OR gate.

Logic gates are physical circuits that implements boolean functions, so to start let us look at the boolean AND and OR functions.

For all the examples below let us assume that we have 2 inputs: A and B, and that A and B both have 2 possible states: on or off, 1 or 0 in binary terms.

AND Function

An AND function requires both A and B to be in an “on” state to give a positive “on” result. (Just note the NAND function will give a positive “on” output when A and B are NOT both “on”. We will look at the NAND function and gate in detail at a later time).

Below is the state table for the AND function with inputs A and B as well as the resulting output:

 A B Output 0 (off) 0 (off) 0 (off) 1 (on) 0 (off) 0 (off) 0 (off) 1 (on) 0 (off) 1 (on) 1 (on) 1 (on)

OR Function

An OR function requires either A or B  (or both) to be in an “on” state to give a positive “on” result. (Just note the NOR function requires neither A or B to be in an “on” state to give a positive “on” result. Additionally the XOR function will give a positive “on” output only when A or B are “on” but NOT when both are “on”. We will also look at the NOR and XOR functions and gates in detail at a later time).

Below is the state table for the OR function with inputs A and B as well as the resulting output:

 A B Output 0 (off) 0 (off) 0 (off) 1 (on) 0 (off) 1 (on) 0 (off) 1 (on) 1 (on) 1 (on) 1 (on) 1 (on)

Now let us examine the gate circuits. (I have constructed both gates on a Adafruit Perma-Proto board shown in the picture below).

AND Gate:

Parts required:

• 3  resistors (10k Ohm will do)
• 2 push buttons (input A and B)
• 2 BJT NPN transistors
• 1 LED (output)

So by pushing the buttons in accordance to the AND state table above the outputs can be recreated. Because the 2 transistors are placed in series the circuit can only be completed when both button A and B are pressed, and thus the AND function is implemented.

OR Gate:

Parts required:

• 3  resistors (1 x 10k Ohm and 2 x 660 Ohm resistors will do)
• 2 push buttons (input A and B)
• 2 BJT NPN transistors
• 1 LED (output)

So by pushing the buttons in accordance to the OR state table the corresponding outputs can be recreated. Because the 2 transistors are placed in parallel the circuit can be completed by pressing either the A or B button (or both). The circuit thus represents the OR function.

Just note the selection of resistor sizes are not cast in concrete, just pick a resistance high enough so your transistor does not get fried based on your power supply size (in my case a 9 Volt battery). I simply chose the resistors based on what I had available at the time.

Additionally if the role of the transistors in the circuit does not make sense to you please look at my earlier post (TRANSISTOR CRASH COURSE) that explains the functioning of transistors and their roles in circuits.

# Transistor Crash Course

Today we will run through a brief overview of the two main variations of transistors commonly used in circuits, NPN and PNP transistors.

It is critical to understand the basic functioning of these transistors to understand any circuit of moderate complexity.

The first thing to note is that the basic function of transistors is to control the flow of current through a circuit.

Both the NPN and PNP transistors have 3 leads or legs, the Base, Emitter and Collector. The main difference between NPN and PNP transistors is how they control the flow of current.

If we imagine the current flowing through a circuit being water flowing through a pipe, a transistor would act like a faucet or tap. It can control the water going through it by opening or closing its valve.

And this is where the NPN and PNP transistors differ. A NPN transistor is closed by default, not allowing current to flow from its Emitter leg to its Collector leg, and will only allow current through when it is “opened” by applying a small amount of current to its Base leg, whereas the PNP transistor is open by default, allowing current to flow from its Emitter leg to its Collector leg, and applying current to its Base leg “closes” it thus stopping the flow of current between the Emitter and Collector.

Below are the schematic symbols for the 2 transistors:

Where the numbers represent:

1 – Base
2 – Emitter
3 – Collector

On an unrelated topic, I use open source software called Fritzing for all my electronic schematics and drawings. It is a great piece of software and can be downloaded from www.fritzing.org.