10. Logic Gate Implementation

Let’s understand the logic gates,

Truth tables of all gates give us a clear idea of how gates work.         

Input AInput BANDORNANDNOR
000011
010110
100110
111100
  • So, to implement gates, we will use two slide switches and four LEDs. Each LED will show the output of the respective gate logic.
  • We need to connect four LEDs to the microcontroller’s four GPIO pins.
  • We need a proper resistor for each LED to limit the current flowing through them to 10mA.

Calculating the Resistor Value

To ensure a 10 mA current through the LED, we need to select an appropriate resistor based on the supply voltage.

Case 1: 5V Supply

Resistor-calculation
  • LED forward voltage (Vf) = 1.8V (from datasheet)
  • Voltage across resistor (VR) = Supply voltage – Vf = 5V – 1.8V = 3.2V
  • Resistor value (R) = VR / I = 3.2V / 10 mA = 320 Ω

Standard resistor values near 320 Ω: 330 Ω or 300 Ω (whichever is available).

Similarly, Case 2: 3.3V Supply

  • Voltage across resistor (VR) = 3.3V – 1.8V = 1.5V
  • Resistor value (R) = 1.5V / 10 mA = 150 Ω

Standard resistor value: 150 Ω.

Slide Switch Connection:

  • The slide switch has three terminals. Terminal 2 (Middle) is common. We can connect the first terminal to VCC and the third terminal to GROUND or vice versa.
  • When the switch is at the left position, terminals 1 and 2 make contact. When the switch slides to the right, terminals 2 and 3 make contact.
slide-switch-symbol

So, by selecting a proper resistor, LED, and slide switch correctly, we can implement the task.

Below are the solutions to the given task using different microcontrollers

  1. STM32
  2. ESP32
  3. Arduino UNO