Electronics Champ
Published © GPL3+

Identification of Basic Logic Gate ICs using Arduino

This project can identify Basic Logic Gate ICs, viz. NOT, AND, NAND, OR, NOR and XOR using Arduino

BeginnerFull instructions provided3,364
Identification of Basic Logic Gate ICs using Arduino

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
SparkFun Serial Enabled 16x2 LCD - White on Black 3.3V
SparkFun Serial Enabled 16x2 LCD - White on Black 3.3V
×1
I2C Module (Optional)
×1
Basic Logic Gate ICs (To be identified)
×1
Push Button Switch
×1
Resistor 220 ohm
Resistor 220 ohm
×2
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic

Please refer to the given schematic if you are using I2C Module

Schematic

Please refer to the given schematic if you are not using I2C Module

Code

Code for Logic Gate Identifier without I2C

Arduino
Use this code if you are not using I2C Module
/*
 
  This sketch can identify NOT, AND, NAND, OR, NOR, and XOR Gate ICs.
  When a gate is connected and a button is pressed, Arduino identifies
  the gate IC.
 
  This program is for LCD without I2C Module or without LCD
 
  This program is written by Shreyas for Electronics Champ YouTube Channel.
  Please subscribe to this channel. Thank You.
 
*/
 
//Including the libraries
#include <LiquidCrystal.h>
 
const int rs = 12, en = 11, d4 = 10, d5 = 9, d6 = 8, d7 = 7;
 
//Define the variables
int in1 = 3;
int in2 = 4;
int out = 5;
int button = 6;
String gate = "";
 
//Create LCD object
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
 
