Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO NAND Gate Trainer with LED Output

View and Edit Project In Cirkit DesignerImage of Arduino UNO NAND Gate Trainer with LED Output

Circuit Documentation

Summary

This circuit is designed to demonstrate a NAND gate operation using an Arduino UNO. The circuit includes two rocker switches as inputs, a red LED as the output, and a resistor to limit the current through the LED. The Arduino UNO reads the states of the rocker switches, performs the NAND operation, and displays the result on the LED. The result is also printed to the serial monitor.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. Rocker Switch (Switch 1)

    • Description: A simple on/off switch.
    • Pins: output, input
  3. Rocker Switch (Switch 2)

    • Description: A simple on/off switch.
    • Pins: output, input
  4. 7408

    • Description: Quad 2-input AND gate IC.
    • Pins: 2, 1, 3, 4, 5, 6, Gnd, Vcc, 8, 9, 10, 11, 12, 13
  5. LED: Two Pin (red)

    • Description: A red light-emitting diode.
    • Pins: cathode, anode
  6. Resistor

    • Description: A 220 Ohm resistor used to limit current.
    • Pins: pin1, pin2
    • Properties: Resistance: 220 Ohms
  7. 16X2 LCD

    • Description: A 16x2 character LCD display.
    • Pins: VSS, VDD, V0, RS, RW, E, D1, D0, D2, D3, D4, D6, D5, D7, A, K
  8. 4X4 Membrane Matrix Keypad

    • Description: A 4x4 matrix keypad.
    • Pins: R1, R2, R3, R4, C1, C2, C3, C4

Wiring Details

Arduino UNO

Rocker Switch (Switch 1)

Rocker Switch (Switch 2)

7408

LED: Two Pin (red)

Resistor

16X2 LCD

4X4 Membrane Matrix Keypad

Code Documentation

/*
 * Project Title: NAND Trainer
 * Description: This code controls the inputs from rocker switches, processes the
 * NAND gate operation, and displays the output on an LED according to the NAND
 * truth table.
 */

// Pin definitions
const int switch1Pin = 2;
const int switch2Pin = 3;
const int ledPin = 13;

void setup() {
  // Set up the switch pins as inputs
  pinMode(switch1Pin, INPUT);
  pinMode(switch2Pin, INPUT);
  // Set up the LED pin as an output
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // Read the state of the switches
  int switch1State = digitalRead(switch1Pin);
  int switch2State = digitalRead(switch2Pin);
  // Perform NAND operation
  int nandResult = !(switch1State && switch2State);
  // Display the result on the LED
  digitalWrite(ledPin, nandResult);
  // Print the states and result to the serial monitor
  Serial.begin(9600);
  Serial.print("Switch1: ");
  Serial.print(switch1State ? "HIGH" : "LOW");
  Serial.print(" | Switch2: ");
  Serial.print(switch2State ? "HIGH" : "LOW");
  Serial.print(" | NAND Result: ");
  Serial.println(nandResult ? "HIGH" : "LOW");
  // Small delay to debounce switches
  delay(100);
}

This code sets up the Arduino UNO to read the states of two rocker switches and perform a NAND operation. The result of the NAND operation is displayed on an LED and printed to the serial monitor. The code includes a small delay to debounce the switches.