Pushbutton LED Circuit
Create a simple USB-powered LED circuit with a pushbutton using tscircuit snippets
Overview
In this tutorial, we’ll create a simple USB-powered LED circuit using the tscircuit snippets editor. When completed, you’ll have a circuit that lights up an LED when a button is pressed.
Creating the Circuit
Open snippets.tscircuit.com and create a new snippet.
First, we’ll import our required components using module imports:
- @tsci/seveibar.red-led
- @tsci/seveibar.push-button
- @tsci/seveibar.smd-usb-c
Let’s build our circuit by connecting the components.
Each component is positioned using schX
and schY
for schematic placement, pcbY
and pcbX
for PCB layout.
The traces use the format .ComponentName > .pinName
.
This is the code used in the example:
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
Understanding the Circuit
Let’s break down the key parts:
- USB-C Power: The
<USBC />
component provides power (VBUS) and ground (GND) - Button: The
<Button />
connects VBUS to the LED circuit when pressed - Current Limiting: The 1kΩ resistor protects the LED from too much current
- LED: Lights up when the button completes the circuit
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.
Next Steps
Try modifying the design:
- Change the LED color by using a different LED component
- Adjust the board dimensions
- Add more buttons or LEDs
- Import different components using the
@
picker
Remember to save your snippet if you want to share it or use it in other projects!