ESP8266 - MP3 Player
This tutorial instructs you how to make a MP3 player using ESP8266, MP3 player module, Micro SD Card, and speaker. The MP3 files (music, or recorded audio) are stored in the micro SD Card. Then, ESP8266 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 ESP8266
- How to program ESP8266 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.
|Micro USB Cable
|Serial MP3 Player Module
|Micro SD Card
|3.5mm Aux Speaker
|(Optional) ESP8266 Screw Terminal Adapter
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 ESP8266 includes 4 pins:
- RX pin: data pin, needs to be connected a TX pin of ESP8266 (Hardware or Software Serial)
- TX pin: data pin, needs to be connected a RX pin of ESP8266 (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 ESP8266
- 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 ESP8266 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
See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.
ESP8266 Code - Play Music
The below code plays the first song stored on the Micro SD Card.
To get started with ESP8266 on Arduino IDE, follow these steps:
- Check out the how to setup environment for ESP8266 on Arduino IDE tutorial if this is your first time using ESP8266.
- Wire the components as shown in the diagram.
- Connect the ESP8266 board to your computer using a USB cable.
- Open Arduino IDE on your computer.
- Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
- 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 ESP8266
- Enjoy the music