Overview

In this tutorial, we’ll create a AND gate circuit using the XD74LS08 AND IC. This circuit is used to demostrate the working of AND gate.

Creating the Circuit

Open snippets.tscircuit.com and create a new snippet.

First, let’s import our AND chip component (Using the import dialog at the top) and set up the basic structure:

import { useXD74LS08 } from "@tsci/Niharika0104.XD74LS08_AND_CHIP";

export default () => {
  const U1 = useXD74LS08("U1");

  return (
   <board width="30mm" height="42mm">
      <U1 />
    </board>
  )
}

Let’s add USBC

We can now integrate a USB-C component into our circuit to provide power.

Connections

  • Connect the VBUS1 pin of the USB-C component to net.VBUS.
  • Connect the GND1 pin of the USB-C component to net.GND.
  • The circuit’s VCC pin is connected to net.VBUS, and the GND pin is connected to net.GND.

Layout Adjustments

  • Schematic Layout (schX, schY): These values are adjusted to ensure the schematic is well-organized and visually less cluttered.
  • PCB Layout (pcbX, pcbY): These values are adjusted to achieve a neat and structured PCB design.
import { useXD74LS08 } from "@tsci/Niharika0104.XD74LS08_AND_CHIP";
import { useUsbC } from "@tsci/seveibar.smd-usb-c";

export default () => {
  const U1 = useXD74LS08("U1");
  const USBC = useUsbC("USBC");
  return (
   <board width="30mm" height="42mm">
      <U1 pcbX={0} pcbY={2} schX={8} schY={0} VCC="net.VBUS" GND="net.GND"/>
      <USBC GND1="net.GND" pcbX={-8} pcbY={-15} VBUS1="net.VBUS" schX={0} schY={0} />
    </board>
  )
}

Let’s add two push buttons

We will connect the pin3 and pin1 of the both the push buttons to the net.VBUS and net.GND networks respectively.

import { useXD74LS08 } from "@tsci/Niharika0104.XD74LS08_AND_CHIP";
import { useUsbC } from "@tsci/seveibar.smd-usb-c";
import { usePushButton } from "@tsci/seveibar.push-button";

export default () => {
  const U1 = useXD74LS08("U1");
  const USBC = useUsbC("USBC");
  const Button1 = usePushButton("SW1");
  const Button2 = usePushButton("SW2");

  return (
   <board width="30mm" height="42mm">

      <U1 pcbX={0} pcbY={2} schX={8} schY={0} VCC="net.VBUS" GND="net.GND"/>
      <USBC GND1="net.GND" pcbX={-8} pcbY={-15} VBUS1="net.VBUS" schX={0} schY={0} />

      <Button1 pcbX={-6} pcbY={-6} schX={5} schY={-5}  pin3="net.VBUS" pin1="net.GND"/>
      <Button2 pcbX={8} pcbY={-6} schX={5} schY={5} pin3="net.VBUS" pin1="net.GND"/>

    </board>
  )
}

Let’s go ahead and add resistors

The AND chip we’re using contains four AND gates. Let’s add resistors at the outputs of each gate to limit the current.

import { useXD74LS08 } from "@tsci/Niharika0104.XD74LS08_AND_CHIP";
import { useUsbC } from "@tsci/seveibar.smd-usb-c";
import { usePushButton } from "@tsci/seveibar.push-button";
import { useResistor } from "@tscircuit/core";

export default () => {

  const U1 = useXD74LS08("U1");
  const USBC = useUsbC("USBC");
  const Button1 = usePushButton("SW1");
  const Button2 = usePushButton("SW2");
  const R1 = useResistor("R1", {
    resistance: "1k",
    footprint: "0603",
  });
  const R2 = useResistor("R2", {
    resistance: "1k",
    footprint: "0603",
  });
  const R3 = useResistor("R3", {
    resistance: "1k",
    footprint: "0603",
  });
  const R4 = useResistor("R4", {
    resistance: "1k",
    footprint: "0603",
  });

  return (
   <board width="30mm" height="42mm">

      <U1 pcbX={0} pcbY={2} schX={8} schY={0} VCC="net.VBUS" GND="net.GND"/>
      <USBC GND1="net.GND" pcbX={-8} pcbY={-15} VBUS1="net.VBUS" schX={0} schY={0} />

      <Button1 pcbX={-6} pcbY={-6} schX={5} schY={-5}  pin3="net.VBUS" pin1="net.GND"/>
      <Button2 pcbX={8} pcbY={-6} schX={5} schY={5} pin3="net.VBUS" pin1="net.GND"/>
 
      <R1 pcbX={-6} pcbY={8} schX={12} schY={-6}  />

      <R2 pcbX={6} pcbY={8} schX={12} schY={-3} />

      <R3 pcbX={-6} pcbY={14} schX={12} schY={0}  />

      <R4 pcbX={6} pcbY={14} schX={12} schY={3} />

    </board>
  )
}

