Arduino Nano - MP3 Player
This tutorial instructs how to make a MP3 player using Arduino Nano, MP3 player module, Micro SD Card, and speaker. The MP3 files (music, or recorded audio) are stored in the micro SD Card. Then, Arduino Nano can control the MP3 player module to read a selected song from SD Car, convert it to audio signal, snd send the signal to the speaker. In detail, we will learn:
- How it works
- How to connect speaker, MP3 player modules to Arduino Nano
- How to program Arduino Nano to play a song stored in the micro SD Card
- How to add the play/pause/next/previous buttons
Then, you can modify the code to add a potentiometer or rotatry encoder to change the volume.
|USB A to Mini-B USB cable
|Serial MP3 Player Module
|Micro SD Card
|3.5mm Aux Speaker
|(Optional) 9V Power Adapter for Arduino Nano
|(Recommended) Screw Terminal Adapter for Arduino Nano
Or you can buy the following sensor kit:
|DIYables Sensor Kit 30 types, 69 units
Overview of Serial MP3 Player Module and Speaker
Serial MP3 Player Module Pinout
A serial MP3 player module has three interfaces:
- The interface to Arduino Nano includes 4 pins:
- RX pin: data pin, needs to be connected a TX pin of Arduino Nano (Hardware or Software Serial)
- TX pin: data pin, needs to be connected a RX pin of Arduino Nano (Hardware or Software Serial)
- VCC pin: power pin, needs to be connected to VCC (5V)
- GND pin: power pin, needs to be connected to GND (0V)
- The interface to the speaker is a 3.5mm Aux output female jack.
- The interface to the Micro SD Card is a Micro SD Card Socket in the back of the module.
A speaker usually has two interfaces:
- Audio signal interface: it is 3.5mm Aux male connector that connects to the MP3 player module
- Poweer interface: it can be USB, 5V power adapter or any other power interface
How It Works
What we need to prepare:
- Pre-store a list of songs or recorded audio that we want to play to micro SD Card.
- Insert the micro SD Card to the MP3 player module
- Connect the MP3 player module to Arduino Nano
- Connect the speaker to the MP3 player module to a
- Connect the speaker to a power source.
Each MP3 file stored on Micro SD Card will have an index. The index is the order of stored song, start from 0.
Then we can program Arduino Nano to send command to the MP3 player module. It supports the following commands:
- Play Next
- Play Previous
- Change volume
When the MP3 player module, it reads the MP3 file from the micro SD Card, converts the MP3 files to audio signal and outputs the audio signal to the speaker via the 3.5mm Aux interface.
This image is created using Fritzing. Click to enlarge image
Arduino Nano Code - Play Music
The below code plays the first song stored on the Micro SD Card.
- Follow the instructions on the How It Works
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to Arduino Nano
- Enjoy the music