FluxBench.AIShared project · read-only

NAND Universality Trainer

ESP32 DevKit (WROOM-32)·Arduino C++·Updated Jul 27, 2026·by FluxBench TeamIncludes Lab + Schematic + PCB

The classic CS proof, live on a breadboard: five NAND gates - and nothing else - rebuild NOT, AND and OR. NAND(A,A) makes an inverter, a double NAND makes AND, and De Morgan turns two inverters plus a NAND into OR. The ESP32 drives A and B, reads all three derived outputs back and checks every truth-table row in the serial monitor while yellow, red and green LEDs show NOT, AND and OR on the bench. Pull one wire and watch exactly the right rows fail. Bundled Lab bench, schematic and routed PCB included.

sketch.ino
// NAND Universality Trainer - NOT, AND and OR built from NAND alone
// G1: NOT A = NAND(A,A)   G2: NAB = NAND(A,B)   G3: AND = NAND(NAB,NAB)
// G4: NOT B = NAND(B,B)   G5: OR = NAND(NOTA,NOTB)
#define PIN_A 25
#define PIN_B 26
#define PIN_NOT 32
#define PIN_AND 33
#define PIN_OR 27

int combo = 0;
int errors = 0;

void setup() {
  Serial.begin(115200);
  pinMode(PIN_A, OUTPUT);
  pinMode(PIN_B, OUTPUT);
  pinMode(PIN_NOT, INPUT);
  pinMode(PIN_AND, INPUT);
  pinMode(PIN_OR, INPUT);
  Serial.println("NAND universality trainer: NOT/AND/OR from NAND only");
  Serial.println(" A B | NOT(A) AND OR");
}

void loop() {
  int a = (combo >> 1) & 1;
  int b = combo & 1;
  digitalWrite(PIN_A, a);
  digitalWrite(PIN_B, b);
  delay(60); // let the NAND chain settle
  int nota = digitalRead(PIN_NOT);
  int andv = digitalRead(PIN_AND);
  int orv = digitalRead(PIN_OR);
  int wantNot = 1 - a;
  int wantAnd = a & b;
  int wantOr = a | b;
  Serial.print(" ");
  Serial.print(a);
  Serial.print(" ");
  Serial.print(b);
  Serial.print(" |   ");
  Serial.print(nota);
  Serial.print("     ");
  Serial.print(andv);
  Serial.print("   ");
  Serial.print(orv);
  if (nota == wantNot && andv == wantAnd && orv == wantOr) {
    Serial.println("   ok");
  } else {
    Serial.println("   MISMATCH");
    errors++;
  }
  combo++;
  if (combo == 4) {
    if (errors == 0) {
      Serial.println("All 4 rows verified - NAND really is universal!");
    } else {
      Serial.println("Check your wiring - mismatches found.");
    }
    combo = 0;
    errors = 0;
    Serial.println(" A B | NOT(A) AND OR");
  }
  delay(1440);
}

Built with FluxBench.AI — the AI workbench for embedded projects.