diff --git a/docs/tutorials/creating-a-capacitive-touch-element.mdx b/docs/tutorials/creating-a-capacitive-touch-element.mdx new file mode 100644 index 0000000..41f1a66 --- /dev/null +++ b/docs/tutorials/creating-a-capacitive-touch-element.mdx @@ -0,0 +1,241 @@ +--- +title: Creating a Capacitive Touch Element +description: Learn how to create capacitive touch pads using polygon SMT pads with solder mask in tscircuit. Build a single touch button and a multi-finger touch surface. +--- + +## Overview + +Capacitive touch elements detect a finger's presence through a change in electrical capacitance. +On a PCB, this is achieved with copper pads covered by a thin solder mask (solder resist) layer. +The solder mask acts as a dielectric — your finger changes the pad's capacitance relative to ground, +which a touch controller IC detects. + +tscircuit supports **polygon-shaped SMT pads** with `coveredWithSolderMask` control, making it +straightforward to create custom touch sensor geometries. + +import TscircuitIframe from "@site/src/components/TscircuitIframe" + +## How It Works + +``` +Copper pad → Solder mask (dielectric) → Air gap → Finger + ↕ capacitance change detected by IC +``` + +Key properties for capacitive touch pads: + +| Property | Value | Purpose | +|---|---|---| +| `shape` | `"polygon"` | Custom pad outline for touch geometry | +| `coveredWithSolderMask` | `true` | Apply solder mask over pad (enables capacitive sensing) | +| `layer` | `"top"` | Place on top copper layer | + +## Single Capacitive Touch Button + +The simplest touch element: a single diamond-shaped pad covered with solder mask. +Polygon pads let you match common touch-IC footprint patterns. + + { + const size = 8 // mm + const half = size / 2 + + return ( + + + + ) +} +`} /> + +The `points` array defines the polygon vertices in millimeters, relative to the pad center. +The diamond shape maximises the sensing area while providing clear visual boundaries. + +## Multi-Pad Touch Surface + +A practical touch surface with multiple sensing pads and spacing between them to reduce +cross-talk. Each pad connects to a separate channel on a touch controller IC. + + { + const half = PAD_SIZE / 2 + const pitch = PAD_SIZE + SPACING + const totalWidth = NUM_PADS * pitch - SPACING + 8 + const startX = -(NUM_PADS - 1) * pitch / 2 + + const diamondPoints = [ + { x: 0, y: half }, + { x: half, y: 0 }, + { x: 0, y: -half }, + { x: -half, y: 0 }, + ] + + return ( + + {Array.from({ length: NUM_PADS }).map((_, i) => ( + ({ x: p.x + startX + i * pitch, y: p.y }))} + coveredWithSolderMask={true} + layer="top" + portHints={[\`pin\${i + 1}\`]} + /> + ))} + + ) +} +`} /> + +## Custom Polygon Shapes + +Polygon pads aren't limited to diamonds. You can define any convex or concave shape +to match your product's industrial design. Here is a rounded-corner approximation +using an octagon: + + ( + + + +) +`} /> + +## Connecting to a Touch Controller + +Each touch pad connects to a dedicated channel on a capacitive touch IC. +Here's a minimal wiring example with a 4-channel touch controller: + +```tsx +export default () => { + const pitch = 8.5 + const start = -(3 * pitch) / 2 + const half = 3.5 + + const diamondPoints = [ + { x: 0, y: half }, + { x: half, y: 0 }, + { x: 0, y: -half }, + { x: -half, y: 0 }, + ] + + return ( + + {/* 4 touch pads */} + {[0, 1, 2, 3].map((i) => ( + ({ + x: p.x + start + i * pitch, + y: p.y + 8, + }))} + coveredWithSolderMask={true} + layer="top" + portHints={[`net.CH${i}`]} + /> + ))} + + {/* Touch controller IC */} + + + ) +} +``` + +## Design Tips + +**Pad size and shape** +- Larger pads give stronger signal but may cause false triggers if spaced too tightly +- Diamond and octagon shapes work well as they pack efficiently while providing clear finger targets +- Typical pad size for a button: 6–12 mm across + +**Solder mask thickness** +- Thinner solder mask = stronger capacitive signal +- Standard thickness (~25–50 µm) works for most designs +- Request "thin solder mask" from your PCB fab for highest sensitivity + +**Spacing between pads** +- Use 1–2 mm gaps between adjacent sensing pads to reduce cross-talk +- Route sense traces on an inner layer or use a ground guard ring between pads + +**Ground plane** +- Place a ground plane on the layer directly below the touch pads +- This creates a controlled reference capacitance for more predictable sensing +- Keep ground plane at least 0.5 mm inset from pad edges + +**Trace routing** +- Keep sense traces short and shielded from high-frequency signals +- Use ground-guard traces (same layer) around sense traces to minimise noise pickup + +## Related Resources + +- [circuit-json pcb_smtpad spec](https://github.com/tscircuit/circuit-json/blob/main/src/pcb/pcb_smtpad.ts) — full type definition including `covered_with_solder_mask` and `shape: "polygon"` +- [Building a Capacitive Touch Slider](./building-a-capacitive-touch-slider) — linear slider layout using rectangular pads