Projects

Kids' Basics - Logic Gates

Using transistors

Daniel Koch

Issue 56, March 2022

Most logic gates are bought as Integrated Circuits (ICs), but to take a Kids’ Basics-level look at them, we make our own!

Logic gates are at the core of digital electronics, but they are a little mystifying at first glance if you’re unfamiliar with electronics in general. For this month’s Kids’ Basics, we’re going to build some logic gates without digital integrated circuits (ICs) so you can easily see how they work, and experiment with them. We will also explain them in very beginner-friendly language, along with the terms and words that you will read and hear when dealing with digital electronics.

RATIONALE

There are several ways to model digital gates from non-digital components. Many examples online use diodes, and the ‘input’ is a connection to ground. We found that this could be confusing to younger or less-experienced makers, because most of us think of ‘inputs’ as an active thing where you know a voltage is going into a certain point. Having a connection to ground almost feels like an output, with current flowing out of it to ground from the gate. Many people don’t think of it as active, either. For those experienced or electronically minded, that feeling doesn’t seem to occur.

Therefore, all the circuits we have made here are designed so that the probes connect to the supply voltage in order to give an ‘input’. The circuits are only demonstrators. You cannot use all of them as functional gates in other circuits, because they depend on current only flowing through the places we want it to. Adding another circuit will give another current path.

The idea of these circuits is to show how digital gates operate in terms of inputs causing change at outputs, in a way where you can easily follow the circuit operation. Real gates work the same way in terms of inputs causing changes in outputs, but are far more complex inside so that overall behaviour cannot be changed by how the output is connected.

HOW TO USE IT

This circuit is a bit different from any we have made before. To use each logic gate, you will need to connect probes to the positive supply rail. Rather than try to describe this all at once, we have written the operation of each gate into the first couple of lines of each part of the ‘How It Works’ section. Even if you are brand new to electronics and aren’t ready to try to follow how the circuit itself works in theory, you can read just the first line or two and know how to make each circuit section work.

SOME HELPFUL HINTS

You will need some basic hand tools for most builds. Small long-nosed pliers and flush-cut side cutters meant for electronics are the main ones. Materials like tape or glue may be mentioned in the steps, too. We always produce a tools materials list if you have to go shopping, but anything that is lying around in most homes is just stated in the steps.

As always with Kids' Basics, we avoid soldering to make the build more accessible to more people, but having an adult around can still be helpful. You won't need any particular skills besides being able to identify components at a basic level, and even then, we help as you go along. If, for example, you don't already know what a resistor is, you'll probably be able to work it out from the photos and description in each step.

We do provide a schematic or circuit diagram but this is just helpful if you already know how to read one. Don’t stress if you have never learned, but take the chance to compare the digital drawing of the breadboard layout (which we call a 'Fritzing' after the company that makes the software) to the schematic and see if you can work some things out.

You can make this project from the Fritzing and photos alone. You might also like to check out our Breadboarding Basics from Issue 15. Having said that, this month, the point is explaining digital logic gates, so we’ll refer to the circuit diagram quite a lot in the ‘How It Works’ section.

The Build:

Parts Required:IDJaycarAltronicsPakronics
1 x Solderless Breadboard-PB8820P1002DF-FIT0096
1 x Packet Breadboard Wire Links-PB8850P1014ASS110990044
7 x Plug-to-Plug Jumper Wires*ProbesWC6024P1016SS110990029
5 x 150Ω Resistors*R3, R6, R8, R10, R12RR0552R7538SS110990043
7 x 1kΩ Resistors*R1, R2, R4, R5, R7, R9, R11RR0572R7558SS110990043
4 x 1N4148/1N914 Small Signal Diodes*D1, D2, D3, D4ZR1100Z0101DF-FIT0323
1 x Red LED*LED2ZD0150Z0800DF-FIT0242
1 x Green LED*LED1ZD0170Z0801DF-FIT0242
1 x Blue LED*LED5ZD0185Z0869DF-FIT0242
1 x Yellow LED*LED4ZD0160Z0802DF-FIT0242
1 x White LED*LED3ZD0190Z0708DF-FIT0242
7 x BC547 NPN Transistors* %Q1, Q2, Q3, Q4, Q5, Q6, Q7ZT2152Z1040DF-FIT0322

Parts Required:

* Quantity used, item may only be available in packs. % We used BC547s. Any small NPN General Purpose Bipolar Transistor will work. Use 2N3904 from Pakronics pack. # 150Ω Not in kit but 220Ω will work fine.

Step 1:

Place the breadboard in front of you with the outer red (+) rail furthest away from you, and the outer blue (-) rail closest to you. Add two wire links, one to join the two blue (-) rails and one to join the two red (+) rails

