davixcky/bjt

This code models a hardware circuit featuring a 12V power supply, an NPN transistor (2N2222), several resistors and LEDs, with a 5V square wave input controlling the transistor to turn the LED on and off.

Version
0.0.1
License
unset
Stars
0

bjt.tsx

export default () => (
  <board width="40mm" height="50mm">
    {/* 12V Power Supply */}
    <voltagesource
      name="V1"
      voltage="12V"
      schX={-5}
      schY={0}
    />

    {/* Base resistor - limits current into transistor base */}
    <resistor
      name="R1"
      resistance="10k"
      footprint="0805"
      schX={-2}
      schY={3}
      pcbX={-6}
      pcbY={-8}
    />

    {/* Collector pull-up resistor */}
    <resistor
      name="R3"
      resistance="10k"
      footprint="0805"
      schX={2}
      schY={-3}
      pcbX={0}
      pcbY={-8}
    />

    {/* LED current limiting resistor */}
    <resistor
      name="R2"
      resistance="220"
      footprint="0805"
      schX={2}
      schY={3}
      pcbX={6}
      pcbY={-8}
    />

    {/* NPN Transistor 2N2222 - the switch */}
    <transistor
      name="Q1"
      type="npn"
      footprint="sot23"
      schX={0}
      schY={0}
      pcbX={0}
      pcbY={0}
    />

    {/* Red LED - output indicator */}
    <led
      name="D1"
      color="red"
      footprint="0805"
      schX={4}
      schY={0}
      pcbX={6}
      pcbY={0}
    />

    {/* Square wave input: 0V to 5V at 100Hz */}
    <voltagesource
      name="V2"
      voltage="5V"
      waveShape="square"
      frequency="100"
      dutyCycle="0.5"
      schX={-5}
      schY={3}
    />

    {/* Input signal -> R1 -> Base */}
    <trace from=".V2 > .pin1" to=".R1 > .pin1" />
    <trace from=".V2 > .pin2" to="net.GND" />
    <trace from=".R1 > .pin2" to=".Q1 > .base" />

    {/* V1 positive (pin1) -> R3 (pull-up) */}
    <trace from=".V1 > .pin1" to="net.VCC12" />
    <trace from="net.VCC12" to=".R3 > .pin1" />

    {/* R3 -> R2 -> LED anode (collector node) */}
    <trace from=".R3 > .pin2" to=".Q1 > .collector" />
    <trace from=".R3 > .pin2" to=".R2 > .pin1" />
    <trace from=".R2 > .pin2" to=".D1 > .anode" />

    {/* LED cathode -> GND */}
    <trace from=".D1 > .cathode" to="net.GND" />

    {/* Transistor emitter -> GND */}
    <trace from=".Q1 > .emitter" to="net.GND" />

    {/* V1 negative (pin2) -> GND */}
    <trace from=".V1 > .pin2" to="net.GND" />
  </board>
)