Skip to content
You Start with one site
Amounts in Start with one site
Embedded Systems & Electronics · Course

ATmega328P Sensor Shield

Lesson 2 of 9 18 min read
Made with KiCad 10checked November 2026Newer version?
Stays the same
  • Schematic first, then the board
  • Footprints, nets and design rules
  • Ground planes, return paths and clearances
  • Gerbers and a drill file for the maker
May look different
  • Menu places and hotkeys
  • The look of the plugin and library managers
  • Default design rules
  • Dialog fields (KiCad 10 gave rectangles a corner radius)
  • The Python module: SWIG pcbnew is deprecated in favour of kicad-cli and the IPC API

A step looks different? Most commands have a hotkey listed in Help, then the list of hotkeys.

The ideas in this lesson do not depend on the version. Where a click moved, the lesson still names the command.

Found this useful?

Through-hole components are easy to solder, but they are large, limit how dense your layout can be, and many modern sensors simply do not come in through-hole packages. If you want to use the latest MEMS sensors, IMUs, or compact MCU variants, you need to work with SMD. Surface mount parts can be ten times smaller, which means shorter traces, less parasitic capacitance, and boards that fit in tight enclosures. In this lesson you will design a sensor shield around the ATmega328P in a TQFP-32 package, add an I2C temperature/humidity sensor (SHT30) and an SPI ambient light sensor (VEML7700), and learn CNC milling as an alternative to chemical etching. #KiCad #SMD #SensorShield

SMD Component Size ComparisonThrough-hole resistor (axial):6.5 mm0805SMD(2.0x1.25mm):fits on a pencil tip0402SMD(1.0x0.5mm):barely visibleTQFP-32 (0.8mm pitch):32 pins total,8 per side,0.8 mm betweenpin centers

What We Are Building

ATmega328P Sensor Shield

A compact double-sided sensor board with the ATmega328P in its smallest through-hole-free package (TQFP-32, 0.8mm pin pitch). The board reads temperature, humidity, and ambient light through I2C and SPI buses, sending data over UART. All passives are 0805 SMD, the smallest size comfortable for hand soldering.

Board specifications:

ParameterValue
MCUATmega328P-AU (TQFP-32, 0.8mm pitch)
Clock16 MHz crystal (3.2x2.5mm SMD)
PowerUSB Micro-B 5V input, 3.3V LDO (AMS1117-3.3) for sensors
SensorsSHT30-DIS (I2C, temp/humidity), VEML7700 (I2C, ambient light)
CommunicationUART header (TX, RX, GND), ISP header
Passives0805 SMD resistors and capacitors
Size40 x 35 mm, double-sided

Bill of Materials

RefComponentPackageQuantityNotes
U1ATmega328P-AUTQFP-3210.8mm pitch
U2AMS1117-3.3SOT-22313.3V LDO for sensors
U3SHT30-DIS-BDFN-8 (2.5x2.5mm)1Temperature/humidity
U4VEML7700OPLGA (6.8x3.5mm)1Ambient light sensor
Y116 MHz3.2x2.5mm SMD1Crystal
C1, C222 pF08052Crystal load caps
C3-C6100 nF08054Decoupling
C7, C810 µF08052Regulator caps
R110 kΩ08051Reset pull-up
R2, R34.7 kΩ08052I2C pull-ups
R4330 Ω08051Power LED
D1Green LED08051Power indicator
J1USB Micro-BSMD1Power input
J22x3 pin header2.54mm1ISP header
J31x4 pin header2.54mm1UART (VCC, TX, RX, GND)
SW1Tactile switchSMD 3x6mm1Reset

SMD Footprint Fundamentals



Before drawing the schematic, let’s understand what changes with SMD components.

Package Sizes

SMD passive components come in standardized sizes named by their imperial dimensions in hundredths of an inch:

PackageSize (mm)Hand Solderable?Use Case
12063.2 x 1.6EasyPrototypes, power resistors
08052.0 x 1.25ComfortableGeneral purpose (this lesson)
06031.6 x 0.8ModerateSpace-constrained designs
04021.0 x 0.5DifficultProfessional assembly only

We use 0805 throughout this lesson. It is small enough to save board space but large enough that a steady hand with a fine-tip soldering iron can handle it.

TQFP vs DIP

The ATmega328P-AU (TQFP-32) has the same silicon as the DIP-28 version from Lesson 1, but in a 7x7mm package instead of 37x7mm. The pin pitch drops from 2.54mm to 0.8mm. This means:

  • Thinner traces between pins (you need at least 0.2mm trace width to route between TQFP pads)
  • Solder paste and a hot air station work better than an iron for TQFP soldering
  • The pinout maps differently: TQFP-32 has 32 pins (4 extra: two additional GND and two ADC pins)

Pad and Courtyard