Let’s add LED’s

Let’s import useLed component and add four LED’s to see the output of each AND gate. We will connect the neg terminal of each LED to the net.GND network.

import { useXD74LS08 } from "@tsci/Niharika0104.XD74LS08_AND_CHIP";
import { useUsbC } from "@tsci/seveibar.smd-usb-c";
import { usePushButton } from "@tsci/seveibar.push-button";
import { useResistor,useLed } from "@tscircuit/core";

export default () => {

  const U1 = useXD74LS08("U1");
  const USBC = useUsbC("USBC");
  const Button1 = usePushButton("SW1");
  const Button2 = usePushButton("SW2");
  const R1 = useResistor("R1", {
    resistance: "1k",
    footprint: "0603",
  });
  const R2 = useResistor("R2", {
    resistance: "1k",
    footprint: "0603",
  });
  const R3 = useResistor("R3", {
    resistance: "1k",
    footprint: "0603",
  });
  const R4 = useResistor("R4", {
    resistance: "1k",
    footprint: "0603",
  });
  const LED1 = useLed("LED1", { footprint: "0603" });
  const LED2 = useLed("LED2", { footprint: "0603" });
  const LED3 = useLed("LED3", { footprint: "0603" });
  const LED4 = useLed("LED4", { footprint: "0603" });

  return (
   <board width="30mm" height="42mm">

      <U1 pcbX={0} pcbY={2} schX={8} schY={0} VCC="net.VBUS" GND="net.GND"/>
      <USBC GND1="net.GND" pcbX={-8} pcbY={-15} VBUS1="net.VBUS" schX={0} schY={0} />

      <Button1 pcbX={-6} pcbY={-6} schX={5} schY={-5}  pin3="net.VBUS" pin1="net.GND"/>
      <Button2 pcbX={8} pcbY={-6} schX={5} schY={5} pin3="net.VBUS" pin1="net.GND"/>
 
      <R1 pcbX={-6} pcbY={8} schX={12} schY={-6}  left={U1.Y1}/>
      <LED1 pcbX={-6} pcbY={11} schX={14} schY={-6}  neg="net.GND" />

      <R2 pcbX={6} pcbY={8} schX={12} schY={-3} left={U1.Y2}/>
      <LED2 pcbX={6} pcbY={11} schX={14} schY={-3}  neg="net.GND"/>

      <R3 pcbX={-6} pcbY={14} schX={12} schY={0} left={U1.Y3} />
      <LED3 pcbX={-6} pcbY={17} schX={14} schY={0}  neg="net.GND" />

      <R4 pcbX={6} pcbY={14} schX={12} schY={3} left={U1.Y4} />
      <LED4 pcbX={6} pcbY={17} schX={14} schY={3}  neg="net.GND"/>

    </board>
  )
}

Let’s add traces and connect everything.

import { useXD74LS08 } from "@tsci/Niharika0104.XD74LS08_AND_CHIP";
import { useUsbC } from "@tsci/seveibar.smd-usb-c";
import { usePushButton } from "@tsci/seveibar.push-button";
import { useResistor,useLed } from "@tscircuit/core";

