Skip to main content
Raspberry Pi HATs

Building a Class D Audio Amplifier HAT

Overview

This tutorial will walk you through building a Class D audio amplifier HAT for Raspberry Pi. Using the PAM8403 chip, we'll create a stereo amplifier delivering 3W per channel, perfect for desktop speakers or portable audio projects.

Objectives

Building a Class D amplifier HAT teaches essential audio electronics:

  • Class D Operation - Understanding pulse-width modulation amplification
  • Audio Signal Path - AC coupling and input filtering
  • Bridge-Tied Load - Maximizing power from low voltage supplies
  • HAT Integration - Interfacing with Raspberry Pi audio output

Use Cases

  • Desktop Speakers - Power small speakers from Pi audio
  • Media Centers - Audio for Kodi or Pi-based media players
  • Voice Assistants - Speaker output for Pi voice projects
  • Portable Audio - Battery-powered Bluetooth speakers

Bill of Materials

ComponentValueFootprintPurpose
PAM8403-SOIC-16Class D stereo amplifier
C1, C21µF0603Input DC blocking
C310µF0805Power supply filtering
C4100nF0402High-freq decoupling
RV110kΩPotentiometerVolume control
J1-3.5mm jackAudio input
SP_L, SP_R2-pin5.08mmSpeaker terminals
J240-pin2.54mmPi GPIO header

Understanding Class D Amplifiers

Class D amplifiers use pulse-width modulation (PWM) for high efficiency:

Amplifier ClassEfficiencyHeat GenerationUse Case
Class A20-30%HighHigh-end audio
Class AB50-60%ModerateGeneral audio
Class D85-95%LowPortable/efficient

The PAM8403 achieves over 90% efficiency, enabling operation without heatsinks.

Circuit Design

Step 1: PAM8403 Power Supply

The PAM8403 operates from 2.5V to 5.5V. Using the Pi's 5V rail provides maximum output power:

Schematic Circuit Preview

Step 2: Audio Input with DC Blocking

Capacitors block DC offset while passing audio frequencies:

Capacitor selection:

  • Target frequency: 20Hz (low end of audio)
  • Input impedance: 20kΩ typical
  • C = 1 / (2π × f × R) = 0.4µF minimum
  • Using 1µF provides margin
Schematic Circuit Preview

Step 3: Volume Control

A potentiometer provides analog volume adjustment:

Schematic Circuit Preview

Step 4: Bridge-Tied Load Outputs

The PAM8403 uses BTL configuration, doubling voltage swing across speakers:

Schematic Circuit Preview

Complete Schematic

Schematic Circuit Preview

Raspberry Pi Audio Configuration

Configure the Pi to output audio to the 3.5mm jack:

# Set audio output to headphone jack
amixer cset numid=3 1

# Test with a sound file
aplay /usr/share/sounds/alsa/Front_Center.wav

# Adjust volume
alsamixer

For I2S audio (higher quality), modify /boot/config.txt:

dtparam=audio=on
audio_pwm_mode=2

Speaker Selection

The PAM8403 works best with 4-8Ω speakers:

Speaker ImpedanceMax Power (5V)Recommended Use
3W per channelDesktop speakers
1.5W per channelSmall speakers

Higher impedance speakers reduce power but also reduce noise.

Ordering the PCB

Export the fabrication files and upload to JLCPCB. See Ordering Prototypes for detailed instructions.