In KiCad, every SMD footprint has:

  • Pads: copper areas where solder connects the component to the board
  • Courtyard: a clearance boundary showing how close other components can be placed
  • Fab layer: the component outline showing its physical dimensions

When placing components, keep courtyards from overlapping. KiCad’s DRC checks this automatically.

Schematic Capture



Create a new KiCad project named atmega328p-sensor-shield.

Download Schematic PDF

Power Supply

This board has two voltage rails: 5V from USB for the MCU, and 3.3V from the LDO for the sensors.

  1. Place the USB Micro-B connector. Add USB_B_Micro from the Connector library. This provides 5V and GND from any USB power source.

  2. Place the 3.3V LDO. Add AMS1117-3.3 (SOT-223). Connect its input to the USB 5V through a 10 µF capacitor (C7). Connect its output to a +3V3 power symbol through another 10 µF capacitor (C8).

  3. Add power symbols. Place +5V, +3V3, and GND power symbols. The MCU runs on +5V; the sensors run on +3V3.

  4. Wire the power section. USB VBUS to +5V, USB GND to GND. LDO input from +5V, LDO output to +3V3.

MCU and Crystal

  1. Place the ATmega328P-AU. Add ATmega328P-AU (the TQFP-32 variant). Place it in the center of the schematic.

  2. Connect power. Wire VCC (pin 4), AVCC (pin 18) to +5V. Wire GND (pins 3, 5, 21) to GND. Place 100 nF decoupling capacitors (C3, C4) close to VCC and AVCC.

  3. Crystal circuit. Place a Crystal_SMD_4Pin (16 MHz) between XTAL1 (pin 7) and XTAL2 (pin 8). Add 22 pF load capacitors (C1, C2) from each crystal pin to GND.

  4. Reset circuit. Connect a 10 kΩ pull-up (R1) from RESET (pin 29) to +5V. Add the SMD tactile switch from RESET to GND.

  5. ISP header. Place Conn_AVR_ISP and wire MISO, MOSI, SCK, RESET, VCC, GND as in Lesson 1.

I2C Bus and Sensors

Both the SHT30 and VEML7700 communicate over I2C, so they share the same bus.

  1. I2C pull-ups. Add two 4.7 kΩ resistors (R2, R3). Connect R2 from SDA (PC4/pin 27) to +3V3. Connect R3 from SCL (PC5/pin 28) to +3V3. We pull up to 3.3V because both sensors are 3.3V devices. The ATmega328P I2C pins are 3.3V tolerant when running at 5V.

  2. Place the SHT30. Add SHT3x-DIS (or create a custom symbol with VDD, GND, SDA, SCL, ADDR, ALERT pins). Connect VDD to +3V3, GND to GND, SDA to the I2C SDA bus, SCL to the I2C SCL bus. Tie ADDR to GND for address 0x44. Add a 100 nF decoupling cap (C5).

  3. Place the VEML7700. Add VEML7700 (or a generic I2C sensor symbol). Connect VDD to +3V3, GND to GND, SDA and SCL to the I2C bus. The VEML7700 has a fixed I2C address (0x10), so no address pin is needed. Add a 100 nF decoupling cap (C6).

UART Output

  1. Place a 1x4 pin header (J3) for UART output. Pins: VCC, TX, RX, GND. This connects to a USB-UART adapter (like FTDI or CP2102) for serial data output.

  2. Wire UART. Connect ATmega328P TXD (PD1/pin 31) to the TX pin and RXD (PD0/pin 30) to the RX pin on the header.

Power LED

  1. Place an 0805 LED (D1) and 330 Ω resistor (R4). Connect +3V3 to R4, R4 to D1 anode, D1 cathode to GND. This indicates the 3.3V rail is active.

  2. Run ERC. Fix any errors before proceeding.

Assign Footprints

Open Tools > Assign Footprints and set:

SymbolFootprint
ATmega328P-AUPackage_QFP:TQFP-32_7x7mm_P0.8mm
AMS1117-3.3Package_TO_SOT_SMD:SOT-223-3_TabPin2
SHT3x-DISSensor_Humidity:Sensirion_DFN-8-1EP_2.5x2.5mm_P0.5mm_EP1.1x1.7mm
VEML7700OptoDevice:Vishay_OPLGA-4_1.25x1mm_P0.8mm
Crystal 16MHzCrystal:Crystal_SMD_3215-4Pin_3.2x1.5mm
USB_B_MicroConnector_USB:USB_Micro-B_Molex_47346-0001
C (0805)Capacitor_SMD:C_0805_2012Metric
R (0805)Resistor_SMD:R_0805_2012Metric
LED (0805)LED_SMD:LED_0805_2012Metric
SW_PushButton_Switch_SMD:SW_SPST_PTS810
Conn_AVR_ISPConnector_PinHeader_2.54mm:PinHeader_2x03_P2.54mm_Vertical
Conn_01x04Connector_PinHeader_2.54mm:PinHeader_1x04_P2.54mm_Vertical