Step 2:

Install a 150Ω (BROWN GREEN BLACK BLACK SPACE BROWN) resistor between the upper red (+) rail and the second row of the breadboard. Add a green LED with its long anode (+) leg to the resistor and its short cathode (-) leg in the next row.

Step 3:

Insert two BC547 NPN transistors with the flat sides facing you. One has its left-hand (collector) leg to the short cathode (-) leg of the LED. The right-hand (emitter) leg of the first transistor goes in the same row as the collector (left-hand leg) of the second transistor.

Step 4:

Add two 1kΩ (BROWN BLACK BLACK BROWN SPACE BROWN) resistors, one to the centre (base) leg of each transistor. When you bend the legs, make sure the resistors end in their own rows and not the same row. Also, add a wire link between the right-hand (emitter) leg of the second transistor, and the upper blue (-) rail.

Step 5:

Insert a red LED with its short cathode (-) leg to the left, and a wire link between there and the upper blue (-) rail. Also add a 150Ω (BROWN GREEN BLACK BLACK SPACE BROWN) resistor from the upper red (+) rail to the long anode (+) leg of the LED.

Step 6:

Place two BC547 NPN transistors with the flat sides facing you. One has its left-hand (collector) leg to the long anode (+) leg of the LED. The right-hand (emitter) leg of the first transistor goes in the same row as the collector (left-hand leg) of the second transistor.

Step 7:

Add two 1kΩ (BROWN BLACK BLACK BROWN SPACE BROWN) resistors, one to the centre (base) leg of each transistor. When you bend the legs, make sure the resistors end in their own rows and not the same row. Also, add a wire link between the right-hand (emitter) leg of the second transistor, and the upper blue (-) rail.

Step 8:

Install a white LED with its short cathode (-) leg to the left, and a wire link between there and the upper blue (-) rail. Also add a 150Ω (BROWN GREEN BLACK BLACK SPACE BROWN) resistor from the upper red (+) rail to the long anode (+) leg of the LED.

Step 9:

Insert a BC547 NPN transistor with its flat side facing you and its left-hand (collector) leg in the same row as the resistor and LED anode. Add a wire link between the right-hand (emitter) leg of the transistor and the upper blue (-) rail, and a 1kΩ (BROWN BLACK BLACK BROWN SPACE BROWN) resistor from the middle (base) leg of the transistor, to the right.

Step 10:

Place a yellow LED with its long anode (+) leg to the left and a 150Ω (BROWN GREEN BLACK BLACK SPACE BROWN) resistor from the lower red (+) rail to the anode of the LED. Add a BC547 NPN transistor with the flat side facing you and the left-hand (collector) leg in the same row as the short cathode (-) leg of the LED.

Step 11:

Add a 1kΩ (BROWN BLACK BLACK BROWN SPACE BROWN) resistor to the centre (base) leg of the transistor, and a wire link from the right-hand (emitter) leg of the LED to the lower blue (-) rail. Insert two diodes with both cathode (-) ends, marked with a stripe, to the resistor but the anodes of each diode in their own row.

Step 12:

Insert a blue LED with its short cathode (-) leg to the left and a wire link between there and the lower blue (-) rail. Add a 150Ω (BROWN GREEN BLACK BLACK SPACE BROWN) resistor from the long anode (+) leg of the LED to the lower red (+) rail.

Step 13:

Install a BC547 NPN transistor with the flat side facing you and the left-hand (collector) leg to the LED anode and the 150Ω resistor. Add a wire link between the right-hand (emitter) leg and the lower blue (-) rail.

Step 14:

Place a 1kΩ (BROWN BLACK BLACK BROWN SPACE BROWN) resistor to the centre (base) leg of the transistor. Add two diodes with both of their cathode (-) ends (marked with a stripe) to the 1kΩ resistor, but the anode of each in its own row.

Step 15:

Carefully place five plug-to-plug jumper wires along the top section. One goes to each of the 1kΩ resistors. In the lower half, another four jumper wires go to the ends of each diode. For now, all opposite ends of jumper wires are left free. Connect the red wire of a 4 x AA battery pack to the upper red (+) rail and the black wire to the lower blue (-) rail.

Step 16:

Install four AA batteries in the battery pack. The red, white, and blue LEDs should turn on, while the green and yellow LEDs should be off. If this is not the case, pull the batteries out and check all of your connections. If only one LED is not behaving the way it should, you can check just that area of the circuit for now.

HOW IT WORKS

