Part 14 · Electronics and Computing
The Relay Computer
A relay is a switch worked by an electromagnet, and switches wired the right way can do logic, add numbers and remember them. With nothing more than iron, copper wire, brass springs and a battery you can build a slow but exact programmable calculator — the most realistic first computer for a rebuilding world.
- Difficulty
- ●●●●●
- Time
- An evening per relay once you are practised; a few weeks for a 4-bit adder; six months to a year for the whole programmable machine
- Steps from zero
- 21 prerequisites →
The full path from nothing — 21 steps before this one
- Fire
- Cordage and Rope
- Stone Tools
- Finding and Preparing Clay
- Finding and Identifying Ores
- Writing and Numbers
- Hunting and Trapping
- Basic Woodworking
- Charcoal
- Pottery
- Arithmetic and Fractions
- Hides and Leather
- Fermentation
- Logic and Binary
- Bellows
- Copper Smelting
- Iron (the Bloomery)
- Blacksmithing
- The Battery
- Copper Wire
- The Electromagnet
- The Relay Computer
Do them roughly in this order. See it on the tech tree →
Why it matters
A person adding columns of figures makes about one mistake in every few hundred steps and gets tired. A machine that adds can work all night and never slips. The first machines that followed a list of instructions and did arithmetic by themselves were built not from vacuum tubes or chips but from relays — the clicking switches of telegraph lines and telephone exchanges.
Relays are slow. A good relay computer does a few additions a second. But they have three great virtues for someone rebuilding:
- They need no new technology. If you can make an The Electromagnet, you can make a relay. Iron, Copper Wire, brass strip, wood and a The Battery are all you need. No vacuum, no glassblowing, no pure crystals.
- You can see and hear them work. Every relay clicks; when something is wrong, you can find it with a lamp and your eyes.
- They teach the whole idea. Gates, adders, memory, clock, program — every part of a modern The Computer has its twin in a relay machine, and it all carries over to tubes and transistors later.
A relay calculator is genuinely useful: it can work out tables for Navigation, Surveying and Levelling and engineering, check accounts, and train the people who will later build faster machines. This chapter builds one, starting from a single relay and a lamp.
How it works
Switches can think
From Logic and Binary: every question can be broken into yes/no steps, and numbers can be written with only 1 and 0. A switch is either closed (current flows — 1) or open (0). A relay is a switch closed by another current, so one relay's output can work the next relay's coil, and chains of relays can calculate.
Every relay has a coil and one or more contact sets that move together when the coil is on. There are three kinds of contact:
- A make contact (also called normally open, NO) is open at rest and closes when the coil is on.
- A break contact (normally closed, NC) is closed at rest and opens when the coil is on.
- A changeover has a middle spring, the common, that rests on a break contact and moves across to a make contact. It is a make and a break sharing one spring, and it is the most useful of the three.
All drawings in this chapter are ladder diagrams: a "+" rail on the left, a "−" rail on the right, and rungs between them. Each rung is a path of contacts ending in a lamp or a coil. If there is a closed path from + to −, the lamp lights or the coil pulls in. Contacts are always drawn at rest (coil off).
That is the whole secret, set out by Claude Shannon in 1937: contacts in series do AND, contacts in parallel do OR, break contacts do NOT. Any logical rule at all can be built from these three.
Adding in binary
In binary, each column can only hold 0 or 1. Adding two digits gives four cases: 0+0=0, 0+1=1, 1+0=1, and 1+1=10 (that is, two: write 0, carry 1). So adding one column needs two answers:
- SUM is 1 when exactly one input is 1. This is called XOR (exclusive or).
- CARRY is 1 when both inputs are 1. This is just AND.
XOR is beautifully simple with changeover contacts: it is the same circuit as a light on a staircase with a switch at the top and the bottom, where either switch turns the light on or off.
This is a half adder. It adds two bits, but it cannot take a carry from the column to its right. For that you need a full adder, which has three inputs — A, B and the carry in, C — and two outputs:
| A | B | C (carry in) | SUM | CARRY OUT |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 | 1 |
SUM is 1 when an odd number of inputs is on; CARRY OUT is 1 when two or more are on. In relays both are made neatly with changeover contacts:
Line up four full adders and connect each CARRY OUT to the C coil of the column on its left, and you have a 4-bit adder: it adds any two numbers from 0 to 15. Eight columns add numbers up to 255.
Subtracting with the same adder
To work out A − B, flip every bit of B (1 becomes 0 and 0 becomes 1) and add, with the carry into the lowest column switched on. This trick, called two's complement, gives the right answer whenever A is at least B. Example in 4 bits: 9 − 3. 9 is 1001; 3 is 0011, flipped is 1100. 1001 + 1100 + 1 = 1 0110. Ignore the carry out of the top column and the answer is 0110 = 6. Correct.
In relays, flipping is easy: feed B's sum network from the B relay's break side instead of its make side. One extra changeover on each B bit, controlled by a SUBTRACT relay, does it.
Memory: a relay that holds itself on
Give a relay a make contact wired around its own switch. Press SET for a moment: the coil pulls in, its own contact closes, and the coil keeps itself on through that contact after you let go, until CLEAR breaks the circuit. That is a latch: one relay remembering one bit while the power stays on.
Four latches side by side hold one 4-bit number: a register. A row of registers, each with an address, is a memory.
The clock
Relays take 10 to 50 milliseconds to move, and an adder's carry ripples from column to column. If everything happens at once, latches catch half-finished answers. The cure is a clock that does things in a fixed order and waits long enough at each step: clear, read, settle, write. In a relay machine the clock can be a drum of contacts turned by hand: a wooden cylinder with copper strips round part of its surface, and springy brass brushes pressing on it. Each brush touches its strip for part of every turn, and so closes its circuit at one phase of the turn and opens it at another.
What you need
For one relay
| Part | Size | Notes |
|---|---|---|
| Soft iron core | Rod 1 cm thick, 5 cm long | Annealed wrought iron (Iron (the Bloomery), The Electromagnet) |
| Soft iron yoke and armature | Strip 3 mm × 15 mm, about 15 cm; plate 2 mm thick, 2 × 6 cm | Bend the yoke into an L |
| Coil wire | 1,500–2,000 turns of 0.25–0.3 mm covered wire, about 100–120 m (50 g) | Silk- or cotton-covered, varnished (Copper Wire) |
| Contact springs | Hard-rolled brass or bronze strip, 0.3 mm thick, 5 mm wide, 6–8 cm long; 3 per changeover | Sheet Metal and Rolling, Zinc and Brass |
| Contact points | Tiny rivets or blobs of silver, 1–2 mm | Gold and Silver; copper works but tarnishes |
| Insulating spacers | Mica, or card soaked in shellac, 1 mm | Between the springs in the clamp |
| Card (pusher) | Bone, horn, or dense hardwood boiled in wax | Carries the armature's movement to the springs |
| Base and screws | Hardwood board; brass or iron screws | Screws, Nuts and Bolts |
For the whole machine described below
| Item | Quantity |
|---|---|
| Relays with 4 changeover sets | About 85 (or 120–150 two-set relays, paired) |
| Coil wire, 0.25–0.3 mm | About 10 km — roughly 4–5 kg of copper |
| Power | 6 V, up to 10 A: three lead-acid cells, or a dynamo with a battery to smooth it |
| Small lamps | 20–30 low-voltage lamps, or galvanometer needles |
| Toggle switches | About 90 (program panel, input, controls) |
| Stepping switch | 1, with 16 or more positions (see Step 6) |
| Hook-up wire | Several hundred metres of 0.5–0.7 mm covered wire |
| Frames | Wooden racks to hold relays in rows, with terminal strips |
Where to find it
Everything comes from earlier chapters: iron from Iron (the Bloomery), copper and wire from Copper Smelting and Copper Wire, brass from Zinc and Brass, silver from Gold and Silver, shellac (lac) and beeswax for varnish from Glues and Adhesives and Beekeeping, silk thread from Silk.
Mica is the one new material: a mineral that splits into thin, clear, flexible sheets that neither burn nor conduct. It occurs as glittering flakes in granite and as "books" of stacked sheets, sometimes hand-sized, in coarse pegmatite veins (Rocks and Minerals). Card or thin wood soaked in shellac and dried hard will do instead.
Old telephone relays found in ruins are ideal; test each with a cell and a lamp. But do not count on them — everything here can be made from scratch.
Step by step
Build in stages, and test each stage fully before going on.
Step 1: Make a good relay
The relay in The Electromagnet has one contact. A computer needs relays with several contact sets that all move at once.
- Bend the yoke: an L of soft iron strip, the upright 6–7 cm tall. Drill the foot and fix the core upright to it with a screw or rivet, so iron touches iron firmly.
- Wind the coil on a paper-covered bobbin over the core: 1,500–2,000 turns of 0.25–0.3 mm covered wire, all in the same direction, a layer of waxed paper every two layers. Varnish it. Its resistance should be about 30–50 ohms; on 6 V it then draws 0.12–0.2 A and pulls with about 200–300 ampere-turns, which is plenty.
- Hinge the armature on top of the yoke's upright: a 2 mm soft iron plate resting across the top of the core. A strip of thin brass riveted to both makes a good hinge. Set the gap at the core to 1 mm at rest.
- Glue a small piece of paper (0.1–0.2 mm) on the core face, or set a brass pin in it, so that iron never quite touches iron. Without this the armature may stick on.
- Build the spring stack: for each changeover, three springs: upper (NC), middle (common, longer, reaching the card), lower (NO). Stack them in a clamp with mica spacers, all insulated from the screws by paper sleeves soaked in shellac. Solder or rivet silver points opposite each other on the springs.
- Fit the card: a strip of bone or waxed hardwood hanging from the armature tip, with slots that catch the ends of the common springs.
- Adjust: with the coil off, each common spring should press on its NC contact with a light but definite pressure (it should lift a 20 g weight hung on it before parting). With the coil on, each common should leave NC and press on NO. The gap between open contacts should be 0.3–0.5 mm — about the thickness of two sheets of paper. Bend the fixed springs with flat-nosed pliers until it is right. The springs' own tension lifts the armature when the current stops.
- Burn it in: wire the relay as a buzzer (its coil through one of its own break contacts) and let it run for an hour. Then readjust. Contacts that are going to fail will usually show it now.
Make relays in batches of ten, with jigs: a bending block for the yokes, a drilling template, a winding jig on a The Lathe with a turn counter. Uniform relays are easier to adjust. Number each relay and keep a notebook page for it.
Step 2: Gates
On a board, mount one relay, two switches, a lamp and the 6 V supply. Wire NOT, AND and OR exactly as in the figure above and check each truth table, row by row. Then replace the lamp with the coil of a second relay, and use the second relay's contact to light the lamp. One relay's answer now drives another, and the whole machine becomes possible.
Step 3: Half adder and full adder
- Wire the half adder with two relays (each needs one changeover and one make contact). Check all four rows of its table.
- Wire one full adder with three relays. Relay A needs 2 changeover sets, B needs 4, C needs 3. If a relay has too few, use two relays with their coils wired in parallel and treat them as one.
- Check all eight rows of the full adder table. Write each result in the notebook.
Step 4: The 4-bit adder
- Build four full adders on one board, the lowest column on the right as in written numbers.
- Wire the CARRY OUT of each column to the C coil of the column on its left. The lowest column's C coil goes to a switch marked "carry in". The top column's CARRY OUT goes to a lamp marked "overflow".
- Wire four switches to the A coils and four to the B coils. Put four lamps on the SUM outputs.
- Test: 0+0, 1+1, 7+1 (the carry must ripple through three columns: 0111 + 0001 = 1000), 15+1 (all four columns carry, the overflow lamp lights and the sum shows 0000), and a dozen random sums checked by hand.
- Add the SUBTRACT relay: a changeover on each B bit that feeds the adder from B's break side when SUBTRACT is on, and a contact that turns on the lowest carry in. Test 9 − 3 = 6, 15 − 15 = 0, 8 − 1 = 7.
You now have a working binary adding machine — roughly what George Stibitz built on his kitchen table in 1937.
Step 5: Registers and memory
- Build one latch and test it: SET, CLEAR, and that it remembers for an hour.
- Build the accumulator (the working register): 4 latches whose outputs drive the A coils of the adder, and 4 lamps showing their contents.
- Build the sum buffer: 4 latches that catch the adder's output. You need it because the accumulator cannot be cleared and written from the adder at the same moment that it is feeding the adder.
- Build the B register: 4 relays that feed the adder's B side.
- Build the memory: 8 words of 4 latches each. Each latch needs a holding contact, a read contact, and its own SET and CLEAR wiring.
- Build the address selector: 3 address relays (one for each bit of the address) with their contacts arranged as a tree — the first relay's changeover splits one wire into two, the second relay's two changeovers split two into four, the third relay's four changeovers split four into eight. Exactly one of the eight end wires is live, whatever the address. That wire pulls in one of 8 word-select relays, and its contacts connect that word, and only that word, to the B register (for reading) or to the accumulator (for writing).
- Wire word 7 to four input switches instead of latches. Reading word 7 reads whatever you have set on the switches.
Step 6: Program, instruction and clock
The program panel: 16 rows of 5 switches. Each row is one instruction: 2 switches for the order and 3 for the address.
Order switches Instruction What it does 00 LOAD n Accumulator becomes the number in word n 01 ADD n Accumulator becomes accumulator + word n 10 SUB n Accumulator becomes accumulator − word n 11 STORE n Word n becomes the accumulator LOAD needs no extra hardware: it is an ADD with the accumulator's contacts to the adder held open, so the adder sees 0 + word n.
The stepping switch picks which row is read. Make it from a ratchet wheel with 16 teeth, moved one tooth by a pawl on an electromagnet's armature each time the clock pulses it. A wiper arm on the same shaft sweeps round a half-circle of 16 brass studs, one wired to each program row. This is the "uniselector" of old telephone exchanges.
The instruction register: 5 latches that hold the current row's switches during the turn.
The clock drum: a hardwood cylinder 8–10 cm across on a crank, with six copper strips at different angles round it and a brush for each. One turn of the crank is one instruction, in six phases:
Phase All instructions LOAD, ADD, SUB STORE 1 Clear instruction, B and sum buffer; step to next row 2 Copy the program row into the instruction latches 3 Read word n into B Clear word n 4 Adder has settled: write it into sum buffer Write accumulator into word n 5 Clear accumulator (nothing) 6 Copy sum buffer into accumulator (nothing) Arrange the strips so that each phase starts only after the last has ended, with a short gap of nothing between them. Then the drum, not the relay contacts, makes and breaks the currents, and the relay contacts last far longer.
A first program
Multiply 5 by 3, by adding three times. Set the input switches (word 7) to 0101.
| Row | Order | Address | Meaning | Accumulator after |
|---|---|---|---|---|
| 1 | 00 LOAD | 111 | load the input | 0101 (5) |
| 2 | 01 ADD | 111 | add the input | 1010 (10) |
| 3 | 01 ADD | 111 | add the input | 1111 (15) |
| 4 | 11 STORE | 000 | keep the answer in word 0 | 1111 |
Crank four turns and the output lamps show 1111: fifteen. You can change the input switches between turns, which is how you feed in a list of numbers; to work out a table, set the steps once on the panel and crank through them again for each new input.
How to tell it worked
- Every relay alone: pulls in crisply at 4.5 V or less on a 6 V supply, drops out cleanly at 1–2 V, and each contact lights a lamp in the right position. Write these voltages in the relay's notebook page.
- Every gate and adder: passes its whole truth table. For the 4-bit adder, test the carry chains: 0111 + 0001, 1111 + 0001, and subtraction 1000 − 0001.
- Memory: store 1010 in every word, then 0101 in every word; read each back. This catches stuck bits and sneak paths.
- The machine: run the multiplication program, then a program you have worked out on paper. Crank slowly and compare every lamp with your paper at every phase.
Note Troubleshooting. A relay buzzes or chatters → the supply is too weak (voltage sags when many relays pull in), or the armature gap is too wide. Check the voltage at the far end of the rack. A relay will not let go → residual magnetism: add a paper shim or brass pin on the core face; check the core is soft iron. A contact works sometimes → dirt or tarnish. Clean both points with a strip of fine paper drawn between them while closed; never file silver. Copper contacts need cleaning every few weeks. Two words change when you write one → a sneak path: current is flowing backwards through some other closed contact. Trace it with a lamp on a long lead. Cure it by routing through a separate word-select contact, or (later) by putting a one-way rectifier in the path (Semiconductors and the Transistor). Right answers by hand, wrong when cranked fast → the carry has not finished rippling before the WRITE phase. Crank more slowly, or widen the gap between phases on the drum. Random errors in hot weather or after a while → coils overheating. A coil too hot to hold needs more turns or a lower voltage.
Dangers
Danger Fire. A rack of 85 relays at 6 V can draw 10 A, and a lead-acid battery can deliver hundreds of amps into a short circuit — enough to make a wire glow red in a second and set wax, shellac and wooden racks alight. Put a fuse (a short length of thin wire in a clay holder, see Wiring and Electrical Safety) in every supply lead, close to the battery: one fuse per rack, rated about twice the rack's normal current. Never leave a machine powered and unattended. Keep a bucket of sand nearby.
- The switch-off kick. Every coil gives a high-voltage spike when its current is broken. One relay gives a sharp tingle; it also burns contacts. Hold wires by their insulation when disconnecting. Put a resistor of about 10 times the coil's resistance (a coil of thin iron wire works) across each coil, or later a rectifier, to quench the spike.
- Battery acid and hydrogen: see The Rechargeable Battery and The Battery.
- Pinched fingers in stepping switches and the clock drum. Keep the drum's crank turning one way only and guard the gears.
- Eyes: wear something over them when cleaning contacts with acid or abrasive.
Going further
- Wider words. Eight bits instead of four doubles the data relays but counts to 255. Zuse's Z3 used 22-bit floating-point numbers (a number and a power of two, like scientific notation).
- A motor for the clock. Drive the drum from a small The Electric Motor or a The Waterwheel through gears at 1–3 turns a second. Keep the hand crank for debugging.
- Jumps. A real computer must be able to choose: "if the accumulator is zero, go to row 12". Add a fifth order bit for "jump if zero", and a second electromagnet that keeps stepping the stepping switch, doing nothing, until it reaches the row whose "mark" switch is set. With jumps and memory, a machine can in principle compute anything any computer can, only slowly.
- Punched tape. Replace the switch panel with a strip of paper or film with holes punched in rows; spring fingers drop through the holes onto a metal drum. Programs can then be any length and kept on a shelf (see The Teleprinter and Punched-Card Tabulating Machines).
- Multiplication and division by shifting and adding, built into the machine. See Programming for how to write such routines.
- Faster switches. Everything here works the same with vacuum tubes (a thousand times faster) and transistors (Semiconductors and the Transistor, millions of times faster). See The Computer.
How it was first done
In 1937 the American student Claude Shannon showed in his master's thesis at MIT that relay circuits obey Boolean logic, so circuits could be designed on paper with algebra instead of by trial. The same year George Stibitz, a mathematician at Bell Telephone Laboratories, took two telephone relays home and built a binary adder on his kitchen table, with flashlight bulbs and contacts cut from a tin can — the "Model K". It led to Bell Labs' Complex Number Calculator of 1940, of several hundred relays, which Stibitz worked over a teleprinter line from a mathematics meeting at Dartmouth College in New Hampshire, more than 300 km away — the first use of a computer from a distance.
In Berlin, the engineer Konrad Zuse built a mechanical binary computer, the Z1 (1938), in his parents' living room, then turned to relays. His Z3 of 1941 used about 2,600 relays, held 64 numbers in relay memory, and read its program from holes punched in discarded 35 mm cinema film. It took about a second for an addition and three for a multiplication. It was the first working programmable, fully automatic digital computer; it was destroyed in an air raid in 1943.
At Harvard, Howard Aiken and IBM finished the Mark I in 1944, a 15-metre machine of relays and rotating counter wheels that calculated for the US Navy and stayed in use until 1959. Vacuum tubes, a thousand times faster, soon overtook relays. Even today hobbyists build complete relay computers with a few hundred relays: the path in this chapter is within reach of a small, patient team.
Source: content/entries/electronics/relay-computer.md