Raspberry Pi hi-fi music player
Build it step by step
0 of 7 doneFlash the card
Raspberry Pi OS Lite with SSH set.
Wire the DAC
Five wires and the clock pin to ground.
Enable the overlay
Add the dtoverlay line and reboot.
Check the card
aplay -l shows the DAC.
Install MPD
Set the output in mpd.conf.
Add music
Update the library and play a track.
Add a phone client
Browse and control from the sofa.
How do you build a raspberry Pi hi-fi music player?
A Pi with a PCM5102 I2S DAC plays your music library and web radio through a stereo amplifier, controlled from a phone browser. You need Raspberry Pi 4 Model B (4 GB), SanDisk microSD card 32 GB (A1, Class 10), Raspberry Pi 27 W USB-C power supply, PCM5102 I2S DAC module, Audio jack 3.5 mm (PCB, stereo) and Jumper wires female to female (40 pcs). It takes 7 steps and about 120 minutes.
- Level
- Intermediate
- Time
- About 120 min
- Parts
- 6
Parts list
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| PCM5102 VIN | Pi pin 1 (3.3 V) | Power |
| PCM5102 GND | Pi pin 6 (GND) | Ground |
| PCM5102 BCK | Pi pin 12 (GPIO18) | I2S bit clock |
| PCM5102 LRCK | Pi pin 35 (GPIO19) | I2S word select |
| PCM5102 DIN | Pi pin 40 (GPIO21) | I2S data |
| PCM5102 SCK | GND | Internal clock (or the board's solder pad) |
| PCM5102 line out | Stereo jack to an amplifier's line input | Audio out |
Code
MPD (the Music Player Daemon) runs in the background, plays files and streams through the DAC, and any client can control it. The PCM5102 board needs its SCK pin to ground (or its solder pad closed) so that it makes its own clock. The "any" bind address lets the phone connect over the network, but MPD has no password by default, so anyone on the network can control it; set a password in mpd.conf if the network is shared. Use FLAC for the best quality, and keep the music on a USB drive or the card. The DAC gives a line-level signal, which goes to an amplifier or powered speakers, never straight to speakers. Read the project page of any web client you install, and read what any install script does before running it. Use a good 5 V 3 A USB-C supply for the Pi 4.
# Pi hi-fi player with MPD. Run on the Pi over SSH. Not an Arduino sketch.
# 1. Enable the DAC: add this line to /boot/firmware/config.txt (older images: /boot/config.txt), comment out dtparam=audio=on, reboot.
# dtoverlay=hifiberry-dac
sudo nano /boot/firmware/config.txt
sudo reboot
# 2. Check the sound card appears.
aplay -l
# 3. Install the Music Player Daemon and its command-line client.
sudo apt update
sudo apt install -y mpd mpc
# 4. Edit /etc/mpd.conf. Set the music folder and the audio output:
# music_directory "/var/lib/mpd/music"
# bind_to_address "any"
# audio_output {
# type "alsa"
# name "I2S DAC"
# device "hw:0,0"
# mixer_type "none"
# }
sudo nano /etc/mpd.conf
# 5. Copy your music into /var/lib/mpd/music (FLAC or MP3), then update the library and play.
sudo systemctl enable --now mpd
mpc update
mpc add /
mpc play
# 6. Web radio: add a station address and play it.
mpc add http://example.com/your-radio-stream
# 7. Control from a phone browser: install a web client such as myMPD by following its project instructions,
# or use a free MPD app on the phone (MALP on Android and similar apps) pointed at the Pi's address.
# 8. Compare with the headphone output: temporarily change device in mpd.conf to the Pi's own output and listen.Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Play a file | Sound from the amplifier |
| Web radio | Streams after a few seconds |
| Phone | Controls play, pause and volume |
| Reboot | MPD starts by itself |
If it does not work
No sound card listed
Check the overlay line and the wiring.
No sound
Check the device name in mpd.conf with aplay -l.
Library empty
Check file permissions and run mpc update.
Hum
Use short cables and a good supply.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the raspberry Pi hi-fi music player?
Raspberry Pi 4 Model B (4 GB), SanDisk microSD card 32 GB (A1, Class 10), Raspberry Pi 27 W USB-C power supply, PCM5102 I2S DAC module, Audio jack 3.5 mm (PCB, stereo) and Jumper wires female to female (40 pcs).
How long does the raspberry Pi hi-fi music player take to build?
About 120 minutes for a intermediate maker, in 7 steps.
How do I know the raspberry Pi hi-fi music player works?
Play a file: Sound from the amplifier. Web radio: Streams after a few seconds. Phone: Controls play, pause and volume.
No sound card listed: what should I check?
Check the overlay line and the wiring.
No sound: what should I check?
Check the device name in mpd.conf with aplay -l.
Library empty: what should I check?
Check file permissions and run mpc update.
Hum: what should I check?
Use short cables and a good supply.
