Relays and Logic Gates – How to Make a Computer: Part I

Relays and Logic Gates – How to Make a Computer: Part I


In our culture, it’s almost impossible to
spend a day without interacting with computers. Almost all of our work and communication is
facilitated by computers, and we entertain ourselves by watching computers, often consuming
content that is about computers. But despite our society’s heavy reliance
on them, it seems like relatively few people actually know how computers work – sure,
most people have some vague understanding, but little knowledge of what’s actually
going on under the hood. In these videos, you’ll be learning how
to build a computer from first principles, building your knowledge of computer logic
step-by-step. Starting from basic circuits and electronic
building blocks, you’ll eventually learn how to build an adding machine – a machine
that works similarly to the CPU inside your computer today. To build this machine, we’ll be using technology
available as early as the 19th century – today’s electronic circuits are just miniaturized
versions of the circuits we’ll be constructing in this series. In this episode, we’ll be starting from
first steps, discovering logic gates – the very most basic components of digital systems. Let’s imagine it’s the 19th century, and
the electrical telegraph becoming all the rage. Enticed by the promise of instant communication,
you decide you want to build a direct line to your friend in another city, so with a
small loan of a million dollars from your father, you get to work. Reading the latest books and manuals, you
learn that a telegraph is just a single copper circuit including two main parts, a key, and
a sounder, as well as a power source to push a current through the circuit. Pressing down on the key completes the circuit,
and magnetises a chunk of iron, attracting a metal bar, which makes a click and clack
when the key is pressed down and released. To save on copper, you just run the circuit
one way from a power source, grounding it at the far end. But, you soon figure out that there’s a
catch – the telegraph can only transmit signals so far. Roughly halfway between you and your friend,
you need to retransmit the signal. Rather than wasting money to pay someone to
copy the signals over halfway, you just take a spare sounder and a spare key. By attaching a stick between the two, the
whole thing conveniently takes care of itself. Closing the circuit on one end activates the
device you’ve created, and retransmits the signal just like you’ve intended. The line works. Without knowing it, you’ve actually invented
a critically important electronic device – the electromagnetic relay. You label the incoming signal from the key
as “input” and the outgoing signal to the sounder as “output.” After having simplified your design by replacing
the bulky moveable bar with a flexible strip of metal, you take to tinkering with relays
in your lab, and make some interesting discoveries. First, you find that you can use these relays
for much more than just telegraphs. Connecting two relays together in this circuit,
so that the output of the first relay provides the input to the second relay, you observe
that triggering the first relay instantly triggers the second relay, which outputs a
current to light the lightbulb. These relays, it seems, are switches that
can be turned on and off by other switches – but soon you find more interesting ways
that relays can be used together. When you connect two relays up in series,
so that the output of the first relay controls the power source of the second, you find that
closing just one switch at a time is not enough to complete the circuit and light the bulb. Instead, you need to trigger both relays to
allow a current to flow to the lightbulb. When you connect the relays in parallel, they
again behave differently. With this kind of circuit, the lightbulb lights
up as long as one (or both) of the relays are triggered. These kinds of circuits, which perform logical
operations, are logic gates. You call the first circuit, for which both
switches have to be closed for the lightbulb to light up, an AND Gate, which you represent
by this D-shaped symbol, and you write up the different permutations of the circuits
in tables, representing a voltage as 1 and no voltage as 0. The second circuit, for which either input
needs to be 1 for the output to be 1, you call an OR gate, which is represented by this
curved symbol. So now you have two interesting circuits you
can make with telegraph relays, but you’re not done yet. Tinkering with these parts in your study,
you one day accidentally wire a relay up incorrectly, so that the relay outputs a voltage when it
is untriggered, and outputs no voltage when it is triggered. You call this kind of relay an Inverter, because
its output is inverse to its input. Attaching this inverter at the output of an
AND gate creates a new type of logic gate, which acts as the inverse to the AND gate. Here, the lightbulb is lit unless both inputs
are closed, at which point the inverter is triggered, and breaks the circuit at the lightbulb. Doing the same to an OR gate, likewise, inverts
its output. Now, the lightbulb is only lit when neither
the first nor the second inputs are 1. You name these two new gates, “Not AND”
and “Not OR” gates, or NAND and NOR for short. These 4 logic gates, AND, OR, NAND and NOR
are the most basic building blocks of any digital system, like a computer. In different configurations, these gates can
be used to add numbers together, and store information in the form of computer memory. The computer you’re using to watch this
video on is built from hundreds of millions of tiny logic gates. Every computer you’ve ever used is essentially
a clockwork device, made from countless switches triggering other switches. In this video, we used telegraph relays to
make these logic gates, but, as you may have guessed, modern computers do not use relays
for logic gates. In fact, a logic gate can really be made using
any switch than can turn other switches on and off – they’re less electronic devices,
and more basic logical principles of the universe. You can use physical mechanisms to create
logic gates, and early computers used vacuum tubes. The overwhelming majority of computers today
use transistors for logic gates, because of how light and cheap they are. In the next episode, you’ll be figuring
out binary, and learning how computers count. After that, you’ll learn how computers add
and subtract, and finally how logic gates are used to create computer memory. At the end of this series, you’ll know how
to build a machine that can add and subtract two numbers together, and save and load the
result. This might seem like a basic goal to be reaching
for, but this machine is essentially a simple version of a modern CPU – the core of every
computer is essentially an extremely fast adding machine.