# Relay Computing

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.

## Mux Mania

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.

## Practical

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.

## 25 thoughts on “Relay Computing”

1. DV82XL says:

There is still a lot of relay logic in service running elevators

1. Thank you !
I should really finish YGREC (whygee’s relay electric computer)
For this project I created a “new” (?) kind of logic : CC-PBRL
Capacitively Coupled Pre-Biased Relay Logic (using hysteresis, like the memory single-relay cells)

but I got lured into the transistor novelty realm because of Ted Yapo…

How many hackers does it take to change a bulb ?
Wait a minute, we reinvent the bulb.

2. Ostracus says:

A lot of PLCs out there although I imagine basic relays can be pretty noisy working. Next up mercury delay lines.

1. PLCs have not been relay based in eons…. sure they are often programmed in “ladder logic” but there aren’t any actual relays involved in that.

1. Jii says:

Many times it’s transistor outputs, but relays are used a lot too. There are things you need to run with more current, than the transistor outputs can provide, or different voltages etc.

1. Outputs are not logic… so I’m not sure what you point is. PLCs long ago were based on relay logic but as I said that hasn’t been the case in forever.

3. Paul Baker says:

Seems like a more modern take would be to use analog SPDT switches such as SN74LVC1G3157 which is a single solid-state SPDT in a SOT-23-6 package. Cheaper than relays (\$0.34 in single quantity), take less power to operate and are smaller than relays but large enough to be easily handled by the average person.

1. inventorm says:

As an electrical engineer, I deal with relay logic all the time at work. While most of the relays in my designs are used as electrically-actuated switches, the electrical isolation and fail-safe operation of electromechanical relays are necessary components for safety systems. I can’t risk a solid-state relay failing conductively and starting up equipment that’s supposed to be deenergized.

4. Tomo says:

I love this stuff!

5. Al Williams says:

I am am not sure where “most fpgas” came from. That should have been some. I will fix it in a bit.

1. Actel’s A1020 was my first exposure to FPGA and MUX-based logic.
I still marvel at its design…

But these days I play with larger, more inefficient, slower, communist-era, clicking and vibration-sensitive MUX2 :-D
Thanks to eBay and Alex (a Ukrainian surplus seller),
http://www.ebay.com/itm/Miniature-relay-2-8-V-control-voltage-Box-of-72-New-/351723476566
I now have enough electromechanical parts to build my own 16-bits relay computer using CC-PBRL (invented with and for those relays)

6. I found this article really fascinating, so I did some analysis to find how efficiently each possible 2-input logic gate could be constructed:

a AND b => a?b:a
a NAND b => (a?b:a)?0:1
a XOR b => a?(b?0:a):b
a XNOR b => a?b:(b?a:1)
a OR b => a?a:b
a NOR b => a?0:(b?a:1)
a AND !b => b?0:a
!a AND b => a?0:b
a OR !b => b?a:1
!a OR b => a?b:1
!a => a?0:1

There are obviously many solutions to this, but the above shows an example with the fewest muxes needed for each. So you can do anything with a single mux except NAND, NOR, XOR, and XNOR, which each need two.

1. You can make a XOR with only one relay, depending on how you wire the two coil signals, as shown in the falstad link :-)
However, with CCPBRL, 2 relays are needed, one for inverting one input signal, the other for selecting the inverted or the non-inverted.

7. Jonathan Quirk says:

In the mid 1980’s my dad owned a general store with a shoplifting problem. He installed cctv cameras but soon had more cameras than monitors. He designed and built a switcher controlled by telephone keypads operating relays switching video. He could control which one of ten cameras was being recorded on a VCR. He had six monitors; one showed the feed going to the VCR. The other five showed one of a pair of images. If he chose to record camera 1 then the monitor for cameras 1&2 would flip to show camera 2 because camera 1 was visible on the recording monitor. As a suspect customer moved around the store he could follow them, keeping them recorded, while keeping an eye on the rest of the store.

The switcher used a bank of old telephone relays on a board, hard wired together and worked flawlessly for many years. I guess he just used the technology he was used to, having worked in the telephone industry after leaving university.

8. DV82XL says:

Given that the electric relay was known by the mid 1800s (it was apparently invented independently by several people) and that Babbage had conceived the idea of a general-purpose computer around the same time, it is too bad that these ideas didn’t cross. Had Babbage considered a relay based design he might have gotten further if for no other reason than the mechanical tolerances are far lower with these components, and thus the costs would have been far lower.

1. Al Williams says:

I have often thought that fluidic logic was within the capabilities of many ancient civilizations. The Egyptians, for example, could have built it using the flow of the Nile as power. Imagine Pharoh with a giant stone mainframe to do data processing. You have to wonder where computing would be today.

1. DV82XL says:

The difference here being that for relay computing, both the concept and the hardware coexisted at the same time and in the same place. I should have also added that George Boole had written “The Laws of Thought” in the same period, so indeed all the necessary elements were at hand. The Egyptians, while decent mathematicians had not developed a comparable understanding of logic.

2. John PhillipsJohn Phillips says:

As slow as the internet?

9. Sam bickford says:

I’ve worked on some elevator controls that were completely relay logic with approximately 200 relays.
Also there are companies that sell elevators with the option of plc or relay logic the selling point of the relay logic being that it is cheaper to repair and maintain.

10. reggy says:

When I was a kid one of the science museums had n exhibit that let you play tick tack toe against a computer that was made out of relays. It was very cool. I think one of the phone companies AT&T or Bell Labs) was behind it.

11. glad I accidentally left this tab open, there’s some interesting comments in here. Pharoh with super computers, tick-tac-toe, prebiased relays, video-switching, the fact that relays and the idea of computing were near but not combined…

12. JohnScnow says:

Sitting on 28 SpartanLX150’s. And ARM 64bit R series chipsets… Zero. *sigh*

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.