Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 2 | ||||
| × | 1 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
|
This video shows how to identify Basic Logic Gate ICs, viz. NOT, AND, NAND, OR, NOR and XOR using Arduino.
When a Logic Gate IC is placed on the Breadboard and a Push Button is pressed, the Arduino writes 1s and 0s to the inputs of the IC and identifies it.
This project is useful if the serial number of the IC is erased.
For detailed instructions on how to make this project, watch this video:
/*
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;
}
}
/*
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;
}
}
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