Fundamentals 22 min read

How Simple Relays Build Binary Logic: From Electricity to a DIY Computer

This article explains how basic electrical phenomena, relays, and binary arithmetic combine to form logic gates, adders, flip‑flops, counters, RAM, and ultimately a rudimentary 8‑bit computer, illustrating each step with clear diagrams and practical examples.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How Simple Relays Build Binary Logic: From Electricity to a DIY Computer

Computers rely on electricity, but many developers wonder how a collection of logic gates can perform arithmetic and control operations. This guide walks through the underlying physics of electricity, the construction of simple circuits, and how those circuits evolve into a functional, though primitive, computer.

Electricity and Simple Circuits

Electricity originates from the movement of electrons within atoms, which consist of protons, neutrons, and electrons. When electrons are freed from atoms they create electric charge; opposite charges attract while like charges repel. Lightning illustrates a massive discharge of electrons seeking balance.

A basic battery‑powered circuit demonstrates this principle: chemical reactions generate excess electrons at the negative terminal, which travel through a conductive path, lighting a bulb before returning to the positive terminal. Adding a housing creates a simple flashlight, and by modulating the circuit with a switch, the light can be used for Morse‑code communication.

Relays as Logic Gates

By wrapping a coil around an iron rod, a relay turns the rod into an electromagnet when current flows. The magnetic field moves a movable contact, opening or closing another circuit. Combining relays yields logical operations:

AND : two switches must both be closed for the lamp to light.

OR : either switch can light the lamp.

NOT (Inverter) : a switch that, when closed, turns the lamp off.

NAND, NOR, XOR : more complex combinations of relays.

These gate symbols are shown in the accompanying diagrams.

Binary Numbers and Addition

Binary uses only 0 and 1, mirroring the on/off nature of switches. Two switches represent a two‑bit number, where 0 means open and 1 means closed. Truth tables (shown in the original figures) map the switch states to lamp output, illustrating the AND operation.

A half‑adder combines an XOR gate for the sum and an AND gate for the carry. Connecting two half‑adders with an OR gate creates a full‑adder , capable of adding three bits (two operands plus an incoming carry) and producing a sum and a new carry.

By chaining eight full‑adders, an 8‑bit adder is built, with nine lamps indicating the possible overflow.

Subtraction via Two’s Complement

Subtraction can be performed by adding the two’s complement of the subtrahend. In decimal, the ten’s complement is obtained by subtracting the number from a string of 9s and adding 1. In binary, the one’s complement is the bitwise NOT, and adding 1 yields the two’s complement. For example, the binary representation of 125 is 01111101; its two’s complement, representing –125, is 10000011.

Oscillators, Flip‑Flops, and Counters

An oscillator built from a relay repeatedly opens and closes, producing a periodic signal that alternates between 0 and 1—this is the clock. A basic RS (set‑reset) flip‑flop stores a single bit: one switch sets the output high, another resets it low. Adding a clock input creates a D‑type flip‑flop, which captures the data input on a clock edge.

Connecting flip‑flops in series forms a binary counter, where each stage toggles on the falling edge of the previous stage, counting from 0000 to 1111.

RAM Construction

By arranging multiple D‑type flip‑flops with address lines (decoded by a selector circuit), an 8‑bit random‑access memory (RAM) cell is formed, capable of storing eight independent bits. Combining two such arrays yields 8×2‑bit storage, and adding more address lines expands capacity exponentially, explaining why RAM is a volatile storage medium.

Assembling a Simple 8‑Bit Computer

The complete system integrates the 8‑bit adder (ALU), a set of flip‑flops (accumulator), a program counter (counter), and RAM. A control panel with switches supplies operand bits and operation codes; lamps display intermediate and final results. Instruction encoding uses one‑byte opcodes followed by address bytes, enabling load, add, store, and jump operations, thus allowing loops and conditional execution.

Although this machine uses relays instead of transistors and lacks buses and parallelism, it demonstrates the fundamental components of a modern computer: ALU, registers, program counter, memory, and a simple instruction set.

Conclusion

The presented design is intentionally simplistic; real computers employ integrated circuits, high‑speed buses, and sophisticated control logic. Nonetheless, the same principles—binary representation, logic gates, sequential logic, and memory addressing—underlie all digital computing devices.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

computer architecturedigital electronicslogic gatesbinary arithmeticDIY computer
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.