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.

6 thoughts on “Gates, Build Gates not Bill Gates”

1. ElectronicsTech says:

Great Article!!

Liked by 1 person

2. Good article, it would be nice to see the schematics as well as the Fritzing diagrams

Liked by 1 person

1. JR says:

Noted, I will add the schematics. Thank you for the feedback.

Like

3. Ray says:

Just found your blog today, it’s nice to see an understandable electronics/robotics/programming blog that doesn’t require a Masters of Engineering to figure out yet still treats you like you have a brain. I appreciate that quite a bit.

Great article, I like both the Fritzing and the schematic views! The large blow-up views are great too. I really appreciate the clean gate illustrations that make the function obvious Too many illustrations I’ve seen in other places tend to be overly complicated, with several extraneous parts that muddle the concepts a bit. I think the way you did it makes the idea accessible to people that aren’t experienced with schematics.

I do have a point I don’t understand: Aren’t current limiting resistors usually in series with the LED? I noticed this one looks like it’s in parallel and I don’t quite understand what’s happening there.

Thanks, and I’m off to enjoy the other articles.

Liked by 1 person

1. JR says:

Hi Ray,
Thank you for your great comment. The main purpose of the resistor in parallel to the resistor is to split the current, thus protecting the LED from an overload. This is most relevant to the OR gate circuit as pressing both buttons simultaneously results in double the current entering the circuit.

Like

4. Ray says:

Thank you for the quick and direct answer!
That’s the first time I’ve run across the current splitting idea for LEDs, in retrospect it’s obvious enough an idea that I’m a little embarrassed I didn’t realize what it was. I’ll have to breadboard it up and play with it some myself.

P.S. Great site, many different subjects and ideas to look through. You’ve been bookmarked!

Liked by 1 person