Fork me on GitHub

Project Notes

#283 XOR With NAND Gates

Construct an XOR gate with only an 74LS132 quad NAND gate, and demonstrate it’s behaviour with an Arduino and Processing.

Build

Notes

I recently needed an XOR gate, but only had NAND gates on hand.

NAND (and NOR) gates are sometimes known as “universal” logic elements, as it is possible to construct any other type of logic gate with them.

So while a little wasteful, I’m using the four NAND gates of a single 74LS132 chip to produce one XOR gate.

XOR From NAND Logic

XOR_from_NAND

A B Q1 Q2a Q2b Q
0 0 1 1 1 0
0 1 1 1 0 1
1 0 1 0 1 1
1 1 0 1 1 0

Output State Plot

The XorWithNandGates.ino sketch drives the A/B inputs with a state change every 500ms. Three Arduino analog pins are used to read the actual A, B and Q (output) voltages.

LEAP#090 PlotNValues (a simple Processing sketch) reads the data from the serial port and plots the output value over time, with some coloration effects thrown in for good measure.

Here’s a sample trace:

  • top trace: Q (output)
  • middle trace: B
  • bottom trace: A

processing trace

Construction

Breadboard

Schematic

Build

Credits and References

About LEAP#283 Digital LogicCMOS/TTL
Project Source on GitHub Project Gallery Return to the LEAP Catalog

This page is a web-friendly rendering of my project notes shared in the LEAP GitHub repository.

LEAP is just my personal collection of projects. Two main themes have emerged in recent years, sometimes combined:

  • electronics - usually involving an Arduino or other microprocessor in one way or another. Some are full-blown projects, while many are trivial breadboard experiments, intended to learn and explore something interesting
  • scale modelling - I caught the bug after deciding to build a Harrier during covid to demonstrate an electronic jet engine simulation. Let the fun begin..
To be honest, I haven't quite figured out if these two interests belong in the same GitHub repo or not. But for now - they are all here!

Projects are often inspired by things found wild on the net, or ideas from the many great electronics and scale modelling podcasts and YouTube channels. Feel free to borrow liberally, and if you spot any issues do let me know (or send a PR!). See the individual projects for credits where due.