What we have built here is really five independent circuits on one breadboard. We will describe each in detail with its operation, but first, there are some general points to cover. One of the biggest challenges for people new to digital electronics is the terminology. There is some language used in digital electronics that, while not only used for digital, is far more common here than in other areas of electronics. The opposite is true, too: You will hardly ever talk about voltages or currents in a digital circuit, once you have the correct circuit voltage set up. Because of this, we have added a glossary that goes with this article, which you can find on our website.

THE INS AND OUTS OF INPUTS AND OUTPUTS

Inputs and outputs in digital circuits need a little explaining. The terms ‘high’ and ‘low’ are used most commonly today, while ‘1’ and ‘0’ are still around. What does this actually mean? Digital circuits have only two states: On or Off. However, an input does not have to be at the full supply voltage to be high, and at completely zero to be low. When it comes to digital integrated circuits (ICs), the datasheet that manufacturers publish for each device will have the information. Generally, there is a voltage below which an input is ‘low’, and a voltage above which an input is ‘high’. In the middle is a gap that should be avoided. In most digital circuits, this is automatically avoided because everything runs on the same two voltages. However, it is something to think about if you are using input voltages from, say, another circuit which could change or have losses.

In the simplest terms, a voltage below half the supply may be considered low, while anything above half would be high. In reality, each device will have its own numbers and sometimes, anything above 0.7V is high. Our circuits are not actually digital, but we make them behave that way because we only use the inputs with the supply rails at full supply voltage or ground. If you feed a variable voltage to the inputs on our circuits, you would find a point where the transistor responded and the LED slowly increased or decreased in brightness.

The ‘probes’ we talk about here are the ends of the jumper wires left loose in the build. We are using ‘H’ for ‘High’ and ‘L’ for ‘Low’ in the truth tables.

AND GATE

The AND gate is the one with the green LED. To use it, both inputs have to be ‘High’. Take one of the probes and plug it into the upper red (+) rail. Nothing should happen until you plug the other probe into the upper red (+) rail as well. Then, the LED should light. An AND gate needs both input ‘A’ AND input ‘B’ high for the output to be high. The truth table shows this.If reading truth tables is new to you, they tell the story line by line. For example, the top line shows input A as L and input B as L. this gives the result at the output of L. In other words, whatever combination of inputs is shown, gives the output at the end of that row. The bottom row shows both input A AND input B high, so the output is high.

Input A

Input B

Output

L

L

L

L

H

L

H

L

L

H

H

H

The circuit works this way because the probes are each connected to the base of an NPN transistor by a 1kΩ resistor. For the LED to light, current has to flow through the 150Ω resistor and the LED, and across both transistors. To recap, transistors are a current amplifying device. The ‘base’ terminal controls the current flowing between the emitter and collector. In an NPN transistor, current flowing into the

base allows a much larger current to flow from the collector to the emitter. The base current flows out the emitter and must go to ground.

All transistors have a minimum amount of base current that must flow for any collector current to flow to the emitter. Then there follows a point where collector current is a certain number of times bigger than the base current (a different number of times for different transistors). After that, the transistor is ‘saturated’, and the maximum amount of collector current is flowing to the emitter. There is also a maximum base current, and that’s what the 1kΩ resistor is for. It limits the current into the base to a safe level to avoid damaging the transistor.

The reason that we can get digital behaviour (on or off with nothing in between) from these transistors is that at 6V supply voltage, the 1kΩ resistor gives us 6mA to the base of the transistor, more than enough to fully saturate it. The only other state the probes can exist in is at 0V, either unplugged or plugged into the ground (-) rail, which fully turns off the transistor.

Because we have two NPN transistors in series (one after the other), both have to be conducting to complete the circuit. If you take the probe of the first one to the positive supply rail, the transistor conducts, but the current still cannot get to ground to complete the circuit, because the second transistor is not conducting. The same goes if you have the second one conducting, but not the first. The LED represents the output, and this is only a demonstration circuit. You can not really drive another gate or circuit with this. If you try to take an output from between the LED and first transistor, you will either not have enough voltage (remember, the LED has a minimum voltage that is ‘dropped’ across it) to be a proper high, or you will give the current another path to ground through the other circuit, and the LED may light anyway.

NAND GATE

The NAND gate is the circuit with the red LED. To use it, input A AND input B must be high for the output to be low. If either input A or input B are low, the output will be high. So, connecting both probes to the supply rail turns the LED off, but if only one probe is connected, the LED still lights.At first glance, the circuit is nearly the same as the AND gate. That’s true. Look closely, however, at the LED connection. With no probes connected, current flows through the 150Ω resistor and the LED to ground. The two transistors are not conducting. If only one transistor is turned on by the probe being connected to the supply voltage, there is still no current path. Only when both transistors are turned on is current able to flow across the pair.

Input A

Input B

Output

L

