14 PCB Design and Fabrication
14.1 Learning Objectives
By the end of this chapter, you will be able to:
- Trace the PCB design workflow from schematic capture through layout, fabrication, and assembly
- Select appropriate PCB design tools (KiCad, EasyEDA, Altium) matched to project complexity and skill level
- Apply best practices for component placement, trace routing, ground planes, and antenna keep-out zones
- Compare PCB manufacturing services by cost, turnaround time, and assembly capabilities
- Execute proper PCB assembly sequence and systematic testing procedures to verify functionality
Key Concepts
- Schematic Capture: Process of drawing a circuit diagram in EDA software before generating the netlist for PCB layout.
- PCB Layout: Process of placing components and routing copper traces on a PCB within the physical board outline.
- Design Rule Check (DRC): Automated verification ensuring all trace widths, clearances, and drill sizes meet fabrication constraints.
- Gerber Files: Standard industry format for PCB manufacturing data including copper layers, solder mask, and drill files.
- Via: Plated hole connecting copper traces on different PCB layers, used to route signals around obstacles.
- Ground Plane: Solid copper pour on a PCB layer providing a low-impedance return path and shielding for signal traces.
- Impedance Control: PCB fabrication specification ensuring trace characteristic impedance matches cable or RF requirements.
For Beginners: PCB Design and Fabrication
Printed circuit boards (PCBs) are the professional, permanent versions of your breadboard prototypes. Think of the difference between a handwritten draft and a professionally printed book – PCBs are compact, reliable, and ready for manufacturing. This chapter covers how to go from a working prototype to a production-ready circuit board.
Sensor Squad: From Breadboard to Circuit Board
“Time to graduate from messy wires to a real circuit board!” announced Max the Microcontroller proudly. “A PCB – Printed Circuit Board – is like upgrading from a hand-drawn map to a professional GPS. It is compact, reliable, and ready for mass production.”
Sammy the Sensor examined a green PCB. “How do you go from a breadboard prototype to one of these?” Max explained the steps. “First, you draw a schematic – a diagram of all the connections. Then you lay out the PCB – deciding where each component goes and how the copper traces connect them. Finally, you send the design to a factory that prints it on a board.”
“The layout is like solving a puzzle,” said Lila the LED. “You have to fit all the components in the right places, keep noisy signals away from sensitive ones, and make sure the copper traces are wide enough to carry the current without overheating.” Bella the Battery added, “And you can order PCBs from factories like JLCPCB or OSH Park for just a few dollars. It only takes about a week to get them back. Then you solder on the components, and your prototype looks and works like a real product!”
14.2 PCB Design Process
14.2.1 Schematic Capture
Creating circuit diagrams showing component connections is the first step in PCB design.
Popular Tools:
| Tool | Cost | Best For |
|---|---|---|
| KiCad | Free, open-source | Professional-grade, all skill levels |
| Eagle | Free (limited) | Hobbyists, Autodesk ecosystem |
| EasyEDA | Free | Beginners, integrated with JLCPCB |
| Altium Designer | $2000+ | Professional, complex designs |
| Fritzing | Free | Beginners, visual approach |
14.2.2 Component Selection
- Choose components available in manufacturer’s libraries
- Verify footprints match physical components
- Consider availability and cost (check DigiKey, Mouser stock)
- Plan for production: prefer common, multi-sourced parts
14.3 PCB Layout Best Practices
14.3.1 Component Placement
- Start with connectors - define board edge locations
- Place critical components - MCU, antenna, power
- Group related components - sensors near MCU, power near input
- Maintain antenna keep-out zones - no traces/copper under RF sections
14.3.2 Trace Routing
| Rule | Recommendation |
|---|---|
| Power traces | 20+ mils for 1A, calculate for higher |
| Signal traces | 8-12 mils typical |
| Spacing | Follow manufacturer minimums (6-8 mils) |
| Vias | Minimize; keep away from pads |
14.3.3 Power and Ground
- Use solid ground plane - reduces EMI, improves signal integrity
- Star grounding for analog/digital separation if needed
- Decoupling capacitors - place within 5-10mm of IC power pins
- Bulk capacitors - at power input for transient handling
14.3.4 Knowledge Check
14.4 PCB Manufacturing
14.4.1 Service Comparison
| Service | Cost (10 boards) | Turnaround | Strengths |
|---|---|---|---|
| JLCPCB | $2-5 | 1-2 weeks | Cheapest, assembly service |
| PCBWay | $5-10 | 1-2 weeks | Good quality, flex PCBs |
| OSH Park | $15-25 | 2-3 weeks | US-based, purple boards |
| Seeed Fusion | $5-10 | 1-2 weeks | Good SMT assembly |
14.4.2 Design Rules
Check manufacturer specifications for: - Minimum trace width (typically 6-8 mils) - Minimum spacing (typically 6-8 mils) - Minimum drill size (typically 0.3mm) - Via specifications (through-hole, blind, buried)
14.4.3 Quality Checklist
Before ordering: - [ ] Run Design Rule Check (DRC) - [ ] Verify Gerber files visually - [ ] Check silkscreen for readability - [ ] Confirm component footprints match datasheets - [ ] Order 2-3 extra boards for testing
14.5 Assembly Techniques
14.5.1 Through-Hole Assembly
- Start with low-profile components (resistors, diodes)
- Progress to taller components (capacitors, ICs)
- Finish with connectors and tall parts
- Trim leads after soldering
- Inspect joints visually
14.5.2 Surface Mount (SMD) Assembly
Component Sizes (difficulty increases as size decreases):
- 1206 (3.2 x 1.6 mm) - Easy to hand solder
- 0805 (2.0 x 1.25 mm) - Common, manageable
- 0603 (1.6 x 0.8 mm) - Requires steady hands
- 0402 (1.0 x 0.5 mm) - Requires magnification
Hand Soldering Process:
- Apply solder paste (stencil or syringe)
- Place components with tweezers
- Reflow with hot air or reflow oven
- Inspect under magnification
14.5.3 Testing Procedure
- Visual inspection - solder bridges, cold joints
- Continuity testing - check power and ground
- Power on with current limiting - catch shorts
- Functional test - verify each subsystem
14.6 Worked Example: PCB Cost Estimation for IoT Sensor Node
Scenario: You are designing a custom PCB for a Wi-Fi-connected temperature/humidity sensor that will be manufactured in batches of 100 units.
PCB Fabrication Cost (JLCPCB, 2-layer, 50x30mm):
| Quantity | Cost per Board | Total PCB Cost | Lead Time |
|---|---|---|---|
| 5 (prototype) | $0.40 | $2.00 + $8 shipping | 7 days |
| 10 | $0.40 | $4.00 + $8 shipping | 7 days |
| 100 | $0.24 | $24.00 + $15 shipping | 5 days |
| 1,000 | $0.12 | $120.00 + $30 shipping | 5 days |
Component BOM (per unit, DigiKey/LCSC pricing at 100 qty):
| Component | Part Number | Unit Cost |
|---|---|---|
| ESP32-C3-MINI-1 | ESP32-C3 | $1.80 |
| SHT31-DIS sensor | Sensirion SHT31 | $2.40 |
| LDO regulator 3.3V | AMS1117-3.3 | $0.08 |
| USB-C connector | TYPE-C-31-M-12 | $0.15 |
| 10uF caps (x3) | 0805 MLCC | $0.06 |
| 100nF caps (x4) | 0603 MLCC | $0.04 |
| 10K resistors (x4) | 0603 | $0.02 |
| LED + resistor | 0603 green | $0.03 |
| Antenna | PCB trace (free) | $0.00 |
| Total BOM | $4.58 |
Total Per-Unit Cost at 100 qty: $4.58 (BOM) + $0.24 (PCB) + $1.50 (assembly if PCBA) = $6.32
Compare to development board approach: ESP32-C3 DevKit ($8) + SHT31 breakout ($12) + breadboard ($3) = $23.00 per unit
Savings at scale: Custom PCB saves $16.68 per unit. At 100 units, that is $1,668 total savings, plus the custom PCB is smaller, more reliable, and production-ready.
14.6.1 Interactive Cost Comparison Calculator
Explore how costs scale with volume using the calculator below:
14.7 Interactive Trace Width Calculator
Try the calculator below to see how current, temperature rise, and copper weight affect trace width requirements:
14.8 Trace Width Calculator Rules of Thumb
For 1 oz copper (35 um thickness) on outer layers with 10C temperature rise:
| Current (A) | Minimum Trace Width (mils) | Minimum Trace Width (mm) |
|---|---|---|
| 0.5 | 10 | 0.25 |
| 1.0 | 19 | 0.48 |
| 2.0 | 35 | 0.89 |
| 3.0 | 51 | 1.29 |
| 5.0 | 76 | 1.93 |
Formula (IPC-2221 approximation):
\[ W = \frac{1}{t} \left( \frac{I}{k \times \Delta T^{0.44}} \right)^{1/0.725} \]
Where: - \(W\) = trace width (mils) - \(I\) = current (amps) - \(k\) = 0.048 for outer layers, 0.024 for inner layers - \(\Delta T\) = temperature rise (°C, typically 10°C) - \(t\) = copper thickness (1.378 mils for 1 oz copper)
For a 2A power trace: \(W = \frac{1}{1.378} \left( \frac{2}{0.048 \times 10^{0.44}} \right)^{1/0.725} = 35\) mils. Using a 10-mil trace (common default) would cause significant heating and potential failure. The Python calculator below implements this formula. Always verify with online IPC-2221 calculators for production designs.
14.9 Code Example: PCB Trace Width and BOM Cost Calculator
This Python tool automates two common PCB design calculations: trace width from the IPC-2221 standard (used in the trace width table above) and bill-of-materials cost estimation at different production volumes:
import math
class PCBDesignCalculator:
"""PCB trace width (IPC-2221) and BOM cost estimation."""
def trace_width_mils(self, current_a, temp_rise_c=10,
copper_oz=1, layer="outer"):
thickness_mils = copper_oz * 1.378
k = 0.048 if layer == "outer" else 0.024
# IPC-2221: Area = (I / (k * dT^0.44))^(1/0.725)
area = (current_a / (k * temp_rise_c ** 0.44)) ** (1 / 0.725)
width_mils = area / thickness_mils
return {
"width_mils": round(max(width_mils, 6), 1),
"width_mm": round(max(width_mils, 6) * 0.0254, 2),
}
def bom_cost(self, components, quantities):
"""Interpolate unit costs between qty=1 and qty=100 pricing."""
results = []
for qty in quantities:
total = 0
for c in components:
ratio = min(qty, 100) / 100
unit = c["unit_cost_1"] - (c["unit_cost_1"]
- c["unit_cost_100"]) * ratio
total += unit * c["qty_per_board"]
results.append({"quantity": qty,
"bom_per_board": round(total, 2)})
return resultsUsage – trace widths and BOM estimation for an ESP32 sensor node:
calc = PCBDesignCalculator()
for amps in [0.5, 1.0, 2.0, 3.0]:
tw = calc.trace_width_mils(amps)
print(f"{amps}A -> {tw['width_mils']} mils ({tw['width_mm']} mm)")
# 0.5A -> 10.3 mils (0.26 mm)
# 2.0A -> 35.1 mils (0.89 mm) <- Don't use 10-mil signal trace!
# 3.0A -> 50.7 mils (1.29 mm)The trace width calculator prevents a common PCB failure: undersized power traces. A 2A power trace needs at least 35 mils (0.89mm) – using the default 10-mil signal trace would cause overheating and potential board failure. The Python calculator matches the IPC-2221 standard calculations shown in the worked example above. Always verify with online IPC-2221 calculators for production designs.
14.10 Common PCB Issues and Solutions
| Issue | Cause | Solution |
|---|---|---|
| Wi-Fi weak/no connection | Ground plane under antenna | Create keep-out zone |
| Random resets | Power supply noise | Add decoupling capacitors |
| I2C communication fails | Missing pull-ups | Add 4.7k pull-up resistors |
| Component overheating | Trace too narrow | Increase trace width |
| Manufacturing rejects | Violates design rules | Run DRC before ordering |
14.11 Quiz: PCB Design
14.12
Worked Example: First PCB Design for ESP32 Environmental Sensor
Scenario: You’ve successfully prototyped an ESP32-based temperature/humidity sensor on a breadboard. It reads a BME280 sensor via I2C every 60 seconds, sends data via MQTT over Wi-Fi, and runs on USB power. Now you want to design your first custom 2-layer PCB.
Step 1: Schematic Capture in KiCad
Components:
- ESP32-WROOM-32E module (pre-certified Wi-Fi/BLE module)
- BME280 sensor breakout or bare IC
- AMS1117-3.3V LDO voltage regulator (5V USB → 3.3V)
- USB Micro-B connector for power and programming
- CP2102 USB-to-UART bridge for programming
- Auto-reset circuit (2x NPN transistors + resistors) for programming
- 10µF bulk capacitors (x2), 0.1µF decoupling caps (x4)
- 10kΩ pull-up resistors for I2C (x2)
- LED + 1kΩ current-limiting resistor
- Tactile button for user input
Power tree:
USB 5V → AMS1117 → 3.3V → ESP32 + BME280 + CP2102
↓
0.1µF decoupling caps near each IC
I2C connection:
ESP32 GPIO21 (SDA) ──┬─── 10kΩ pull-up to 3.3V ──── BME280 SDA
ESP32 GPIO22 (SCL) ──┴─── 10kΩ pull-up to 3.3V ──── BME280 SCL
Step 2: Component Placement Strategy
| Zone | Components | Reason |
|---|---|---|
| Top-left | USB connector, CP2102, auto-reset circuit | Keep USB signals short, near connector |
| Center | ESP32-WROOM module | Central hub, short traces to peripherals |
| Center-right | AMS1117 regulator, bulk caps | Near ESP32 (high current consumer) |
| Top-right | BME280 sensor | Edge of board for airflow, away from heat-generating ESP32 |
| Bottom-right | LED, button | User interface elements |
Critical placement rules:
- ESP32 antenna keep-out zone: No copper (traces or ground plane) within 5mm of ESP32 antenna section
- Decoupling caps: 0.1µF caps within 5mm of ESP32 VDD pins (pins 2, 19)
- I2C pull-ups: Near ESP32 I2C pins, not near BME280 (minimizes stub)
- Power input caps: 10µF bulk cap immediately after AMS1117 output
Step 3: Trace Width Calculations
Using IPC-2221 standard for 1 oz copper, 10°C temperature rise:
| Signal | Current | Trace Width (mils) | Trace Width (mm) |
|---|---|---|---|
| USB 5V input | 500 mA | 10 | 0.25 |
| 3.3V power rail | 300 mA | 8 | 0.20 |
| I2C signals (SDA, SCL) | <1 mA | 6 (minimum) | 0.15 |
| GPIO signals | <10 mA | 6 (minimum) | 0.15 |
| Ground return | 500 mA | Solid plane | Solid plane |
Step 4: Layer Stackup (2-layer PCB)
- Top layer (red): Signal traces, component pads, small ground fills
- Bottom layer (blue): Solid ground plane (maximized), some power traces
Ground plane strategy:
- Bottom layer is 90% solid ground plane (remove copper only for signal vias)
- Top layer has ground fills in unused areas
- All decoupling capacitors connect to ground via short traces (not vias if possible)
Step 5: Routing Order
- Critical traces first (short, direct, no vias):
- ESP32 VDD to decoupling caps to ground
- AMS1117 output to bulk cap to ESP32 VDD
- ESP32 antenna feed (if using external antenna)
- I2C signals (matched length, parallel routing):
- SDA and SCL routed parallel, equal length ±5mm
- No sharp 90° bends (use 45° or curved)
- 10kΩ pull-ups near ESP32 end
- USB signals (D+ and D-):
- Differential pair, 90Ω impedance (for USB 2.0 full-speed)
- Routed parallel, equal length, minimal vias
- Keep away from switching power supplies
- Power traces:
- Wide traces (10+ mils) for 5V and 3.3V rails
- Star topology for voltage regulator (avoid daisy-chaining)
- GPIO signals last:
- LED, button, spare GPIOs
Step 6: Design Rule Check (DRC)
JLCPCB design rules: - Minimum trace width: 6 mil (0.15mm) ✅ - Minimum trace spacing: 6 mil (0.15mm) ✅ - Minimum drill size: 0.3mm ✅ - Minimum annular ring: 0.15mm ✅
Run KiCad DRC → fix all errors before ordering.
Step 7: Gerber Generation and Order
- Export Gerber files from KiCad (File → Plot)
- Include drill file (.drl)
- Zip all files
- Upload to JLCPCB → PCB specs: 2-layer, 1.6mm thickness, HASL finish, green solder mask
- Cost: 5 PCBs for $2 + $8 shipping = $10 total
- Lead time: 5-7 days fabrication + 7-10 days shipping
Step 8: Assembly and Testing
- Inspect PCB: Check for manufacturing defects (shorts, open traces)
- Solder small components first: Resistors, capacitors (0805 or 1206 size)
- Solder ICs: ESP32 module, CP2102, AMS1117 (use flux, avoid bridges)
- Visual inspection: Check for solder bridges under magnification
- Continuity test: Multimeter → check VCC to GND (should be open circuit, >1MΩ)
- Power-on test: Connect USB, measure 3.3V at ESP32 VDD pin (no load)
- Program firmware: Upload test sketch (blink LED)
- Sensor test: Read BME280 via I2C
- Wi-Fi test: Connect to network, send MQTT message
Common first-PCB mistakes and fixes:
- ESP32 won’t boot: Missing pull-up resistors on EN (enable) pin → add 10kΩ to 3.3V
- I2C not working: Forgot pull-up resistors → hand-solder 10kΩ resistors
- Wi-Fi range poor: Ground plane under antenna → cut away copper with Dremel
- Programming fails: Auto-reset circuit wrong → manual press EN + BOOT buttons
Decision Framework: 2-Layer vs 4-Layer PCB for IoT Projects
| Factor | 2-Layer PCB | 4-Layer PCB |
|---|---|---|
| Cost (5 boards) | $2-5 | $15-30 |
| Cost (100 boards) | $50-100 | $200-400 |
| Design complexity | Simple (1 day) | Medium (2-3 days) |
| Signal integrity | Adequate for <10 MHz | Better for high-speed (SPI >10 MHz, USB, Ethernet) |
| EMI performance | Moderate (may fail FCC/CE without careful layout) | Good (solid ground plane reduces emissions) |
| Power integrity | Moderate (shared routing layer) | Better (dedicated power plane) |
| Routing density | 70-80% achievable | 95%+ achievable |
| Ground plane quality | Fragmented (shared with signals) | Solid internal plane |
Use 2-layer when:
- Simple sensor nodes (I2C sensors, low-speed GPIO)
- Prototyping (not production)
- Wi-Fi/BLE with good antenna design and ground pour
- Budget constrained (<$100 for 10 boards)
- Single-sided component placement
Use 4-layer when:
- High-speed interfaces (Ethernet, USB 2.0 high-speed, SDIO, fast SPI >20 MHz)
- RF designs requiring solid ground plane (Wi-Fi, BLE, LoRa)
- Precision analog circuits (ADC, DAC) needing clean grounds
- Dense component placement (BGA packages, many ICs)
- Production intent (EMC compliance required)
- Safety-critical or industrial applications
Example decision: An ESP32 environmental sensor with BME280 (I2C, 400 kHz) can use 2-layer. The same ESP32 with Ethernet PHY (RMII, 50 MHz) needs 4-layer for reliable operation and EMC compliance.
Common Mistake: Ignoring Antenna Design Guidelines
The Problem: A developer successfully breadboards an ESP32 project with Wi-Fi working perfectly (50m range). They design a custom PCB, placing the ESP32 module wherever it fits, routing traces near the antenna, and filling the entire board with ground copper. After assembling the PCB, Wi-Fi barely reaches 5 meters.
What went wrong (antenna killer mistakes):
Ground plane under antenna: The ESP32-WROOM module has a PCB trace antenna on the module’s edge. Ground copper beneath the antenna acts as a shield, blocking RF radiation. Fix: Maintain a 5mm x 15mm keep-out zone (no copper on any layer) under the antenna section.
Traces crossing near antenna: Signal traces near the antenna couple RF noise and detune the antenna. Fix: Route all traces at least 5mm away from the antenna feed point and antenna keep-out zone.
Metal enclosure too close: Metal enclosure walls within 10mm of the antenna shield RF and detune the antenna. Fix: Use plastic enclosures or position the antenna near a plastic window in metal enclosures.
No ground plane at all: The antenna needs a ground plane to work (it’s a monopole antenna using ground as the other half). Fix: Provide solid ground copper on the side opposite the antenna keep-out zone.
Wrong PCB edge placement: Placing the ESP32 module in the center of the PCB puts the antenna far from the board edge, surrounded by ground copper. Fix: Position the ESP32 module so its antenna section is at the PCB edge (no board material beyond the antenna).
Proper antenna design checklist:
- ✅ ESP32 module positioned with antenna at board edge
- ✅ 5mm x 15mm keep-out zone on all layers (no copper, no traces)
- ✅ Solid ground plane on opposite side of board (not under antenna)
- ✅ No metal components within 15mm of antenna
- ✅ If using external antenna, use 50Ω impedance-controlled trace from ESP32 to U.FL connector
- ✅ Test Wi-Fi range before and after PCB redesign
How to diagnose: If breadboard works but PCB doesn’t, antenna design is the #1 suspect. Use a Wi-Fi scanner app to measure RSSI (signal strength). If RSSI is 20+ dB worse than breadboard, you have antenna problems.
: