Recently, [Manuel] did a post on making logic gates out of anything. He mentioned a site about relay logic. While it is true that you can build logic gates using switch logic (that is, two switches in series are an AND gate and two in parallel are an OR gate), it isn’t the only way. If you are wiring a large circuit, there’s some benefit to having regular modules. A lot of computers based on discrete switching elements worked this way: you had a PCB that contained some number of a basic gate (say, a two input NAND gate) and then the logic was all in how you wired them together. And in this context, the SPDT relay was used as a two input multiplexer (or mux).
In case you think the relay should be relegated to the historical curiosity bin, you should know there are still applications where they are the best tool for the job. If you’re not convinced by normal macroscopic relays, there is some work going on to make microscopic relays in ICs. And even if they don’t use relays to do it, some FPGAs use mux-based logic inside. So it’s worth your time to dig into the past and see how simply switching between two connections can make a computer.
How do you go from a two input mux to an arbitrary logic gate? Simple, if you paid attention to the banner image. (Or try it interactive). The mux symbols show the inputs to the left, the output to the right and the select input at the bottom. If the select is zero, the “0” input becomes the output. If the select is one, the “1” input routes to the output.
Obviously, a relay with two poles can act like two gates (the input at the bottom has to be the same for both gates). You can also work out a buffer (swap the inputs of the NOT gate), or A OR NOT B and A AND NOT B.
It is also possible to do things like “wired OR” with relays. For example, suppose you had ten AND gates made like the one above. If you want to OR the outputs together, you just connect the output wires. Any one (or more) AND gates triggering will drive the output high. Or, you could let ground be a 1 and float highs. This has the advantage of working better with ICs and other circuits that can sink more current than they can source. Then the relay coils are always hooked up to the positive supply and you need the ground to complete the circuit.
There are other tricks you can use. Diodes can handle some simple logic functions, although this may be considered cheating if you are trying to make a true relay computer. Resistors can convert normal relays into latching relays, as can extra contacts. If you do make both logic levels actual voltages, you can play tricks with feeding both sides of the coil. This makes a great XOR circuit–think about it. It is even more straightforward to create XOR if you don’t mind using two relays. Many modern demonstration relay computers bite the bullet and use semiconductors for memory and control circuits.
This isn’t just in the realm of theory. Many relay computing devices were built in the last century. There are several modern examples, too, although they are mostly for show, not practical devices. There is a good looking 8-bit computer, for example, that only uses 83 relays. Watch it go in the attached video. In all fairness, though, it does use semiconductors for memory and the front panel. However, the architecture write up is quite illuminating, even if you don’t want to build the computer yourself. You can see a video of it in action below.
[Paul] has a project over on Hackaday.io that refuses to use diodes for logic and has a whopping 32-bits of memory. To save relays, he uses a 1-bit ALU. There are quite a few others out there including [Simon Winder’s] impressive build to compute square roots with a telephone dial (see video below).
We’ve covered some other cool relay builds in the past, including this 8-bit marvel that uses 152 relays and reads its programming from paper using optical sensing. There’s also this much larger computer that even has its own online simulator.
Go For It!
If you’ve ever thought about building a computer with relays, this should give you plenty of inspiration. Just keep in mind that relays are deceptively simple: they are non-ideal devices made of coils and strips of spring steel. For example, arcing across contacts is bad, right? Depends. Some contact material depends on arcing to clean corrosion. Others just pit and fail. There’s a lot of subtlety to relays and a lot of their perceived unreliability is really just misapplication. Not that they are as reliable as modern semiconductor devices, of course, but well-made relays with the proper construction for their intended application can be pretty reliable.