All submissions

Solving Approach

1. Connect two push buttons as input switches to Arduino (using INPUT_PULLUP so that pressed = LOW, not pressed = HIGH).

 

2. Connect four LEDs to Arduino output pins with resistors. Each LED will represent the output of a logic gate:

LED1 → AND gate output

LED2 → OR gate output

LED3 → NAND gate output

LED4 → NOR gate output

 

3. In the code, read the state of the two switches (A and B).

 

4. Compute the gate outputs:

AND = A && B

OR = A || B

NAND = !(A && B)

NOR = !(A || B)

 

5. Write these outputs to the respective LEDs.

 

6. As buttons use pull-ups, invert the input (LOW = pressed, HIGH = not pressed).

 

 
 

 

 

 

Code

// Pin assignment
const int switchA = 2;   // Input A
const int switchB = 3;   // Input B
const int ledAND  = 4;   // AND output
const int ledOR   = 5;   // OR output
const int ledNAND = 6;   // NAND output
const int ledNOR  = 7;   // NOR output
void setup() {
  // Input setup with internal pull-ups
    pinMode(switchA, INPUT_PULLUP);
      pinMode(switchB, INPUT_PULLUP);
        // Output LEDs
          pinMode(ledAND, OUTPUT);
            pinMode(ledOR, OUTPUT);
              pinMode(ledNAND, OUTPUT);
                pinMode(ledNOR, OUTPUT);
                }
                void loop() {
                  //


 

 

 

Output

The output is shown by the 4 LEDs, each one representing a logic gate result.

Let’s define:

SW A = Switch A (Input A)

SW B = Switch B (Input B)

1 = switch pressed

0 = switch not pressed

Video

 

 

 

 

Submit Your Solution

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