Skip to main content
Tutorials

Class D Audio Amplifier HAT

Overview

This tutorial builds a compact stereo Class D amplifier HAT using a PAM8403. The PAM8403 can drive small left and right speakers at up to 3W per channel from a 5V rail, making it a practical choice for simple Raspberry Pi audio projects.

The HAT includes audio input pins, a dual-gang volume control, the amplifier IC, speaker terminal outputs, and local decoupling for the power rail.

How Class D Amplification Works

A Class D amplifier rapidly switches its output transistors instead of operating them in a continuous linear region. The speaker receives a filtered version of that switching waveform. This approach is efficient, produces less heat than a linear amplifier, and works well for battery-powered or compact boards.

Circuit Requirements

The board needs:

  • PAM8403 stereo Class D amplifier
  • 5V and ground from the Raspberry Pi HAT header
  • left and right audio inputs
  • volume control before the amplifier inputs
  • left and right speaker terminal outputs
  • decoupling capacitors near the amplifier supply pins

Final Circuit Preview

Step 1: Add the HAT Base

Use RaspberryPiHatBoard to start with the expected HAT outline and 40-pin GPIO header. The amplifier can use the 5V and ground pins from this header.

Schematic Circuit Preview

Step 2: Add Volume Control

A dual-gang potentiometer lets one knob adjust both channels. Route the left and right input signals to the potentiometer inputs, then route each wiper to the matching amplifier input.

Step 3: Add Speaker Outputs

The PAM8403 uses bridge-tied-load outputs, so each speaker connects between a positive and negative output pair. Do not connect either speaker terminal to ground unless the amplifier datasheet explicitly allows it.

Raspberry Pi Audio Configuration

For a Raspberry Pi analog audio source, route left, right, and ground from your audio output connector to the HAT input header. If you use I2S audio, add a DAC module before this amplifier stage and feed the DAC's analog outputs into the volume control.

Example /boot/firmware/config.txt setting for analog audio:

dtparam=audio=on

Then use raspi-config or your desktop audio settings to select the analog output. Keep the Pi output volume moderate and use the HAT potentiometer for listening-level adjustment.

Layout Notes

Place the 10uF and 100nF capacitors close to the PAM8403 supply pins. Keep the speaker traces wider than the signal traces, separate speaker output routing from the low-level audio inputs, and keep the volume-control traces short to reduce noise pickup.

Bill of Materials

ReferencePartNotes
U1PAM84033W per channel stereo Class D amplifier
RV1Dual 10k audio potentiometerLeft/right volume control
J13-pin audio input headerLeft, right, ground
J2, J32-pin speaker terminalsLeft and right speaker outputs
C110uF capacitorBulk supply decoupling
C2100nF capacitorHigh-frequency decoupling
R110k resistorPulls shutdown/enable high