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.
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables.
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.
Speaker Pinout
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
- Pause
- 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.
Wiring Diagram
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.
Detailed Instructions
- 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