PCB Layout



Board Setup

  1. Board outline. On the Edge.Cuts layer, draw a 40 x 35 mm rectangle.

  2. Layer setup. This is a double-sided board: F.Cu (front copper) and B.Cu (back copper). Go to Board Setup > Board Stackup > Physical Stackup and verify the board has two copper layers with a 1.6mm substrate.

  3. Design rules. Set the Default net class:

    • Track width: 0.25 mm (for signal traces between TQFP pads)
    • Clearance: 0.2 mm
    • Via size: 0.6 mm, drill 0.3 mm

    Add a Power net class:

    • Track width: 0.5 mm
    • Clearance: 0.2 mm

Import and Place Components

  1. Update PCB from schematic (F8). All components appear in a cluster.

  2. Place the USB connector on the top edge of the board, centered, with the plug side extending slightly beyond the board edge.

  3. Place U2 (LDO) near the USB connector. Put C7 and C8 immediately adjacent to its input and output pins.

  4. Place U1 (ATmega328P-AU) in the center. The TQFP package is compact, so component placement around it matters more.

  5. Place the crystal (Y1) as close to pins 7 and 8 as possible. Place C1 and C2 right next to the crystal.

  6. Place decoupling caps (C3, C4) within 3mm of the VCC/AVCC pins. Shorter is better.

  7. Place sensors. Put U3 (SHT30) away from heat sources (the LDO, MCU). Temperature sensors need accurate ambient readings. Put U4 (VEML7700) near a board edge where it can see ambient light.

  8. Place the ISP header (J2) and UART header (J3) on the bottom edge for easy access.

  9. Place the reset button near a board edge.

Routing Strategy

  1. Route power traces first using the Power net class (0.5mm). Run +5V and +3V3 as short, direct traces from their sources to each component.

  2. Route the crystal traces. Keep XTAL1 and XTAL2 short, symmetric, and away from other signals. Guard them with a ground pour later.

  3. Route I2C bus. SDA and SCL run from the MCU to both sensors and the pull-up resistors. Keep these traces under 50mm total length. Route them as a pair with consistent spacing.

  4. Route UART. TX and RX from the MCU to the UART header. These are low-speed signals, so routing is straightforward.

  5. Route ISP signals. MISO, MOSI, SCK, RESET from the MCU to the ISP header.

  6. Use vias when needed. With a double-sided board, you can route signals on the back copper layer. Press V during routing to place a via and switch layers. Keep via count reasonable (under 20 for this board).

  7. Add ground pours on both layers. Create a GND zone on F.Cu and B.Cu. Fill them with B (Build All Zones). This provides a solid ground plane and reduces the amount of copper that needs to be removed during milling.

  8. Run DRC. Zero errors, zero unconnected items.

Optional: Speed Up With Freerouting

KiCad does not ship a built-in autorouter (the original was Java-based and dropped in KiCad 5 because no one stepped up to maintain it). The community-standard replacement is Freerouting, a free Java app that talks to KiCad through the Specctra DSN/SES file format.

For a board this dense, Freerouting can save real time, but only if you do not let it touch the nets that matter:

  1. Hand-route and lock the critical nets first. Power (+5V, +3V3, GND), the crystal pair (XTAL1/XTAL2), and the I2C pair (SDA/SCL) all benefit from deliberate placement. Route them yourself, then select each track and check Locked in the Properties panel. Locked tracks survive the autorouter pass.

  2. Install Freerouting. Download the latest release from github.com/freerouting/freerouting (you need a Java runtime installed). On many systems it is also available through KiCad’s Plugin and Content Manager (PCM).

  3. Launch the autorouter from the PCB Editor toolbar (the icon usually looks like a maze or a green PCB with arrows). The dialog exports a .dsn of the current board, hands it to Freerouting, waits for results, and imports the .ses back automatically.

  4. Review the result. Look for: too many vias on a single net, sharp corners on signals you care about, traces that cross under the crystal. Re-route by hand anything you don’t like; the autoroute is a starting point, not a finished design.

  5. Run DRC again. Locked tracks should be untouched, the rest should be connected, zero errors.

For a small, mostly-digital board like this one, hand routing teaches you more and the time difference is small. Freerouting earns its place when you reach 50+ nets, are working under deadline, or routing pure digital fan-out where aesthetics matter less than completion. Either choice produces the same Gerbers downstream.

Double-Sided Layout Tips

SMD Placement Rules

  • Keep all SMD components on the front side unless space forces some to the back
  • Through-hole components (ISP header, UART header) can go on either side
  • If a component must go on the back, flip it with F key in KiCad
  • The sensor ICs (SHT30, VEML7700) should face outward, not trapped between the board and a surface

Manufacturing: CNC Milling



