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 16GB or Micro SD Card 32GB
  5. IOBIT V2.0 for micro:bit
  6. Rainbow LED 1x5 Module
  7. Gravity Gesture Sensor

 

micro:bit V2 Go (On-The-Go Starter Bundle)

Introducing the brand-new micro: bit V2, a must-have for technology and STEM enthusiasts. Now available with improved features to the hugely successful predecessor board with over 4 million boards being sold worldwide. This powerful, pocket-sized computer will be loved by all that use it. Designed to teach kids coding and solve problems using technology.

  • 1x micro:bit V2 Board
  • 1x micro USB Cable 6"
  • 1x Battery Holder 2xAAA
  • 2x AAA Batteries
  • 1x Quick Start Guide

 

DFPlayer - A Mini MP3 Player

Sing for the moment! The DFPlayer Mini is a small and low-cost MP3 module player with a simplified output directly to the speaker. The module can be used as a stand-alone module with an attached battery, speaker, and push buttons or used in combination with an Arduino UNO or any other with RX/TX capabilities.

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. Through a simple serial port, you can play the designated music without any other tedious underlying operations.

DFPlayer extension with built-in speaker, amplifier and volume control

Looking for a micro SD music player with built-in speaker, amplifier and volume control that works seamlessly with your microcontroller (Arduino, ESP, micro:bit, etc)? We have created an extension for DFPlayer - A Mini MP3 Player that simplifies all the messy wiring for you.

Micro SD Card 16GB/32GB

The Micro SD Card stores the songs you want to play. 16GB provides for a lot of storage, enough for more than 1000 songs!

IOBIT V2.0 for micro:bit

  • On-board buzzer you can directly use the music module in MakeCode to play music. At the same time, the 3.5mm audio connector on the board can be connected to audio equipment; such as, headphones to have more creative endeavors.
  • Two LEGO-compatible pin holes for easy assembly and integration
  • The 3PIN interface is distinguished by yellow, red, and black. It is created so that it is convenient to plug in the sensors.
  • It imitates the 5PIN gold fingers on the micro:bit. This is convenient for makers who like to use the alligator clips.

 

Rainbow LED 1x5 Module

Rainbow LED Module is a cascadable RGB LED module. It is possible to cascade more than 100 modules together.

The module adopts a high-brightness RGB LED with excellent display performance. This RGB LED module can be programmed to show cool effects of flashing, fading and rainbow colours.

Gravity Gesture Sensor

This interactive sensor with 3D gesture recognition that can recognize up to 13 gestures within 20cm. It is an excellent choice for interactive applications like non-contact remote controller, interactive robot, gesture-based game device, smart lighting management, and so on.

There are two recognition modes for this sensor: fast mode (9 gestures) and slow mode (13 gestures). In fast detection mode, the sensor can recognize 9 gestures: move left, right, up, down, forward, backward, clockwise, counter-clockwise, wave. The slow mode can recognize 4 expanded gestures besides the 9 basic ones: slowly move left and right, slowly move up and down, slowly move forward and backward, move randomly. Moreover, users can customize their own gestures if necessary.


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