All submissions

Logic Gate Implementation

Solving Approach

How do you plan to solve it?

 To solve the logic gate implementation using an ESP32, I would begin by connecting two push-button switches to designated GPIO pins configured with internal pull-up resistors, allowing them to act as digital inputs. Each button press would pull the pin LOW, enabling the microcontroller to detect user interaction. Next, I would connect four LEDs to separate GPIO output pins, each representing the output of a different logic gate: AND, OR, NAND, and NOR. In the code, I would continuously read the state of both buttons and apply the corresponding logic operations. For example, the AND LED would turn on only when both buttons are pressed simultaneously, while the OR LED would light up if either button is pressed. The NAND and NOR outputs would be the inverse of AND and OR, respectively. Each LED would be wired in series with a current-limiting resistor to prevent damage. This setup provides a clear and interactive way to visualize digital logic operations in real time, making it ideal for educational demonstrations or foundational embedded systems projects.
 

 

 

 

Code

const int inputA = 18;
const int inputB = 19;
const int andLED = 23;
const int orLED = 22;
const int nandLED = 21;
const int norLED = 20;

void setup() {
  pinMode(inputA, INPUT_PULLUP);
  pinMode(inputB, INPUT_PULLUP);
  pinMode(andLED, OUTPUT);
  pinMode(orLED, OUTPUT);
  pinMode(nandLED, OUTPUT);
  pinMode(norLED, OUTPUT);
}

void loop() {
  bool A = !digitalRead(inputA); // Active LOW
  bool B = !digitalRead(inputB);

  digitalWrite(andLED, A && B);
  digitalWrite(orLED, A || B);
  digitalWrite(nandLED, !(A && B));
  digitalWrite(norLED, !(A || B));
}



 

 

 

Output

Video

Add a video of the output (know more)

https://drive.google.com/file/d/1D_Sea6-yUl1zhcpEmgkxvHSYFIl-uVHh/view?usp=drive_link

 

 

 

Submit Your Solution

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