CNC milling removes copper mechanically instead of chemically. A small end mill cuts isolation channels around traces, leaving the copper traces as raised islands. This works well for double-sided boards because you can flip the board and mill the other side.

Why CNC Milling?

  • No chemicals (no ferric chloride, no disposal issues)
  • Higher precision than toner transfer (0.1mm channels are achievable)
  • Repeatable (once set up, you can make identical boards)
  • Drills holes in the same setup
  • Works well for fine-pitch SMD pads like TQFP

CNC Milling Workflow

  1. Export Gerber files. In KiCad PCB Editor, go to File > Plot. Select F.Cu, B.Cu, and Edge.Cuts layers. Set format to Gerber. Click Plot. Then click Generate Drill Files in Excellon format.

  2. Import into your CNC software. Common options:

    • FlatCAM (free, open source): imports Gerbers and generates G-code
    • Candle or bCNC: G-code senders for GRBL-based CNC machines
    • PCB-GCODE (Eagle plugin also works with Gerber conversions)
  3. Set milling parameters in FlatCAM:

    • V-bit: 0.1mm tip, 30-degree angle
    • Isolation width: 0.15mm (number of passes: 2-3 for wider isolation)
    • Feed rate: 100-200 mm/min
    • Cut depth: 0.05-0.1mm (just deep enough to cut through the copper layer, typically 35 µm thick)
  4. Secure the copper-clad board to the CNC bed. Use double-sided tape or a vacuum table. The board must be perfectly flat; any warping will cause uneven cuts.

  5. Set the Z-origin (tool height). Touch the bit to the board surface. A Z-probe or continuity tester helps find the exact surface. This is the most critical setup step: too shallow and traces short together, too deep and the bit wears out fast.

  6. Mill the front copper layer. Run the F.Cu isolation routing G-code. The CNC cuts channels around every pad and trace, leaving copper islands.

  7. Drill all holes. Switch to a 0.8mm drill bit and run the Excellon drill file. The holes serve as alignment points when you flip the board.

  8. Flip the board for the back layer. Use two drilled holes as alignment pins. Secure the board face-down. Re-probe the Z-height.

  9. Mill the back copper layer. Run the B.Cu isolation routing G-code.

  10. Mill the board outline. Switch to a 1-2mm end mill and run the Edge.Cuts G-code to cut the board to its final shape.

  11. Clean and inspect. Remove copper dust with a brush. Inspect under magnification: check that all isolation channels are clean and no copper bridges remain between pads.

Connecting Front and Back Layers (Manual Vias)

CNC-milled boards do not have plated through-holes. You need to create manual vias:

  1. For each via, insert a short piece of bare copper wire (0.5mm diameter) through the drilled hole.

  2. Solder the wire to the pad on the front side, trim it, then flip the board and solder it to the pad on the back side.

  3. Trim excess wire flush with the solder joints.

This adds time compared to professionally fabricated boards, but it works reliably for prototypes.

Soldering SMD Components



SMD soldering requires different tools than through-hole work.

Tools Needed

ToolPurpose
Fine-tip soldering iron (0.5mm tip)Resistors, capacitors, LED, headers
Solder paste (Sn63/Pb37 or lead-free)TQFP and sensor ICs
Hot air stationReflowing solder paste on TQFP and sensors
Flux penImproving solder flow on fine-pitch pads
Tweezers (fine-point)Placing 0805 components
Magnifying glass or microscopeInspecting solder joints

Soldering Order

  1. TQFP MCU first. Apply solder paste to the TQFP-32 pads. Place the ATmega328P-AU with tweezers, aligning pin 1 with the pad 1 mark. Reflow with hot air at 250-280°C, holding the nozzle 2-3 cm above the chip. The paste will melt and self-align the chip. Inspect every pin under magnification for solder bridges.

  2. Sensor ICs. Apply paste and reflow the SHT30 and VEML7700 the same way. The SHT30 has an exposed pad on the bottom; make sure the paste connects it to the ground pad.

  3. LDO and crystal. Solder the SOT-223 regulator and SMD crystal. These are larger and easier than the sensors.

  4. 0805 passives. Tin one pad of each resistor/capacitor location with a small amount of solder. Place the component with tweezers, reflow the tinned pad, then solder the other pad. This “tack and solder” method is fast for 0805 parts.

  5. USB connector. Solder the Micro-B connector. The shield pins provide mechanical strength; solder them well.

  6. Through-hole headers. Solder the ISP and UART pin headers last, as they are the tallest components.

  7. Manual vias. If you used CNC milling, solder all via wires now.

Common SMD Mistakes

Troubleshooting

  • Solder bridges on TQFP: drag a clean, fluxed iron tip across the pins to wick away excess solder. Or use solder wick.
  • Tombstoning (0805 part stands up on one end): uneven solder paste or uneven heating. Remove, clean, and resolder.
  • Cold joints: dull, grainy appearance. Reheat with flux.
  • Component shifted during reflow: the component moved when you applied hot air. Use less airflow, or tack one side with an iron first.

