Components and supplies
SparkFun Serial Enabled 16x2 LCD - White on Black 3.3V
Solderless Breadboard Full Size
Arduino Nano R3
Jumper wires (generic)
Basic Logic Gate ICs (To be identified)
I2C Module (Optional)
Push Button Switch
Resistor 220 ohm
Apps and platforms
Arduino IDE
Project description
Code
Code for Logic Gate Identifier without I2C
arduino
Use this code if you are not using I2C Module
1/* 2 3 This sketch can identify NOT, AND, NAND, OR, NOR, and XOR 4 Gate ICs. 5 When a gate is connected and a button is pressed, Arduino identifies 6 7 the gate IC. 8 9 This program is for LCD without I2C Module or without LCD 10 11 12 This program is written by Shreyas for Electronics Champ YouTube Channel. 13 14 Please subscribe to this channel. Thank You. 15 16*/ 17 18//Including the 19 libraries 20#include <LiquidCrystal.h> 21 22const int rs = 12, en = 11, d4 = 23 10, d5 = 9, d6 = 8, d7 = 7; 24 25//Define the variables 26int in1 = 3; 27int 28 in2 = 4; 29int out = 5; 30int button = 6; 31String gate = ""; 32 33//Create 34 LCD object 35LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 36 37void setup() { 38 39 40 //Start Serial communication 41 Serial.begin(9600); 42 43 //Set pinModes 44 45 pinMode(in1, OUTPUT); 46 pinMode(in2, OUTPUT); 47 pinMode(button, INPUT); 48 49 pinMode(out, INPUT); 50 51 //Initialize the lcd 52 lcd.begin(16, 2); 53 54 lcd.clear(); 55 lcd.setCursor(0, 0); 56 lcd.print("Electronics"); 57 lcd.setCursor(0, 58 1); 59 lcd.print("Champ"); 60 Serial.println("Electronics Champ"); 61 delay(3000); 62 63 lcd.clear(); 64 lcd.setCursor(0, 0); 65 lcd.print("Place a Gate and"); 66 67 lcd.setCursor(0, 1); 68 lcd.print("press the button"); 69 Serial.println("Place 70 a Gate and press the button"); 71 72} 73 74void loop() { 75 76 if (digitalRead(button) 77 == HIGH) { //If the button is pressed... 78 79 //Check if the gate is NOT 80 or NOR 81 checkNOT(); 82 checkNOR(); 83 84 //If the gate is neither 85 NOR nor NOT, check for other gates 86 if (gate == "") { 87 digitalWrite(in1, 88 0); 89 digitalWrite(in2, 0); 90 91 if (digitalRead(out) == 0) { 92 93 digitalWrite(in1, 0); 94 digitalWrite(in2, 1); 95 96 if 97 (digitalRead(out) == 0) { 98 gate = "AND"; 99 } 100 101 else 102 if (digitalRead(out) == 1) { 103 digitalWrite(in1, 1); 104 digitalWrite(in2, 105 1); 106 107 if (digitalRead(out) == 0) { 108 gate = "XOR"; 109 110 } 111 112 else { 113 gate = "OR"; 114 } 115 116 } 117 } 118 119 else if (digitalRead(out) == 1) { 120 gate 121 = "NAND"; 122 } 123 } 124 125 if (isGatePresent() == true) { //If 126 a gate IS PLACED AND the button is pressed... 127 lcd.clear(); 128 lcd.setCursor(0, 129 0); 130 lcd.print("Gate: Logic "); 131 lcd.print(gate); 132 Serial.print("Gate: 133 Logic "); 134 Serial.print(gate); 135 Serial.println(); 136 pinMode(in1, 137 OUTPUT); 138 pinMode(in2, INPUT); 139 digitalWrite(in1, 0); 140 delay(1000); 141 142 gate = ""; 143 } 144 145 else { 146 checkNOT(); 147 148 if 149 (gate != "NOT") { 150 Serial.println("Place a gate for classification!!"); 151 152 lcd.clear(); 153 lcd.setCursor(0, 0); 154 lcd.print("Place 155 a gate for"); 156 lcd.setCursor(0, 1); 157 lcd.print("classification!!"); 158 159 digitalWrite(in1, HIGH); 160 digitalWrite(in2, LOW); 161 gate 162 = ""; 163 delay(2000); 164 } 165 166 else if (gate == "NOT") 167 { 168 lcd.clear(); 169 lcd.setCursor(0, 0); 170 lcd.print("Gate: 171 Logic "); 172 lcd.print("NOT"); 173 Serial.print("Gate: Logic 174 "); 175 Serial.print("NOT"); 176 Serial.println(); 177 pinMode(in1, 178 OUTPUT); 179 pinMode(in2, INPUT); 180 digitalWrite(in1, 0); 181 delay(1000); 182 183 gate = ""; 184 } 185 186 } 187 188 } 189 190} 191 192void 193 checkNOR() { //Check if the gate is NOR Gate 194 195 pinMode(out, OUTPUT); 196 197 pinMode(in1, INPUT); 198 digitalWrite(out, 0); 199 digitalWrite(in2, 0); 200 201 202 if (digitalRead(in1) == 1) { 203 digitalWrite(out, 0); 204 digitalWrite(in2, 205 1); 206 207 if (digitalRead(in1) == 0) { 208 digitalWrite(out, 1); 209 210 digitalWrite(in2, 0); 211 212 if (digitalRead(in1) == 0) { 213 digitalWrite(out, 214 1); 215 digitalWrite(in2, 1); 216 217 if (digitalRead(in1) == 0) 218 { 219 gate = "NOR"; 220 } 221 } 222 } 223 } 224 225 226 pinMode(in1, OUTPUT); 227 pinMode(in2, OUTPUT); 228 pinMode(button, INPUT); 229 230 pinMode(out, INPUT); 231 232} 233 234void checkNOT() { //Check if the gate is 235 NOT Gate 236 237 pinMode(in2, INPUT); 238 digitalWrite(in1, 0); 239 240 if 241 (digitalRead(in2) == 1) { 242 digitalWrite(in1, 1); 243 244 if (digitalRead(in2) 245 == 0) { 246 gate = "NOT"; 247 pinMode(in1, OUTPUT); 248 pinMode(in2, 249 INPUT); 250 } 251 } 252 253 pinMode(in2, OUTPUT); 254 255} 256 257boolean 258 isGatePresent() { //Check if a gate is placed 259 260 digitalWrite(in1, 0); 261 262 digitalWrite(in2, 0); 263 264 if (digitalRead(out) == 0) { 265 digitalWrite(in1, 266 0); 267 digitalWrite(in2, 1); 268 269 if (digitalRead(out) == 0) { 270 digitalWrite(in1, 271 1); 272 digitalWrite(in2, 0); 273 274 if (digitalRead(out) == 0) { 275 276 digitalWrite(in1, 1); 277 digitalWrite(in2, 1); 278 279 if 280 (digitalRead(out) == 0) { 281 checkNOR(); 282 checkNOT(); 283 284 285 if (gate != "NOR" and gate != "NOT") { 286 return false; 287 288 } 289 290 } 291 292 else { 293 return true; 294 295 } 296 297 } 298 299 else { 300 return true; 301 } 302 303 304 } 305 306 else { 307 return true; 308 } 309 310 } 311 312 313 else { 314 return true; 315 } 316 317} 318
Code for Logic Gate Identifier without I2C
arduino
Use this code if you are not using I2C Module
1/* 2 3 This sketch can identify NOT, AND, NAND, OR, NOR, and XOR Gate ICs. 4 When a gate is connected and a button is pressed, Arduino identifies 5 the gate IC. 6 7 This program is for LCD without I2C Module or without LCD 8 9 This program is written by Shreyas for Electronics Champ YouTube Channel. 10 Please subscribe to this channel. Thank You. 11 12*/ 13 14//Including the libraries 15#include <LiquidCrystal.h> 16 17const int rs = 12, en = 11, d4 = 10, d5 = 9, d6 = 8, d7 = 7; 18 19//Define the variables 20int in1 = 3; 21int in2 = 4; 22int out = 5; 23int button = 6; 24String gate = ""; 25 26//Create LCD object 27LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 28 29void setup() { 30 31 //Start Serial communication 32 Serial.begin(9600); 33 34 //Set pinModes 35 pinMode(in1, OUTPUT); 36 pinMode(in2, OUTPUT); 37 pinMode(button, INPUT); 38 pinMode(out, INPUT); 39 40 //Initialize the lcd 41 lcd.begin(16, 2); 42 lcd.clear(); 43 lcd.setCursor(0, 0); 44 lcd.print("Electronics"); 45 lcd.setCursor(0, 1); 46 lcd.print("Champ"); 47 Serial.println("Electronics Champ"); 48 delay(3000); 49 lcd.clear(); 50 lcd.setCursor(0, 0); 51 lcd.print("Place a Gate and"); 52 lcd.setCursor(0, 1); 53 lcd.print("press the button"); 54 Serial.println("Place a Gate and press the button"); 55 56} 57 58void loop() { 59 60 if (digitalRead(button) == HIGH) { //If the button is pressed... 61 62 //Check if the gate is NOT or NOR 63 checkNOT(); 64 checkNOR(); 65 66 //If the gate is neither NOR nor NOT, check for other gates 67 if (gate == "") { 68 digitalWrite(in1, 0); 69 digitalWrite(in2, 0); 70 71 if (digitalRead(out) == 0) { 72 digitalWrite(in1, 0); 73 digitalWrite(in2, 1); 74 75 if (digitalRead(out) == 0) { 76 gate = "AND"; 77 } 78 79 else if (digitalRead(out) == 1) { 80 digitalWrite(in1, 1); 81 digitalWrite(in2, 1); 82 83 if (digitalRead(out) == 0) { 84 gate = "XOR"; 85 } 86 87 else { 88 gate = "OR"; 89 } 90 } 91 } 92 93 else if (digitalRead(out) == 1) { 94 gate = "NAND"; 95 } 96 } 97 98 if (isGatePresent() == true) { //If a gate IS PLACED AND the button is pressed... 99 lcd.clear(); 100 lcd.setCursor(0, 0); 101 lcd.print("Gate: Logic "); 102 lcd.print(gate); 103 Serial.print("Gate: Logic "); 104 Serial.print(gate); 105 Serial.println(); 106 pinMode(in1, OUTPUT); 107 pinMode(in2, INPUT); 108 digitalWrite(in1, 0); 109 delay(1000); 110 gate = ""; 111 } 112 113 else { 114 checkNOT(); 115 116 if (gate != "NOT") { 117 Serial.println("Place a gate for classification!!"); 118 lcd.clear(); 119 lcd.setCursor(0, 0); 120 lcd.print("Place a gate for"); 121 lcd.setCursor(0, 1); 122 lcd.print("classification!!"); 123 digitalWrite(in1, HIGH); 124 digitalWrite(in2, LOW); 125 gate = ""; 126 delay(2000); 127 } 128 129 else if (gate == "NOT") { 130 lcd.clear(); 131 lcd.setCursor(0, 0); 132 lcd.print("Gate: Logic "); 133 lcd.print("NOT"); 134 Serial.print("Gate: Logic "); 135 Serial.print("NOT"); 136 Serial.println(); 137 pinMode(in1, OUTPUT); 138 pinMode(in2, INPUT); 139 digitalWrite(in1, 0); 140 delay(1000); 141 gate = ""; 142 } 143 144 } 145 146 } 147 148} 149 150void checkNOR() { //Check if the gate is NOR Gate 151 152 pinMode(out, OUTPUT); 153 pinMode(in1, INPUT); 154 digitalWrite(out, 0); 155 digitalWrite(in2, 0); 156 157 if (digitalRead(in1) == 1) { 158 digitalWrite(out, 0); 159 digitalWrite(in2, 1); 160 161 if (digitalRead(in1) == 0) { 162 digitalWrite(out, 1); 163 digitalWrite(in2, 0); 164 165 if (digitalRead(in1) == 0) { 166 digitalWrite(out, 1); 167 digitalWrite(in2, 1); 168 169 if (digitalRead(in1) == 0) { 170 gate = "NOR"; 171 } 172 } 173 } 174 } 175 176 pinMode(in1, OUTPUT); 177 pinMode(in2, OUTPUT); 178 pinMode(button, INPUT); 179 pinMode(out, INPUT); 180 181} 182 183void checkNOT() { //Check if the gate is NOT Gate 184 185 pinMode(in2, INPUT); 186 digitalWrite(in1, 0); 187 188 if (digitalRead(in2) == 1) { 189 digitalWrite(in1, 1); 190 191 if (digitalRead(in2) == 0) { 192 gate = "NOT"; 193 pinMode(in1, OUTPUT); 194 pinMode(in2, INPUT); 195 } 196 } 197 198 pinMode(in2, OUTPUT); 199 200} 201 202boolean isGatePresent() { //Check if a gate is placed 203 204 digitalWrite(in1, 0); 205 digitalWrite(in2, 0); 206 207 if (digitalRead(out) == 0) { 208 digitalWrite(in1, 0); 209 digitalWrite(in2, 1); 210 211 if (digitalRead(out) == 0) { 212 digitalWrite(in1, 1); 213 digitalWrite(in2, 0); 214 215 if (digitalRead(out) == 0) { 216 digitalWrite(in1, 1); 217 digitalWrite(in2, 1); 218 219 if (digitalRead(out) == 0) { 220 checkNOR(); 221 checkNOT(); 222 223 if (gate != "NOR" and gate != "NOT") { 224 return false; 225 } 226 227 } 228 229 else { 230 return true; 231 } 232 233 } 234 235 else { 236 return true; 237 } 238 239 } 240 241 else { 242 return true; 243 } 244 245 } 246 247 else { 248 return true; 249 } 250 251} 252
Code for Logic Gate Identifier with I2C
arduino
Use this code if you are using I2C Module
1/* 2 3 This sketch can identify NOT, AND, NAND, OR, NOR, and XOR Gate ICs. 4 When a gate is connected and a button is pressed, Arduino identifies 5 the gate IC. 6 7 This program is for LCD with I2C Module or without LCD 8 9 This program is written by Shreyas for Electronics Champ YouTube Channel. 10 Please subscribe to this channel. Thank You. 11 12*/ 13 14//Including the libraries 15#include <Wire.h> 16#include <LiquidCrystal_I2C.h> 17 18//Define the variables 19int in1 = 3; 20int in2 = 4; 21int out = 5; 22int button = 6; 23String gate = ""; 24 25//Create LCD_I2C object 26LiquidCrystal_I2C lcd(0x27, 16, 2); 27 28void setup() { 29 30 //Start Serial communication 31 Serial.begin(9600); 32 33 //Set pinModes 34 pinMode(in1, OUTPUT); 35 pinMode(in2, OUTPUT); 36 pinMode(button, INPUT); 37 pinMode(out, INPUT); 38 39 //Initialize the lcd 40 lcd.init(); 41 lcd.begin(16, 2); 42 lcd.clear(); 43 lcd.backlight(); 44 lcd.setCursor(0, 0); 45 lcd.print("Electronics"); 46 lcd.setCursor(0, 1); 47 lcd.print("Champ"); 48 Serial.println("Electronics Champ"); 49 delay(3000); 50 lcd.clear(); 51 lcd.setCursor(0, 0); 52 lcd.print("Place a Gate and"); 53 lcd.setCursor(0, 1); 54 lcd.print("press the button"); 55 Serial.println("Place a Gate and press the button"); 56 57} 58 59void loop() { 60 61 if (digitalRead(button) == HIGH) { //If the button is pressed... 62 63 //Check if the gate is NOT or NOR 64 checkNOT(); 65 checkNOR(); 66 67 //If the gate is neither NOR nor NOT, check for other gates 68 if (gate == "") { 69 digitalWrite(in1, 0); 70 digitalWrite(in2, 0); 71 72 if (digitalRead(out) == 0) { 73 digitalWrite(in1, 0); 74 digitalWrite(in2, 1); 75 76 if (digitalRead(out) == 0) { 77 gate = "AND"; 78 } 79 80 else if (digitalRead(out) == 1) { 81 digitalWrite(in1, 1); 82 digitalWrite(in2, 1); 83 84 if (digitalRead(out) == 0) { 85 gate = "XOR"; 86 } 87 88 else { 89 gate = "OR"; 90 } 91 } 92 } 93 94 else if (digitalRead(out) == 1) { 95 gate = "NAND"; 96 } 97 } 98 99 if (isGatePresent() == true) { //If a gate IS PLACED AND the button is pressed... 100 lcd.clear(); 101 lcd.setCursor(0, 0); 102 lcd.print("Gate: Logic "); 103 lcd.print(gate); 104 Serial.print("Gate: Logic "); 105 Serial.print(gate); 106 Serial.println(); 107 pinMode(in1, OUTPUT); 108 pinMode(in2, INPUT); 109 digitalWrite(in1, 0); 110 delay(1000); 111 gate = ""; 112 } 113 114 else { 115 checkNOT(); 116 117 if (gate != "NOT") { 118 Serial.println("Place a gate for classification!!"); 119 lcd.clear(); 120 lcd.setCursor(0, 0); 121 lcd.print("Place a gate for"); 122 lcd.setCursor(0, 1); 123 lcd.print("classification!!"); 124 digitalWrite(in1, HIGH); 125 digitalWrite(in2, LOW); 126 gate = ""; 127 delay(2000); 128 } 129 130 else if (gate == "NOT") { 131 lcd.clear(); 132 lcd.setCursor(0, 0); 133 lcd.print("Gate: Logic "); 134 lcd.print("NOT"); 135 Serial.print("Gate: Logic "); 136 Serial.print("NOT"); 137 Serial.println(); 138 pinMode(in1, OUTPUT); 139 pinMode(in2, INPUT); 140 digitalWrite(in1, 0); 141 delay(1000); 142 gate = ""; 143 } 144 145 } 146 147 } 148 149} 150 151void checkNOR() { //Check if the gate is NOR Gate 152 153 pinMode(out, OUTPUT); 154 pinMode(in1, INPUT); 155 digitalWrite(out, 0); 156 digitalWrite(in2, 0); 157 158 if (digitalRead(in1) == 1) { 159 digitalWrite(out, 0); 160 digitalWrite(in2, 1); 161 162 if (digitalRead(in1) == 0) { 163 digitalWrite(out, 1); 164 digitalWrite(in2, 0); 165 166 if (digitalRead(in1) == 0) { 167 digitalWrite(out, 1); 168 digitalWrite(in2, 1); 169 170 if (digitalRead(in1) == 0) { 171 gate = "NOR"; 172 } 173 } 174 } 175 } 176 177 pinMode(in1, OUTPUT); 178 pinMode(in2, OUTPUT); 179 pinMode(button, INPUT); 180 pinMode(out, INPUT); 181 182} 183 184void checkNOT() { //Check if the gate is NOT Gate 185 186 pinMode(in2, INPUT); 187 digitalWrite(in1, 0); 188 189 if (digitalRead(in2) == 1) { 190 digitalWrite(in1, 1); 191 192 if (digitalRead(in2) == 0) { 193 gate = "NOT"; 194 pinMode(in1, OUTPUT); 195 pinMode(in2, INPUT); 196 } 197 } 198 199 pinMode(in2, OUTPUT); 200 201} 202 203boolean isGatePresent() { //Check if a gate is placed 204 205 digitalWrite(in1, 0); 206 digitalWrite(in2, 0); 207 208 if (digitalRead(out) == 0) { 209 digitalWrite(in1, 0); 210 digitalWrite(in2, 1); 211 212 if (digitalRead(out) == 0) { 213 digitalWrite(in1, 1); 214 digitalWrite(in2, 0); 215 216 if (digitalRead(out) == 0) { 217 digitalWrite(in1, 1); 218 digitalWrite(in2, 1); 219 220 if (digitalRead(out) == 0) { 221 checkNOR(); 222 checkNOT(); 223 224 if (gate != "NOR" and gate != "NOT") { 225 return false; 226 } 227 228 } 229 230 else { 231 return true; 232 } 233 234 } 235 236 else { 237 return true; 238 } 239 240 } 241 242 else { 243 return true; 244 } 245 246 } 247 248 else { 249 return true; 250 } 251 252} 253
Downloadable files
Schematic
Please refer to the given schematic if you are not using I2C Module
Schematic
Schematic
Please refer to the given schematic if you are using I2C Module
Schematic
Schematic
Please refer to the given schematic if you are using I2C Module
Schematic
Schematic
Please refer to the given schematic if you are using I2C Module
Schematic
Comments
Only logged in users can leave comments