Skip to main content
Tutorials

Building a Simple USB Flashlight

In this tutorial we will design a USB-powered LED flashlight as a printed circuit board (PCB). By the end you will have a complete, working schematic and PCB layout that you can send straight to a board house.

This is a great first project because it uses only three components and introduces the core tscircuit elements you will use in almost every design: a connector, a resistor, and an LED.


What You Will Build

A tiny PCB that plugs into any USB-A port. The 5 V supply from the USB bus powers a white LED through a current-limiting resistor. No firmware, no microcontroller — just light.

Components

PartValue / Parttscircuit element
USB-A connector (male)USB-A through-hole<connector />
Current-limiting resistor68 Ω, 0402<resistor />
White LEDGeneric 0402 white<led />

How the Circuit Works

USB supplies 5 V on pin 1 (VBUS) and ground on pin 4 (GND).

A white LED typically has a forward voltage (V_f) of about 3.0 V–3.4 V and wants roughly 20 mA of current. We choose R so that:

R = (V_supply − V_f) / I_led
R = (5 V − 3.2 V) / 0.020 A
R ≈ 90 Ω → use standard value 68 Ω (gives ~26 mA, fine for a bright flash)

The circuit is simply: VBUS → R1 → LED anode → LED cathode → GND.


Step 1 — Create a New Project

If you haven't installed tscircuit yet, follow the Quickstart CLI guide or use the online editor to follow along in your browser.

tsci init usb-flashlight
cd usb-flashlight
tsci dev

Open lib/MyCircuit.tsx in your editor. You will see a blank board template.


Step 2 — Add the USB Connector

A USB-A male connector exposes four pins. We only need pin 1 (VBUS, +5 V) and pin 4 (GND). In tscircuit we declare it with <connector /> and assign net labels to the pins we care about:

import { connector, resistor, led, board, trace } from "@tscircuit/core"

export default () => (
<board width="20mm" height="15mm">
<connector
name="J1"
footprint="usb_a_male_th"
pinLabels={{
pin1: "VBUS",
pin4: "GND",
}}
pcbX={-7}
pcbY={0}
/>
</board>
)

Tip: footprint="usb_a_male_th" selects a through-hole USB-A male footprint from the built-in footprint library. You can browse available footprints at tscircuit.com/footprints.

After saving, you should see the connector appear on the PCB preview in your browser.


Step 3 — Add the Current-Limiting Resistor

Place a 68 Ω 0402 resistor to the right of the connector. Its left pin (pin1) will connect to VBUS, and its right pin (pin2) will go to the LED:

    <resistor
name="R1"
resistance="68"
footprint="0402"
pcbX={0}
pcbY={0}
/>

Step 4 — Add the LED

Place a 0402 white LED to the right of the resistor. The anode (pin1) connects to R1, and the cathode (pin2) connects to GND:

    <led
name="LED1"
color="white"
footprint="0402"
pcbX={7}
pcbY={0}
/>

Step 5 — Connect the Components with Traces

Now wire everything together. tscircuit traces are declared by listing the net path using dot notation ComponentName.pinLabel:

    {/* VBUS from USB connector pin 1 to resistor pin 1 */}
<trace from="J1.VBUS" to="R1.pin1" />

{/* R1 pin 2 to LED anode */}
<trace from="R1.pin2" to="LED1.pin1" />

{/* LED cathode back to GND on USB connector pin 4 */}
<trace from="LED1.pin2" to="J1.GND" />

Full Circuit Code

Putting it all together:

import { connector, resistor, led, board, trace } from "@tscircuit/core"

export default () => (
<board width="20mm" height="15mm">
{/* USB-A Male Connector */}
<connector
name="J1"
footprint="usb_a_male_th"
pinLabels={{
pin1: "VBUS",
pin4: "GND",
}}
pcbX={-7}
pcbY={0}
/>

{/* 68 Ω current-limiting resistor */}
<resistor
name="R1"
resistance="68"
footprint="0402"
pcbX={0}
pcbY={0}
/>

{/* White LED */}
<led
name="LED1"
color="white"
footprint="0402"
pcbX={7}
pcbY={0}
/>

{/* Traces */}
<trace from="J1.VBUS" to="R1.pin1" />
<trace from="R1.pin2" to="LED1.pin1" />
<trace from="LED1.pin2" to="J1.GND" />
</board>
)

Step 6 — Preview and Verify

The tsci dev server shows three tabs: Schematic, PCB, and 3D.

Check the following:

  • Schematic: The net from J1 pin 1 flows through R1 and then through LED1 to GND. No unconnected pins ("ratsnest" lines) should remain.
  • PCB: All three components fit within the 20 × 15 mm board outline. All traces are routed (no airwires).
  • 3D: The USB connector overhangs the board edge slightly — this is normal for a plug-style connector. If you see any ratsnest (unrouted) lines, double-check the from / to pin names in your <trace /> elements.

Step 7 — Export and Order

When you are happy with the design, export Gerber files for fabrication:

tsci export --format gerber

The files land in ./output/gerbers/. Zip the folder and upload it to your preferred PCB manufacturer (JLCPCB, PCBWay, OSH Park, etc.). A standard 5-board run of this simple design typically costs under $5 including shipping.


What's Next?

  • Add a push-button switch between VBUS and R1 to turn the light on and off (<pushbutton /> element).
  • Swap the single LED for three LEDs in parallel (each with its own 100 Ω resistor) for a brighter beam.
  • Try the Building a 3×5 LED Matrix tutorial to scale up to a full dot-matrix display.