First Power-On and Testing



  1. Visual inspection. Check every solder joint under magnification. Look for bridges on the TQFP pins especially.

  2. Continuity check. Verify no short between +5V and GND, or +3V3 and GND.

  3. Apply power via USB. Plug in a USB cable. The power LED should light. Measure +5V at the MCU VCC pin and +3.3V at the sensor VDD pins.

  4. Flash the blink firmware from Lesson 1 over the ISP header. If the LED blinks, the MCU and crystal are working.

Firmware: Reading Sensors



Save this as sensor_read.c. It reads both I2C sensors and outputs data over UART at 9600 baud.

/*
* sensor_read.c - Read SHT30 and VEML7700 via I2C, output via UART
* ATmega328P-AU @ 16 MHz
*/
#define F_CPU 16000000UL
#define BAUD 9600
#define UBRR_VAL ((F_CPU / 16 / BAUD) - 1)
#include <avr/io.h>
#include <util/delay.h>
#include <util/twi.h>
#include <stdio.h>
/* UART */
void uart_init(void) {
UBRR0H = (uint8_t)(UBRR_VAL >> 8);
UBRR0L = (uint8_t)UBRR_VAL;
UCSR0B = (1 << TXEN0);
UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
}
void uart_putc(char c) {
while (!(UCSR0A & (1 << UDRE0)));
UDR0 = c;
}
void uart_puts(const char *s) {
while (*s) uart_putc(*s++);
}
/* I2C */
void i2c_init(void) {
TWSR = 0;
TWBR = ((F_CPU / 100000UL) - 16) / 2; /* 100 kHz */
}
uint8_t i2c_start(uint8_t addr) {
TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN);
while (!(TWCR & (1 << TWINT)));
TWDR = addr;
TWCR = (1 << TWINT) | (1 << TWEN);
while (!(TWCR & (1 << TWINT)));
return (TWSR & 0xF8);
}
void i2c_write(uint8_t data) {
TWDR = data;
TWCR = (1 << TWINT) | (1 << TWEN);
while (!(TWCR & (1 << TWINT)));
}
uint8_t i2c_read_ack(void) {
TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWEA);
while (!(TWCR & (1 << TWINT)));
return TWDR;
}
uint8_t i2c_read_nack(void) {
TWCR = (1 << TWINT) | (1 << TWEN);
while (!(TWCR & (1 << TWINT)));
return TWDR;
}
void i2c_stop(void) {
TWCR = (1 << TWINT) | (1 << TWSTO) | (1 << TWEN);
}
/* SHT30 (I2C address 0x44) */
void sht30_read(int16_t *temp_raw, uint16_t *hum_raw) {
uint8_t data[6];
/* Send single-shot measurement command: 0x2400 (high repeatability) */
i2c_start(0x44 << 1);
i2c_write(0x24);
i2c_write(0x00);
i2c_stop();
_delay_ms(50); /* Wait for measurement */
/* Read 6 bytes: temp_msb, temp_lsb, temp_crc, hum_msb, hum_lsb, hum_crc */
i2c_start((0x44 << 1) | 1);
for (uint8_t i = 0; i < 5; i++) data[i] = i2c_read_ack();
data[5] = i2c_read_nack();
i2c_stop();
*temp_raw = (data[0] << 8) | data[1];
*hum_raw = (data[3] << 8) | data[4];
}
/* VEML7700 (I2C address 0x10) */
uint16_t veml7700_read(void) {
uint8_t low, high;
/* Configure: ALS gain x1, integration time 100ms, power on */
i2c_start(0x10 << 1);
i2c_write(0x00); /* ALS_CONF register */
i2c_write(0x00); /* LSB: power on, gain x1 */
i2c_write(0x00); /* MSB: integration 100ms */
i2c_stop();
_delay_ms(150); /* Wait for measurement */
/* Read ALS data register (0x04) */
i2c_start(0x10 << 1);
i2c_write(0x04);
i2c_start((0x10 << 1) | 1);
low = i2c_read_ack();
high = i2c_read_nack();
i2c_stop();
return (high << 8) | low;
}
/* Simple integer-to-string for UART output */
void print_int(int16_t val) {
char buf[8];
int8_t i = 0;
if (val < 0) { uart_putc('-'); val = -val; }
if (val == 0) { uart_putc('0'); return; }
while (val > 0) { buf[i++] = '0' + (val % 10); val /= 10; }
while (i > 0) uart_putc(buf[--i]);
}
int main(void) {
int16_t temp_raw;
uint16_t hum_raw;
uint16_t lux_raw;
uart_init();
i2c_init();
uart_puts("Sensor Shield Ready\r\n");
while (1) {
/* Read SHT30 */
sht30_read(&temp_raw, &hum_raw);
int16_t temp_c = -45 + (175 * (int32_t)temp_raw / 65535);
uint16_t hum_pct = 100 * (uint32_t)hum_raw / 65535;
/* Read VEML7700 */
lux_raw = veml7700_read();
/* Output */
uart_puts("T=");
print_int(temp_c);
uart_puts("C H=");
print_int(hum_pct);
uart_puts("% L=");
print_int(lux_raw);
uart_puts(" lux\r\n");
_delay_ms(2000);
}
}

Compile and Flash

Terminal window
avr-gcc -mmcu=atmega328p -DF_CPU=16000000UL -Os -o sensor_read.elf sensor_read.c
avr-objcopy -O ihex sensor_read.elf sensor_read.hex
avrdude -c usbasp -p m328p -U flash:w:sensor_read.hex:i

Connect a USB-UART adapter (FTDI or CP2102) to the UART header. Open a serial terminal at 9600 baud. You should see readings like:

Sensor Shield Ready
T=23C H=45% L=312 lux
T=23C H=45% L=310 lux

What You Have Learned



Lesson 2 Complete

KiCad skills:

  • Worked with SMD footprints (TQFP, 0805, SOT-223, DFN)
  • Designed a double-sided PCB with front and back copper layers
  • Used vias to route signals between layers
  • Set up fine-pitch design rules for TQFP routing

Electronics skills:

  • I2C bus design with pull-up resistors and multiple devices
  • Dual voltage rail design (5V MCU + 3.3V sensors)
  • SMD component selection and sizing (0805 passives)

Manufacturing skills:

  • CNC milling workflow (Gerber to FlatCAM to G-code)
  • Double-sided alignment technique with drilled reference holes
  • Manual via soldering for non-plated boards

Firmware skills:

  • Bare-metal I2C (TWI) driver for ATmega328P
  • SHT30 temperature/humidity sensor communication
  • VEML7700 ambient light sensor communication
  • UART serial output for sensor data

Comments

Loading comments...


© 2021-2026 SiliconWit®. All rights reserved.
Predict first

To keep the tracks short, a designer places a temperature sensor 4 mm from the voltage regulator of the board. The board sits in a room at 24 °C. What does the sensor report?

See it: the pull-up resistor shapes the clock

Rise time, 30% to 70%
Longest rise time allowed
Current a chip must sink

A chip pulls the line to 0 V and then lets it go. Only the resistor brings it back, charging the capacitance of the pins and tracks, so the line rises as 3.3 V × (1 − e^(−t / RC)). The rise time between the two dashed levels is 0.847 × R × C. The I2C standard allows at most 1,000 ns at 100 kHz and 300 ns at 400 kHz, and it lets a chip sink 3 mA, which sets the smallest resistor at about 970 Ω. The 50 pF at the start is an estimate for this small board. The fall is drawn as instant, and the curve ignores the inductance of the tracks.

Check yourself

Three questions. Each wrong choice is a mistake people really make, so read the note after you answer.

1. The board has one 4.7 kΩ pull-up on SDA. You connect two ready-made sensor modules to the same bus. Each module carries its own 2.2 kΩ pull-up on SDA, to the same 3.3 V. What pull-up does the bus now have?

2. A student copies the design rules of a through-hole board into this project: clearance 0.3 mm. The TQFP-32 footprint has pads 0.55 mm wide at a pitch of 0.8 mm. Before a single track is drawn, DRC lists a clearance error at every pin of the chip. Why?

3. A new board is programmed with the sensor program. The computer receives only unreadable characters at 9,600 baud. At 600 baud the text is perfect. The chip is new and was never used on another board. What was missed?

MCUSHT30VEML7700 3.3 Vpull-up 4.7 kΩSDA line pulls down Only the resistor lifts it back.
too highrighttoo low copper leftclean channeltrack eaten copperboard
Watch it build: from Gerber to a milled board
Front face Back face F.Cu Gerber:the copper shapes FlatCAM pathround each island 0.1 mm V-bitcuts 0.15 mmchannels 0.8 mm holes,turned overon 2 pins back milled,outline cut
  1. The F.Cu Gerber is a flat picture of the front copper: pads and tracks.
  2. On a copper blank, FlatCAM plans a tool path around each copper island.
  3. With the tool height set, the V-bit cuts channels about 0.15 mm wide round every island.
  4. Drilled at 0.8 mm, then turned over on two pins: the back face, left and right swapped.
  5. The back copper is milled, then a 1 to 2 mm end mill cuts the outline.
Through-hole resistor 6.5 mm 0805 SMD (2.0 x 1.25 mm) 0402 SMD (1.0 x 0.5 mm) 1 mm TQFP-32 chip 7 x 7 mm 0.8 mm pitch 32 pins, 8 on each side, 0.8 mm from the centre of one pin to the next All drawn at the same scale.
Coming here first?

This board uses the steps of the through-hole breakout board. If you have not done them, each one is here, at the part that teaches it:

Words used here, each with a five-minute page:

The finished sensor shield in 3D, seen from above: a small green board with the square 32-pin chip in the middle, the USB socket at the top edge, the regulator at the top left, the two sensors on the right, and two pin headers along the bottom edge.
The board you will make, made in KiCad 10 (40 × 35 mm).

What the finished project uses where the table leaves a choice:

  • U4 is the VEML7700-TT, the top-view version, which looks up from the board. The -TR version looks sideways.
  • Y1: 22 pF suits a crystal with a load capacitance (CL) of 16 pF: 2 × (16 − 5) = 22 pF. For a crystal with another CL, use 2 × (CL − 5 pF).
  • C8 is 22 µF tantalum, 10 V (case B), the safe choice the regulator step names. C7 is 10 µF, 16 V ceramic.
  • SW1: the PTS810 footprint is a 4.2 × 3.2 mm switch, not 3 × 6 mm.

atmega328p-sensor-shield-bom.csv is the parts list KiCad writes from the schematic, with a part number for each chip.

The pin numbers above are right for the TQFP-32 (we checked them against the symbol and the data sheet). Pins you do not use, such as AREF (20), ADC6 (19) and ADC7 (22), get a No Connect flag (Q), or ERC reports them. Check: the crystal symbol's two case pins (2 and 4) go to GND.

Two pins the steps leave out

KiCad's SHT30-DIS symbol has eight pins and a centre pad. The data sheet says what to do with each one:

  • ALERT (3): leave it open. Put a No Connect flag on it.
  • nRESET (6): leave it open (it has its own 50 kΩ pull-up inside). No Connect flag.
  • R (7) and the centre pad VSS (9): to GND, with VSS (8).

Draw the VEML7700 symbol with these pin numbers, from the data sheet: 1 SCL, 2 VDD, 3 GND, 4 SDA. KiCad 10 still has no symbol for it.

Check: the ADDR pin goes to GND, so the SHT30 answers at 0x44. The two sensors then have different addresses (0x44 and 0x10).

The names on J3 are the board's view: TX is the MCU's output. Connect the adapter's RX to TX and its TX to RX. Leave the adapter's VCC wire off while the USB cable is in: two supplies on one rail push current into each other.

Check it

The finished schematic, in KiCad 10.0.8: ERC 0 errors, 0 warnings. Every wire it draws is in the lesson's text; its netlist has 14 nets of two or more pins. Parts sit in titled boxes, one per job, and net labels join the boxes, so no wire runs across the sheet. To draw a box: Place > Add Text Box, drag it round the group, type its title.

The whole schematic on one sheet in six titled boxes, joined by net labels: Power (the USB socket, the 3.3 V regulator and the power LED) at the top left, Programming and serial (the ISP and UART headers) under it, the ATmega328P with its two decoupling capacitors in the middle, Clock (the 16 MHz crystal) and Reset to its right, and Sensors on I2C (the pull-ups, the SHT30 and the VEML7700 with their capacitors) on the right. Short notes give the I2C addresses and the UART wiring.
Yours may look different on the sheet; what must match is what connects to what. The schematic as a PDF.

Draw the VEML7700 footprint once, in its own library:

  1. In the project window, Footprint Editor, then File > New Library..., Project, name it sensor-shield. Check: the library appears in the tree on the left.
  2. File > New Footprint..., name Vishay_VEML7700-TT, type SMD.
  3. Place > Add Pad four times. Set each pad: SMD, rectangle, size 0.7 × 1.6 mm. Positions X -1.905, -0.635, 0.635, 1.905 mm, all at Y 0.875 mm. Numbers 1 to 4 from left to right.
  4. On F.Fab draw the body: a rectangle from (−3.4, −1.175) to (3.4, 1.175) mm. On F.Courtyard, one 0.25 mm larger all round and past the pads.
  5. Save, then pick it for U4 in Assign Footprints.

The pads are the data sheet's "proposed pad layout, top view": four pads 0.7 × 1.6 mm, 1.27 mm apart, under the edge where the legs bend. Pin 1 is at the left when the legs face you. The data sheet marks this layout "for reference only", so the paper print test in the milling part is the real check.

  1. Put the supply nets in the Power class. On the same Net Classes page, under Netclass Assignments, click + three times: Pattern +5V, +3V3 and GND, each with Net Class Power. Check: a track started on a +5V pad is 0.5 mm wide.
  2. For a milled board, make the vias larger. In the Default class set Via Size 1.2 mm and Via Hole 0.6 mm. A milled via is joined by a 0.5 mm wire, and that wire does not pass a 0.3 mm hole. For a factory board, 0.6 / 0.3 mm is right.

Near the chip a 0.5 mm supply track is wider than the 0.55 mm pad gap allows. Draw it 0.5 mm in the open, and narrow it to 0.25 mm for the last 1 to 2 mm into a TQFP pin: press W while routing to pick another width. DRC accepts this, since the class sets the width a track starts with, not a minimum.

Where the finished board puts each part, and why:

PartWhere, and why
J1Middle of the top edge. Its footprint has a line marked PCB Edge on Dwgs.User: put that line on the board edge, and the socket's mouth stands 0.7 mm past it
U2, C7, C8Top left, beside J1: C7 under the input pin, C8 under the tab (the output)
U1The middle of the board
C3; C4C3 just left of pins 4 to 6 (VCC, GND); C4 just right of pins 18 and 21 (AVCC, GND)
Y1, C1, C2Lower left of U1, a few millimetres from pins 7 and 8
U4, C6Top right, at the edge, where light reaches the window
U3, C5Bottom right corner: as far from U2 and U1 as the board allows
J2, J3The bottom edge, where a cable reaches them. SW1 on the left edge
The board from above, as its printed outlines show it: a 40 by 35 millimetre rectangle with the USB socket at the top middle, the regulator at the top left, the light sensor at the top right, the chip in the middle, the crystal at its lower left, the humidity sensor in the bottom right corner, and the two headers along the bottom edge.
Check: DRC reports no Courtyards overlap. The finished placement, from the KiCad 10 board.
Check it: the finished board
The top copper: the pads of every part, most tracks and the ground pour around them.
F.Cu, the top copper
The bottom copper seen from above: the tracks that cross under others, the via pads, and the ground pour.
B.Cu, the bottom copper, seen from above

DRC in KiCad 10.0.8, with Test for parity between PCB and schematic ticked and every severity shown: 0 errors, 0 unconnected items, 0 parity issues, and 2 warnings, both Silkscreen clipped by board edge: the USB footprint draws its outline out to the socket's mouth, past the edge, and the factory trims it.

This board, made in KiCad, has 34 vias and passes DRC. That is more than the 20 the steps aim for: on a milled board each via is a wire to solder, so a layout that saves vias is worth the time. The SHT30's centre pad and its ADDR pin sit inside its own ring of pads, where neither a track from outside nor the pour can reach: two short tracks under the sensor join them to pin 7. The pour joins surface-mount pads solid, and the header pins with four spokes.

Drills, and the KiCad 10 files

One 0.8 mm drill is not enough. The holes of this board, from Generate Report File in the drill dialog:

HoleFor
0.6 mmThe 34 vias (for the 0.5 mm wire)
1.0 mmThe 10 header pins of J2 and J3
noneNo unplated holes: the board has no mounting holes
  • The Plot and drill dialogs are also under File > Fabrication Outputs in KiCad 10. Leave PTH and NPTH in single file unticked.
  • Keep the Gerbers and the drill file on the same origin (Absolute in the drill dialog, the default), or FlatCAM places the holes away from the pads.

Check: the zip holds nine .gbr files, -PTH.drl, an empty -NPTH.drl and a .gbrjob. Compare yours with ours: atmega328p-sensor-shield-gerbers.zip.

The 0.5 mm wire passes the 0.6 mm via hole of this board. With the factory size of 0.3 mm it does not, which is why Board Setup above makes the vias larger for milling.

Or have it made and assembled

A factory that also places the parts needs three files: the Gerber zip, the parts list, and a position file with the centre and rotation of each part.

  1. Place > Drill/Place File Origin, and click the bottom left corner of the board. The finished board has it there.
  2. File > Fabrication Outputs > Component Placement (.pos)...: format CSV, units Millimeters, Use drill/place file origin, front side. Check: one row for each surface-mount part, X and Y between 0 and 40 and 0 and 35.
  3. Rename the columns to the ones the factory's form names (for example Designator, Mid X, Mid Y, Rotation, Layer). Then look at every part in its preview: a factory's 0 degrees is not always KiCad's, and a chip turned 90 degrees is a scrap board. The TQFP, the sensors, the USB socket and the tantalum capacitor (its + end) need this look most.

atmega328p-sensor-shield-pos.csv is ours. The two headers are through-hole, so you solder them yourself or ask for them as a separate service.

We compiled sensor_read.c with avr-gcc for the ATmega328P: 1,258 bytes, no warnings. If -DF_CPU is on the command line and in the file, the two values must match.

The factor 0.0576 lux per count comes from an older data sheet. Revision 1.8 (2024) gives 0.0336 lux per count at gain 2 and 100 ms, so 0.0672 at gain 1: change 576 to 672 if your part follows it. An empty bus then reads L=4404 lux, not 3774.

Found this useful?

Discussion

    Comments show your name. Be kind, stay on the topic.