L

H

L

H

H

H

L

H

H

H

L

When this happens, the path across the two transistors is a much lower resistance than the path through the LED, which has a higher forward voltage. Therefore, as soon as they are both saturated, the current flows through them and the LED turns off. Transistors will burn if too much current passes through them, but the 150Ω resistor takes care of that. So, as with the AND gate, the current flow is not like a NAND gate if you buy one as an IC, but the behaviour of the inputs and outputs is.

NOT GATE

The NOT gate is the simplest of all, and has a white LED. To use it, connect the only input to the supply rail. The LED turns off. Take it out, so that the input is low, and the LED turns on. The output is NOT equal to the input. In other words, the output is the opposite of the input, and this is also known as an inverter. We tend to use the term ‘NOT gate’ partly to keep things consistent, and partly because there is also an analogue inverter, which will take a voltage at its input and change its polarity for an output. That device is proportional, which means that it will work at any voltage, not the ‘on’ or ‘off’ we expect from a digital circuit.It operates in much the same way the NAND gate does, except it has one input to one transistor. If the input is connected to ground or left free, giving a ‘low’, the current flows through the 150Ω resistor and the LED, to give an output. As soon as there is a high on the input, the transistor conducts, and the current flows straight to ground and not through the LED. The LED turns off, representing a ‘low’.

Input

Output

H

L

L

H

OR GATE

The OR gate, with the yellow LED, almost seems pointless at first, and there are even easier ways to make one than this. We just wanted to stick with a transistor. To use it, the output will be high, shown by the LED lit up, if input A OR input B OR both are high.The inputs are the probes again, but this time they have diodes before the resistor on the base of the transistor. This is because you can connect one input, OR the other, OR both. The diodes stop current flowing back so that you know that the other probe will not be live if it contacts anything while you experiment.

Input A

Input B

Output

L

L

L

L

H

H

H

L

H

H

H

H

Without the diodes, current could flow down one probe, then back up the other if it was making contact with another part of the circuit. They also help you know that current cannot feed back if you were to use two different sources of voltage for the inputs, like experimenting with connecting the gates together.

This one is really straightforward. If current flows down either probe, the transistor is saturated and conducts current, lighting the LED.

NOR GATE

The NOR gate with the blue LED is the opposite of the OR gate. To use it, both probes must be low for the output to be high. If input A OR input B Or both are high, the output will be low. To put it another way, for the output to be high, neither input A NOR input B NOR both can be high.Much like the NAND and NOT gates, the transistor actually diverts the current away from the LED when it becomes saturated by either input being high, because of its lower internal resistance. The LED is only lit when none of the inputs are high.

Input A

Input B

Output

L

L

H

L

H

L

H

L

L

H

H

L

REMEMBERING THINGS

That all sounds a bit crazy! But it can be easier to remember than you think. Remember this: AND means A AND B. OR means A OR B OR both. N means opposite. So, the output of a NAND will be the opposite of an AND for the same inputs. The same for an OR vs NOR. Some people also remember it by: Either, Or; Neither, NOR. Then the others follow the theme.

WHERE TO NEXT?

There isn’t much you can do with these circuits as they are. Our suggestion is rather to buy some dedicated IC gates, where the outputs are not electrically affected by what is connected to them. If you buy an IC NAND gate, for example, you can connect the output to another gate, and nothing will change. If you connect the output of this transistor NAND gate to something else, there is suddenly (maybe) another current path and the LED will not behave the same.

When shopping for logic ICs, stick with the 74LS and 74HS series. They are more rugged, powered by 5V (so don’t use four AAs but you can happily use a USB battery pack or plugpack), and not as static-sensitive as 4000-series CMOS ICs.

You will find them listed often as things like ‘quad two-input AND gate’. This means that each has two inputs, and there are four in one IC package. You might also find a dual four-input AND gate, which means each gate has four inputs (and yes, all four have to be high for the output to be high), and there are two in each package.

Each IC will have its own voltage supply and ground connections, which are shared internally to all the gates.

You will also have to look at the datasheets, which can be really overwhelming. Don’t worry too much, Just look for the truth tables, and the diagram showing you which pin is which on the IC. Sometimes, the pins are not next to each other.

For example, input A may be on one side, input B on the other, and the output further away. This is just because of internal circuitry layouts. You will also have to look carefully to see how the gates are shown in the IC. For the 74LS08 quad AND gate, for example, the inputs are 1A, 1B, 2A, 2B, and so on, with the outputs as 1Y, 2Y, 3Y, and 4Y.

With ICs, you can really start interconnecting ICs so the output of one gate triggers the input of another. You will be exploring the beginnings of digital computing.■

Reading & Resources: