Skip to main content
Raspberry Pi HATs

Building a Class D Audio Amplifier HAT

Overview

This tutorial builds a small Raspberry Pi audio HAT around a PAM8403-style stereo Class D amplifier. The HAT takes left and right audio from the Pi, routes it through a dual-gang volume control, drives two speaker terminal blocks, and includes local power filtering for the amplifier.

What You Are Building

The HAT contains:

  • PAM8403-style 3 W per channel stereo Class D amplifier
  • Dual-gang 10 kOhm volume control
  • Left and right speaker terminal blocks
  • Power filtering near the amplifier
  • Pull-down resistors on both audio inputs
  • Power LED for quick bring-up feedback

The PAM8403 is commonly used from a 5 V supply. Use speakers that match the amplifier board and power source you choose.

Bill of Materials

ReferencePartValue or packageNotes
U1PAM8403 stereo amplifierSOIC/QFN module-friendly footprint3 W + 3 W Class D output
RV1Dual audio potentiometer10 kOhm, logarithmic preferredShared volume control
J1, J2Speaker terminals2 pin, 5.08 mmLeft and right speaker outputs
R1, R2Resistors100 kOhmInput pull-downs
R3Resistor1 kOhmLED current limit
C1Capacitor10 uF or larger5 V bulk filtering
C2Capacitor100 nFLocal high-frequency bypass
LED1LEDGreen, 0603Power indicator

Step 1: Add the Amplifier

Start with the amplifier and label the audio inputs, speaker outputs, supply, and control pins clearly.

Schematic Circuit Preview

Step 2: Add Volume Control

A dual-gang potentiometer keeps the left and right channels at the same volume. The wipers feed the amplifier inputs, and both low sides connect to signal ground.

Schematic Circuit Preview

Step 3: Add Speaker Terminals

Class D outputs are usually bridge-tied load outputs. Do not connect either speaker terminal to ground unless the amplifier datasheet explicitly says it is safe.

Schematic Circuit Preview

Step 4: Add Power Filtering

Place the bulk and bypass capacitors close to the amplifier. Audio boards are sensitive to supply bounce, especially when both speakers draw current at the same time.

<capacitor name="C1" capacitance="10uF" footprint="0805" />
<capacitor name="C2" capacitance="100nF" footprint="0402" />
<trace from=".HAT1_chip .V5_1" to=".U1 .VDD" />
<trace from=".HAT1_chip .GND_1" to=".U1 .GND" />
<trace from=".C1 > .pin1" to=".U1 .VDD" />
<trace from=".C1 > .pin2" to=".U1 .GND" />
<trace from=".C2 > .pin1" to=".U1 .VDD" />
<trace from=".C2 > .pin2" to=".U1 .GND" />

Raspberry Pi Audio Setup

For quick testing, route PWM audio to GPIO18 and GPIO19, or feed the HAT from an external DAC module. A simple /boot/firmware/config.txt test setup can enable the Pi audio path:

dtparam=audio=on

Then test with:

speaker-test -t sine -f 440 -c 2

Start with the volume low, confirm left and right channels separately, then raise the volume slowly.

PCB Layout Notes

  • Keep speaker output traces short and wide.
  • Keep input traces away from the switching speaker outputs.
  • Put C1 and C2 near the amplifier power pins.
  • Route left and right input traces as similar lengths when practical.
  • Place the volume control on a board edge so the knob is reachable.
  • Add silkscreen labels for left and right speaker polarity.

Bring-Up Checklist

  1. Inspect for shorts between 5 V and GND.
  2. Power the HAT without speakers and check that the LED turns on.
  3. Confirm the amplifier supply pin is near 5 V.
  4. Connect one speaker at low volume and play a sine wave.
  5. Repeat for the other channel.
  6. Check that the amplifier stays cool after several minutes at normal listening volume.

Common Fixes

  • Hum or hiss: shorten the input wiring and keep it away from the speaker outputs.
  • One channel silent: check the potentiometer wiper and speaker terminal polarity.
  • Distortion at low volume: confirm the audio source is not clipping before the amplifier.
  • Amplifier overheats: use a lower volume, higher-impedance speakers, or a stronger 5 V supply.