Cultivate Curiosity, Inspire Imagination.

micro:bit Tutorial: Music & Lights MP3 Player

Introduction

The micro:bit Music & Lights project is the perfect gesture-controlled lights and MP3 player! Program your micro:bit and get your MP3 player, complete with built-in speaker, amplifier and volume control running in 5 minutes! You can swipe up/down to turn on/off the light, or left/right to change from red to blue colour. It perfectly integrates the hard decoding module, which supports common audio formats such as MP3, WAV, and WMA. Besides, it also supports TF card with FAT16, FAT32 file system.

Let us show you how to build it!

 

 

Hardware Required

In this example we are using micro:bit Music & Lights Kit and micro:bit V2 Go (On-The-Go Starter Bundle), which includes all the necessary sensors and modules to get started right out of the box.

You may also choose to purchase the individual components here:

  1. micro:bit V2 Go (On-The-Go Starter Bundle)
  2. DFPlayer - A Mini MP3 Player
  3. DFPlayer extension with built-in speaker, amplifier and volume control
  4. Micro SD Card 32GB
  5. IOBIT V2.0 for micro:bit
  6. Rainbow LED 1x5 Module
  7. Gesture Sensor

 

Connecting the Hardware

Plug the connector into Gesture Sensor Module

  • Connect the blue wire to 19
  • Connect the green wire to 20
  • Connect the red wire to 3V
  • Connect the black wire to GND

Plug the connector into Rainbow LED 1x5 Module. Make sure that the text shows “G V I”. “I” is input and “O” is output. If you connect to more LED Modules then connect the “O” to the other LED Module “I”

Plug the connector into slot 8 with yellow wire on the yellow header

Plug the connector in, load songs into the microSD card and insert into DFPlayer Extension

  • Connect the yellow wire to 1
  • Connect the green wire to 2
  • Connect the red wire to 3V
  • Connect the black wire to GND

Finally, slot in the micro:bit. That’s it!

 

Programming the micro:bit

New Project

Go to makecode.microbit.org and click “New Project”.

Installing Extensions

Install DFPlayer, Gesture sensor and neopixel extension by clicking the gear icon on the top right and select “Extensions”.

Click “neopixel” to install extension.

Key in “dfplayer” and press enter. Click “dfplayermini” to install extension.

Key in “https://github.com/elecfreaks/pxt-gesture” and press enter. Click “Gesture” to install extension.

You should see 3 new options: “Gesture”, “DFPlayer Mini” and “Neopixel” appear in your code drawer.

Programming on start

At the on start method, initialize Gesture, DFPlayer and Neopixel. Initialize DFPlayer to P1 and P2, Neopixel to P8.

Delete the forever block as it’s not required.

Programming on Gesture

Add the following blocks:

On Gesture Right:

Show Right Arrow, Red LED and play next song.

On Gesture Left:

Show Left Arrow, Green LED and play previous song.

On Gesture Up:

Show Up Arrow, Blue LED and increase volume.

On Gesture Down:

Show Down Arrow, Violet LED and decrease volume.

On Gesture Forward & Backward:

Show X/O display, turn off LED and stop music.

Getting Ready to Run

Connect micro USB cable to micro:bit and download program. Once done, disconnect micro USB cable from micro:bit and connect to the IOBIT.

Depress the on/off button beside the micro USB connector to switch on the IOBIT. Test your program to make sure it works!

 

Resources