## Intro: Logic Gates - AND and OR

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.

## Step 1: Boolean Functions - AND Function

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”). The image above illustrates the state table for the AND function with inputs A and B as well as the resulting output.

## Step 2: Boolean Functions - OR Function

**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”). The above image illustrates the state table for the OR function with inputs A and B as well as the resulting output.

## Step 3: The Circuits

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

## Step 4: AND GATE Circuit

**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.

## Step 5: OR GATE Circuit

*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.

## Step 6: Transistors

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

For more electronics and robotics articles please visit my blog - http://killerrobotics.me/

It also contains articles on Development, Electronics, Gadgets and other cool things.

## 2 Discussions

3 years ago on Introduction

gotta love some logic gates! :)

Reply 3 years ago on Introduction

Thanks for the comment!