Relay Implementation

Relay logic was the first technology used to build programmable computers, using electromagnetic switches to implement logic gates — achievable today from salvaged electrical components without semiconductor fabrication.

Why This Matters

Relays were the technology of choice for the first generation of digital computers. Konrad Zuse’s Z3 (1941) used 2,600 relays. The Harvard Mark I (1944) used 3,304 relays and 1,400 mechanical components. These were working computers capable of running real programs, built without a single transistor.

In a civilization-rebuilding context, relays may be the first practicable technology for digital logic construction — after electrical power has been established and before semiconductor fabrication is available. Relay computers are slow (hundreds of operations per second vs. millions for transistors) and mechanical (relays wear out, click audibly, consume significant power), but they work, they are debuggable without instruments, and all their behavior is directly observable.

Understanding relay logic also deepens understanding of all digital logic: a relay gate is conceptually identical to a transistor gate, just larger and slower. The Boolean algebra is the same.

Relay Fundamentals

An electromagnetic relay consists of:

  • Coil: wire wound around a ferromagnetic core; current through the coil creates a magnetic field
  • Armature: a movable metal lever attracted to the core when the coil is energized
  • Contacts: the armature physically moves contact fingers to change electrical connections

Types of contacts:

  • NO (Normally Open): open when coil is de-energized, closes when energized
  • NC (Normally Closed): closed when coil is de-energized, opens when energized
  • DPDT (Double Pole Double Throw): two independent contact pairs switched simultaneously

Relay specifications to know:

  • Coil voltage (5V, 12V, 24V): the voltage needed to energize
  • Coil current (50–200 mA typical for small relays)
  • Contact rating (maximum current the contacts can switch)
  • Operate time (2–10 ms): delay from coil energization to contact closure
  • Release time (1–5 ms): delay from de-energization to contact opening

A freewheeling diode (connected in reverse across the coil) is essential: when coil current stops, the collapsing magnetic field induces a voltage spike (back-EMF) that can destroy the driving transistor without this protection.

Logic Gates from Relays

NOT gate (inverter): one relay with a NC contact.

  • Relay coil = input
  • NC contact output = NOT input
  • When coil de-energized (input=0): NC contact closed → output=1
  • When coil energized (input=1): NC contact open → output=0

AND gate: two relays with NO contacts in series.

  • Both relays must be energized (both inputs=1) for current to flow through the series chain
  • Any relay de-energized (input=0) breaks the series chain → output=0

OR gate: two relays with NO contacts in parallel.

  • Either relay energized allows current flow → output=1
  • Both de-energized → output=0

NAND gate: two relays in series, but using the output to drive a further load — equivalently, AND gate followed by inverter (NC contact of a third relay driven by the AND output).

Alternatively: a NAND can be directly realized with two relays in series using NC contacts, with a power supply at one end. When both coils are energized (both inputs=1), both NC contacts open, breaking the chain → output=0 (NAND behavior). When either is de-energized, the chain remains closed → output=1.

Relay Computer Architecture

A relay-based ALU requires approximately:

  • 1-bit full adder: ~15 relays
  • 4-bit adder: ~60 relays
  • 4-bit register (4 SR latches from relays): ~8 relays
  • Basic instruction decoder: ~40 relays

A minimal useful relay computer (4-bit data, 8-bit address, 8 instructions) requires roughly 400–800 relays. This is comparable to the scale of early computer projects and is achievable with perseverance.

Historical reference: the Relay Calculator No. 2 (Bell Labs, 1944) performed floating-point addition in 0.3 seconds — slow by modern standards but fast enough to automate calculations that previously required weeks of manual work.

Practical Construction Notes

Relay selection: use 12V DPDT relays rated for low coil current (< 100 mA). DIP-footprint signal relays (Omron G6K, Panasonic TQ series) are compact. Industrial relays (Omron MY, Potter & Brumfield KRP) are more robust but larger.

Driving relays from logic outputs: a TTL or CMOS logic gate cannot drive a relay directly (relay coil current exceeds logic output rating). Use a transistor driver: NPN transistor with base through 1kΩ resistor to logic output, collector to relay coil through protective diode, emitter to ground, coil other end to power supply.

Noise immunity: relay switching generates electrical noise (contact bounce, back-EMF). Separate relay power supply from logic power supply. Use metal-film resistors and film capacitors in timing circuits adjacent to relays.

Contact bounce: when a relay armature closes, contacts bounce 2–5 times over 1–5 ms before settling. This creates multiple voltage transitions — a problem for SR latches and edge-sensitive circuits. Add RC debounce (1kΩ + 0.1µF) on relay outputs used as latch inputs.

Debugging: relay state is directly observable (listen for clicks, observe armature position with LED indicators on each relay output). Use LED indicators on key nodes to verify circuit behavior at each step. Relay-speed debugging (milliseconds per operation) is far easier than oscilloscope debugging of nanosecond-speed ICs.

A relay computer built from 500 salvaged relays, powered by a 12V supply, and running at 100 operations per second is a real, functional computing machine — one of the most tangible demonstrations that information processing is a physical, constructable phenomenon.