Top Logo Sp Logo
Create Your Own MP3 Player with Sense HAT and Raspberry Pi

Create Your Own MP3 Player with a Sense HAT and Raspberry Pi

Create Your Own MP3 Player with a Sense HAT and Raspberry Pi

 

Who needs an iPod when you can create your very own customized MP3 player! With this project, you’ll be able to make your own music player with just a Raspberry Pi and Sense HAT. Not only will you have control over the tracks for your playlist, you’ll be able to display a fun disco effect, just like a real live DJ.

Here at Vilros we all love playing music and sharing it with the kids in our lives – so we’re super excited about this beginner-level project to build your own customized MP3 player.  Are you ready to get your groove on? 

1. Parts You Will Need

  • Hardware
  • Raspberry Pi
  • A Sense HAT
  • Speakers / Headphones (optional – but highly recommended!)

2. Your Cool DJ Light Display

To start, you’re going to get set-up so that your Sense HAT will show a random sparkling display – just like a true DJ effect:

  1. Open Scratch 2 on your Raspberry Pi
  2. Add a Scratch sprite for your MP3 player (make sure to delete any sounds already on the sprite).
  3. Add the Pi GPIO extension for SenseHAT
  4. Add a “when flag clicked” block with a “forever” block below
  5. Within the “forever” block, use a “set pixel” block and then “pick random” blocks so that random LED’s on your SenseHAT will light up in a variety of colors – this will give you that cool DJ look!

3. Your Music

Now that your lights are working, it’s time for some music!

  1. Choose some MP3 files (you’ll want at least 3 to start) and save them in the same directory where you have your Scratch code.
  2. Go to the “Sounds” tab for your sprite and click the “Upload sound from file” button – this will upload all your chosen MP3’s
  3. Insert a “play sound” block above your “forever” block – now when you click the green “go” flag you should have lights and music!
  4. (Optional) Plug your speakers or headphone into your Raspberry Pi for the full effect.
Create Your Own MP3 Player with Sense HAT and Raspberry PiCreate Your Own MP3 Player with Sense HAT and Raspberry Pi

    4. Show Your Track Number

      Want to know what song is currently playing?  You can do this by adding a variable in Scratch.

      1. Create a new variable in Scratch called “track”
      2. Add the “scroll message” block in order to display the track number on your Sense Hat
      3. Play the track with the number you stored in your “track” variable.

      5. Changing the Volume and the Currently Playing Track

      Now it’s time to add some more controls to your MP3 player.

      You can setup a script so you can control the volume with your Sense HAT joystick (using up and down keyboard arrows):

      1. Insert a “set volume” block so that your music starts at 100%
      2. Add a “when up arrow key pressed” block with a “change volume by 10” block
      3. Add a “when down arrow key pressed” block with a “change volume by – 10” block

      You can also use the joystick function to change the track that’s playing (using left and right keyboard arrows):

      1. Insert a “stop all sounds” block for when the program starts
      2. Add a “when left arrow key pressed” block to scroll back through your tracks
      3. Add a “when right arrow key pressed” block to scroll forward through your tracks
      4. (Optional) Use a “scroll message” block to show which track is currently being played

      You did it! You now should have your very own MP3 player with a fun light display. To see more details about this project, check out this step-by-step guide.

      All of us here at Vilros hope you are enjoying your new MP player with your friends and family.  For more project ideas, be sure to check for updates to our Vilros Projects blog.