export default () => {

  const U1 = useXD74LS08("U1");
  const USBC = useUsbC("USBC");
  const Button1 = usePushButton("SW1");
  const Button2 = usePushButton("SW2");
  const R1 = useResistor("R1", {
    resistance: "1k",
    footprint: "0603",
  });
  const R2 = useResistor("R2", {
    resistance: "1k",
    footprint: "0603",
  });
  const R3 = useResistor("R3", {
    resistance: "1k",
    footprint: "0603",
  });
  const R4 = useResistor("R4", {
    resistance: "1k",
    footprint: "0603",
  });
  const LED1 = useLed("LED1", { footprint: "0603" });
  const LED2 = useLed("LED2", { footprint: "0603" });
  const LED3 = useLed("LED3", { footprint: "0603" });
  const LED4 = useLed("LED4", { footprint: "0603" });

  return (
   <board width="30mm" height="42mm">

      <U1 pcbX={0} pcbY={2} schX={8} schY={0} VCC="net.VBUS" GND="net.GND"/>
      <USBC GND1="net.GND" pcbX={-8} pcbY={-15} VBUS1="net.VBUS" schX={0} schY={0} />

      <Button1 pcbX={-6} pcbY={-6} schX={5} schY={-5}  pin3="net.VBUS" pin1="net.GND"/>
      <Button2 pcbX={8} pcbY={-6} schX={5} schY={5} pin3="net.VBUS" pin1="net.GND"/>
 
      <R1 pcbX={-6} pcbY={8} schX={12} schY={-6}  left={U1.Y1}/>
      <LED1 pcbX={-6} pcbY={11} schX={14} schY={-6}  neg="net.GND" />

      <R2 pcbX={6} pcbY={8} schX={12} schY={-3} left={U1.Y2}/>
      <LED2 pcbX={6} pcbY={11} schX={14} schY={-3}  neg="net.GND"/>

      <R3 pcbX={-6} pcbY={14} schX={12} schY={0} left={U1.Y3} />
      <LED3 pcbX={-6} pcbY={17} schX={14} schY={0}  neg="net.GND" />

      <R4 pcbX={6} pcbY={14} schX={12} schY={3} left={U1.Y4} />
      <LED4 pcbX={6} pcbY={17} schX={14} schY={3}  neg="net.GND"/>
      
      {/* Connections to the inputs of the four AND gates on U1 */}
      <trace from={U1.A1} to=".SW1 > .pin2" />
      <trace from={U1.B1} to=".SW1 > .pin2" />
      <trace from={U1.A2} to=".SW2 > .pin2" />
      <trace from={U1.B2} to=".SW2 > .pin2" />
      <trace from={U1.A3} to=".SW1 > .pin2" />
      <trace from={U1.B3} to=".SW2 > .pin2" />
      <trace from={U1.A4} to="net.VBUS" />
      <trace from={U1.B4} to="net.VBUS" />
   
      {/* Connections from resistor outputs to the positive terminals of the LEDs */}
      <trace from={R1.pin2} to={LED1.pos} />
      <trace from={R2.pin2} to={LED2.pos} />
      <trace from={R3.pin2} to={LED3.pos} />
      <trace from={R4.pin2} to={LED4.pos} />

    </board>
  )
}

Desired Behavior

  1. Button 1 Pressed (SW1):

    • LED1 should turn on.
  2. Button 2 Pressed (SW2):

    • LED2 should turn on.
  3. Both Buttons Pressed Simultaneously (SW1 and SW2):

    • LED3 should turn on (LED1 and LED2 might turn on as well).
  4. USB-C Powered (VBUS):

    • LED4 should always turn on as long as the USB-C is powered.

Pin Configuration of XD74LS08

Power Pins

  • VCC: Supplies power to the chip (typically 5V for TTL logic).
  • GND: Ground connection to complete the circuit.

Input Pins

Each AND gate has two input pins:

  • A1, B1: Inputs for Gate 1.
  • A2, B2: Inputs for Gate 2.
  • A3, B3: Inputs for Gate 3.
  • A4, B4: Inputs for Gate 4.

Output Pins

Each AND gate has one output pin:

  • Y1: Output for Gate 1.
  • Y2: Output for Gate 2.
  • Y3: Output for Gate 3.
  • Y4: Output for Gate 4.

Testing Your Circuit

Click “Run” to see your circuit. You can switch between different views:

Schematic view showing component connections

Switch to the PCB view to see the physical layout:

PCB view showing component placement and traces

And check the 3D view to preview the final board:

3D preview of the assembled circuit

Want to see this circuit in action? Check out the live example

Exporting Your Design

You can export your design in various formats:

  • Gerber files for PCB manufacturing
  • KiCad format for further editing
  • STEP files for mechanical design

Click the “Export” button and choose your desired format.

Remember to save your snippet if you want to share it or use it in other projects!