Skip to content

MP3 Player with Sense HAT

Create your own customized MP3 player with a disco light show using Raspberry Pi, Sense HAT, and Scratch.

  • Raspberry Pi
  • Beginner
  • 30–45 minutes
  • 5 steps

Shop this project

Cart

You'll need

Prices from vilros.com. Tax and shipping at checkout.

Before you start, you'll need

  • Raspberry Pi (any model with GPIO)
  • Sense HAT
  • Speakers or headphones (optional)
  • MP3 files (at least 3)

Attach the Sense HAT

About 5 minutes

Mount the Sense HAT on your Raspberry Pi.

  1. Power off your Raspberry Pi.
  2. Carefully align the Sense HAT with the GPIO pins.
  3. Press the Sense HAT firmly onto the pins until it's fully seated.
  4. Power on your Raspberry Pi.

You should see

The Sense HAT is securely attached. The LED matrix should light up when powered.

Program the DJ light display

About 10 minutes

Make the Sense HAT LEDs sparkle randomly.

  1. Open Scratch 2 on your Raspberry Pi.
  2. Delete the default cat sprite and add a new sprite for your MP3 player.
  3. Add the Pi GPIO extension for Sense HAT.
  4. Add a 'when flag clicked' block with a 'forever' loop.
  5. Inside the loop, use 'set pixel' blocks with 'pick random' blocks to light up random LEDs in random colors.

You should see

Clicking the green flag makes the Sense HAT display a sparkling, random light pattern.

Add your MP3 files

About 10 minutes

Upload MP3 files to your Scratch sprite.

  1. Save at least 3 MP3 files in the same directory as your Scratch project.
  2. In Scratch, go to the Sounds tab for your sprite.
  3. Click 'Upload sound from file' and select your MP3 files.
  4. Repeat for all your music files.
  5. Add a 'play sound' block above your 'forever' block to play the first track.

You should see

Clicking the green flag plays music and shows the light display.

Display the current track

About 5 minutes

Show which track is playing on the Sense HAT.

  1. Create a new variable in Scratch called 'track'.
  2. Set 'track' to 1 at the start of your program.
  3. Add a 'scroll message' block that displays the track number on the Sense HAT.

You should see

The Sense HAT scrolls the current track number.

Add volume and track controls

About 10 minutes

Control volume and skip tracks using the Sense HAT joystick.

  1. Add a 'set volume to 100%' block at the start.
  2. Create a 'when up arrow key pressed' event that increases volume by 10.
  3. Create a 'when down arrow key pressed' event that decreases volume by 10.
  4. Create a 'when left arrow key pressed' event that decreases the track variable and plays the previous track.
  5. Create a 'when right arrow key pressed' event that increases the track variable and plays the next track.
  6. Add 'stop all sounds' at the start so tracks don't overlap.

You should see

The Sense HAT joystick controls volume (up/down) and track selection (left/right).

It didn't work
  • Volume controls don't work.

    Make sure you're using the 'change volume by' block, not 'set volume to'. Volume changes are relative.

  • Tracks overlap or don't change.

    Add 'stop all sounds' before playing a new track. Verify the track variable is changing correctly.

What to do next

Stuck? Contact Vilros Support with your board model and what you see on screen.