All submissions

Logic Gate Implementation

Solving Approach

How do you plan to solve it?

  •  Two switches are connected between Ground and 5V, and connected to Arduino pins 0 and 1 which are declared as INPUT_PULLUP.
  • Four logic gates (AND, OR, NAND, NOR) are represented using LEDs connected in series with 330 Ohm resistors.
  • Each LED-resistor pair is connected between a digital output pin and Ground.
  • The digital pins are declared as OUTPUT, and the program controls them based on the input switch states to simulate the logic gate outputs.
     

 

 

 

Code

#define INPUTA 2
#define INPUTB 3

#define ORGATE     13
#define ANDGATE    12
#define NORGATE    11
#define NANDGATE   10

void setup() {
  pinMode(INPUTA, INPUT_PULLUP);
  pinMode(INPUTB, INPUT_PULLUP);

  pinMode(ORGATE, OUTPUT);
  pinMode(ANDGATE, OUTPUT);
  pinMode(NORGATE, OUTPUT);
  pinMode(NANDGATE, OUTPUT);
}

void loop() {
  int inputA = !digitalRead(INPUTA);
  int inputB = !digitalRead(INPUTB);

  digitalWrite(ORGATE, inputA || inputB);
  digitalWrite(ANDGATE, inputA && inputB);
  digitalWrite(NORGATE, !(inputA || inputB));
  digitalWrite(NANDGATE, !(inputA && inputB));
}



 

 

 

Output

Video

Add a video of the output (know more)

 

 

 

 

Submit Your Solution

Note: Once submitted, your solution goes public, helping others learn from your approach!