All submissions

Logic Gate Implementation

Solving Approach

How do you plan to solve it?

 To implement the logic gates, we will build a circuit using two push-buttons as inputs and four LEDs as outputs on an Arduino UNO. The Arduino will act as the processor, performing the logic operations in software.

  • Hardware Setup: We will use two push-buttons for our inputs (Input A and Input B) and four LEDs to display the outputs for the OR, AND, NOR, and NAND gates.
  • Wiring: To simplify the circuit, we'll use the Arduino's internal pull-up resistors for the push-buttons. This means a button press will register as a LOW signal. Each of the four LEDs will require a 330Ω resistor in series to limit the current and protect them from damage. The LEDs will be wired to separate digital output pins.
  • Software Logic: The code will continuously read the states of the two input pins. The output for each LED will be determined by applying the respective logical operator (AND, OR, NOT) to the input states. The digitalWrite() function will then be used to turn the corresponding LEDs on or off.
     

Code

/*Paste your code here*/
// Define the input pins for the two switches
const int inputA_pin = 2;
const int inputB_pin = 3;

// Define the output pins for the four LEDs
const int or_led_pin = 8;
const int and_led_pin = 9;
const int nand_led_pin = 10;
const int nor_led_pin = 11;

void setup() {
  // Set the input pins with internal pull-up resistors
  pinMode(inputA_pin, INPUT_PULLUP);
  pinMode(inputB_pin, INPUT_PULLUP);
  
  // Set the LED pins as outputs
  pinMode(or_led_pin, OUTPUT);
  pinMode(and_led_pin, OUTPUT);
  pinMode(nand_led_pin, OUTPUT);
  pinMode(nor_led_pin, OUTPUT);
}

void loop() {
  // Read the state of the buttons
  // A button press reads as LOW due to the internal pull-up resistor
  bool inputA = !digitalRead(inputA_pin); // Invert the logic for clarity
  bool inputB = !digitalRead(inputB_pin);

  // Implement the logic for each gate and set the LED outputs

  // OR Gate: True if input A OR input B is true
  digitalWrite(or_led_pin, inputA || inputB);

  // AND Gate: True if input A AND input B are both true
  digitalWrite(and_led_pin, inputA && inputB);
  
  // NAND Gate: The inverse of AND
  digitalWrite(nand_led_pin, !(inputA && inputB));
  
  // NOR Gate: The inverse of OR
  digitalWrite(nor_led_pin, !(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!