void setup() {
 
  //Start Serial communication
  Serial.begin(9600);
 
  //Set pinModes
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(button, INPUT);
  pinMode(out, INPUT);
 
  //Initialize the lcd
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Electronics");
  lcd.setCursor(0, 1);
  lcd.print("Champ");
  Serial.println("Electronics Champ");
  delay(3000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Place a Gate and");
  lcd.setCursor(0, 1);
  lcd.print("press the button");
  Serial.println("Place a Gate and press the button");
 
}
 
void loop() {
 
  if (digitalRead(button) == HIGH) { //If the button is pressed...
 
    //Check if the gate is NOT or NOR
    checkNOT();
    checkNOR();
 
    //If the gate is neither NOR nor NOT, check for other gates
    if (gate == "") {
      digitalWrite(in1, 0);
      digitalWrite(in2, 0);
 
      if (digitalRead(out) == 0) {
        digitalWrite(in1, 0);
        digitalWrite(in2, 1);
 
        if (digitalRead(out) == 0) {
          gate = "AND";
        }
 
        else if (digitalRead(out) == 1) {
          digitalWrite(in1, 1);
          digitalWrite(in2, 1);
 
          if (digitalRead(out) == 0) {
            gate = "XOR";
          }
 
          else {
            gate = "OR";
          }
        }
      }
 
      else if (digitalRead(out) == 1) {
        gate = "NAND";
      }
    }
 
    if (isGatePresent() == true) { //If a gate IS PLACED AND the button is pressed...
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Gate: Logic ");
      lcd.print(gate);
      Serial.print("Gate: Logic ");
      Serial.print(gate);
      Serial.println();
      pinMode(in1, OUTPUT);
      pinMode(in2, INPUT);
      digitalWrite(in1, 0);
      delay(1000);
      gate = "";
    }
 
    else {
      checkNOT();
 
      if (gate != "NOT") {
        Serial.println("Place a gate for classification!!");
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Place a gate for");
        lcd.setCursor(0, 1);
        lcd.print("classification!!");
        digitalWrite(in1, HIGH);
        digitalWrite(in2, LOW);
        gate = "";
        delay(2000);
      }
 
      else if (gate == "NOT") {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Gate: Logic ");
        lcd.print("NOT");
        Serial.print("Gate: Logic ");
        Serial.print("NOT");
        Serial.println();
        pinMode(in1, OUTPUT);
        pinMode(in2, INPUT);
        digitalWrite(in1, 0);
        delay(1000);
        gate = "";
      }
 
    }
 
  }
 
}
 
void checkNOR() { //Check if the gate is NOR Gate
 
  pinMode(out, OUTPUT);
  pinMode(in1, INPUT);
  digitalWrite(out, 0);
  digitalWrite(in2, 0);
 
  if (digitalRead(in1) == 1) {
    digitalWrite(out, 0);
    digitalWrite(in2, 1);
 
    if (digitalRead(in1) == 0) {
      digitalWrite(out, 1);
      digitalWrite(in2, 0);
 
      if (digitalRead(in1) == 0) {
        digitalWrite(out, 1);
        digitalWrite(in2, 1);
 
        if (digitalRead(in1) == 0) {
          gate = "NOR";
        }
      }
    }
  }
 
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(button, INPUT);
  pinMode(out, INPUT);
 
}
 
void checkNOT() { //Check if the gate is NOT Gate
 
  pinMode(in2, INPUT);
  digitalWrite(in1, 0);
 
  if (digitalRead(in2) == 1) {
    digitalWrite(in1, 1);
 
    if (digitalRead(in2) == 0) {
      gate = "NOT";
      pinMode(in1, OUTPUT);
      pinMode(in2, INPUT);
    }
  }
 
  pinMode(in2, OUTPUT);
 
}
 
boolean isGatePresent() { //Check if a gate is placed
 
  digitalWrite(in1, 0);
  digitalWrite(in2, 0);
 
  if (digitalRead(out) == 0) {
    digitalWrite(in1, 0);
    digitalWrite(in2, 1);
 
    if (digitalRead(out) == 0) {
      digitalWrite(in1, 1);
      digitalWrite(in2, 0);
 
      if (digitalRead(out) == 0) {
        digitalWrite(in1, 1);
        digitalWrite(in2, 1);
 
        if (digitalRead(out) == 0) {
          checkNOR();
          checkNOT();
 
          if (gate != "NOR" and gate != "NOT") {
            return false;
          }
 
        }
 
        else {
          return true;
        }
 
      }
 
      else {
        return true;
      }
 
    }
 
    else {
      return true;
    }
 
  }
 
  else {
    return true;
  }
 
}

Code for Logic Gate Identifier with I2C

Arduino
Use this code if you are using I2C Module
/*
 
  This sketch can identify NOT, AND, NAND, OR, NOR, and XOR Gate ICs.
  When a gate is connected and a button is pressed, Arduino identifies
  the gate IC.
 
  This program is for LCD with I2C Module or without LCD
 
  This program is written by Shreyas for Electronics Champ YouTube Channel.
  Please subscribe to this channel. Thank You.
 
*/
 
//Including the libraries
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
 
//Define the variables
int in1 = 3;
int in2 = 4;
int out = 5;
int button = 6;
String gate = "";
 
//Create LCD_I2C object
LiquidCrystal_I2C lcd(0x27, 16, 2);
 
void setup() {
 
  //Start Serial communication
  Serial.begin(9600);
 
  //Set pinModes
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(button, INPUT);
  pinMode(out, INPUT);
 
  //Initialize the lcd
  lcd.init();
  lcd.begin(16, 2);
  lcd.clear();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Electronics");
  lcd.setCursor(0, 1);
  lcd.print("Champ");
  Serial.println("Electronics Champ");
  delay(3000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Place a Gate and");
  lcd.setCursor(0, 1);
  lcd.print("press the button");
  Serial.println("Place a Gate and press the button");
 
}
 
void loop() {
 
  if (digitalRead(button) == HIGH) { //If the button is pressed...
 
    //Check if the gate is NOT or NOR
    checkNOT();
    checkNOR();
 
    //If the gate is neither NOR nor NOT, check for other gates
    if (gate == "") {
      digitalWrite(in1, 0);
      digitalWrite(in2, 0);
 
      if (digitalRead(out) == 0) {
        digitalWrite(in1, 0);
        digitalWrite(in2, 1);
 
        if (digitalRead(out) == 0) {
          gate = "AND";
        }
 
        else if (digitalRead(out) == 1) {
          digitalWrite(in1, 1);
          digitalWrite(in2, 1);
 
          if (digitalRead(out) == 0) {
            gate = "XOR";
          }
 
          else {
            gate = "OR";
          }
        }
      }
 
      else if (digitalRead(out) == 1) {
        gate = "NAND";
      }
    }
 
    if (isGatePresent() == true) { //If a gate IS PLACED AND the button is pressed...
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Gate: Logic ");
      lcd.print(gate);
      Serial.print("Gate: Logic ");
      Serial.print(gate);
      Serial.println();
      pinMode(in1, OUTPUT);
      pinMode(in2, INPUT);
      digitalWrite(in1, 0);
      delay(1000);
      gate = "";
    }
 
    else {
      checkNOT();
 
      if (gate != "NOT") {
        Serial.println("Place a gate for classification!!");
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Place a gate for");
        lcd.setCursor(0, 1);
        lcd.print("classification!!");
        digitalWrite(in1, HIGH);
        digitalWrite(in2, LOW);
        gate = "";
        delay(2000);
      }
 
      else if (gate == "NOT") {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Gate: Logic ");
        lcd.print("NOT");
        Serial.print("Gate: Logic ");
        Serial.print("NOT");
        Serial.println();
        pinMode(in1, OUTPUT);
        pinMode(in2, INPUT);
        digitalWrite(in1, 0);
        delay(1000);
        gate = "";
      }
 
    }
 
  }
 
}
 
void checkNOR() { //Check if the gate is NOR Gate
 
  pinMode(out, OUTPUT);
  pinMode(in1, INPUT);
  digitalWrite(out, 0);
  digitalWrite(in2, 0);
 
  if (digitalRead(in1) == 1) {
    digitalWrite(out, 0);
    digitalWrite(in2, 1);
 
    if (digitalRead(in1) == 0) {
      digitalWrite(out, 1);
      digitalWrite(in2, 0);
 
      if (digitalRead(in1) == 0) {
        digitalWrite(out, 1);
        digitalWrite(in2, 1);
 
        if (digitalRead(in1) == 0) {
          gate = "NOR";
        }
      }
    }
  }
 
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(button, INPUT);
  pinMode(out, INPUT);
 
}
 
void checkNOT() { //Check if the gate is NOT Gate
 
  pinMode(in2, INPUT);
  digitalWrite(in1, 0);
 
  if (digitalRead(in2) == 1) {
    digitalWrite(in1, 1);
 
    if (digitalRead(in2) == 0) {
      gate = "NOT";
      pinMode(in1, OUTPUT);
      pinMode(in2, INPUT);
    }
  }
 
  pinMode(in2, OUTPUT);
 
}
 
boolean isGatePresent() { //Check if a gate is placed
 
  digitalWrite(in1, 0);
  digitalWrite(in2, 0);
 
  if (digitalRead(out) == 0) {
    digitalWrite(in1, 0);
    digitalWrite(in2, 1);
 
    if (digitalRead(out) == 0) {
      digitalWrite(in1, 1);
      digitalWrite(in2, 0);
 
      if (digitalRead(out) == 0) {
        digitalWrite(in1, 1);
        digitalWrite(in2, 1);
 
        if (digitalRead(out) == 0) {
          checkNOR();
          checkNOT();
 
          if (gate != "NOR" and gate != "NOT") {
            return false;
          }
 
        }
 
        else {
          return true;
        }
 
      }
 
      else {
        return true;
      }
 
    }
 
    else {
      return true;
    }
 
  }
 
  else {
    return true;
  }
 
}

Credits

Electronics Champ

Electronics Champ

4 projects • 11 followers
Projects based on breadboard electronics and Arduino with clear step-by-step instructions, circuit diagrams, schematics, and source code.

Comments