Arduino MP3 Player
This page is for a Arduino audio player solution with Arduino UNO R3 + low-noise MP3 player. Another solution for audio play with Arduino MKR WiFi 1010 or MKR Zero can be found in audio-player.md
If you and your group have any questions or get stuck as you work through this in-class exercise, please ask the instructor for assistance. Have fun!
-
If you haven’t already, please go to the Arduino website and download the “Arduino IDE” for either Windows or Mac, and then install the software on your computer. Another alternative is to use the cloud IDE. Please refer to this link on how to use the cloud IDE for our workshop: https://github.com/uviclibraries/arduino/blob/audio-player/face-to-face_workshop_children/cloud_IDE.md
Materials needed:
-
1 Arduino UNO R3 (see below)

-
MP3 player with SD card shield slot and 3.5mm Jack audio connector that is the YX5300 MP3 player board (see below)

-
HC-SR04 Ultrasonic sensor (see below)

- One active(embedded with amplifier) speaker with audio cable connect to the YX5300 module (see below). The actual print put of the pin might be different(TX and RX are swapped), Just follow the connections for the pin position.

- One 32GB SD card with FAT file system and stored with some .wav or .mp3 audio files. The file name has to be in the format of: ‘file order’+ ‘three characters’.wav or .mp3, for instance: 01tet.wav or 02ply.mp3. The files have to be stored in the top-level directory of the SD drive or folders with names of three-digital such as 001 or 002 etc.
-
Make sure that the SD card have correct audio file, file name and folder name and then insert the SD card into the SD card slot.
-
Connect the black wire to the GND pin on the Arduino and then the “-” pin on the breadboard.
Connect the red wire to the 5V pin on the Arduino and then the “+” pin on the breadboard.
-
Connect all the other wires and their placement as can be seen in the diagram below.

***Please notice that the breadboard power has to be connected to 5V (from Arduino MKR board), otherwise, the mp3 player might not work properly)
- Launch the arduino IDE. Use the provided USB cable to connect your Arduino board to your computer. Open a new scratch by selecting: File-New in the menu. Delete all the lines of codes for the file,
copy and paste to replace with this file: https://github.com/uviclibraries/arduino/blob/audio-player/code/audioplayer.c
-
Install the libraries for the Arduino UNO board: Go to the menu: Tools-Manager libraries-search with keyword ‘UNO’ and install “Arduino AVR boards”

-
Go to the menu of the IDE and select Tools- Board: Arduino UNO -Arduino AVR boards-Arduino UNO, connect and communicate with the board Auduino UNO.

Select board information window from Tools-Get board info menu, if it shows the information like below, it means that the Arduino UNO board has been connected to the IDE sussessfully:

- Select the Com port for the board from the Tools menu. The value of port number might be different for your board.

Also open the serial monitor window from the Tools menu: Tools-Serial monitor.

-
Press the arrow button and upload the codes to the board. Wait for a few seconds.

-
From the serial monitor window, you will the serial monitor window keeps on printing out the system information.

When there is no object within 50 cm in front of ultrasonic sensor, the audio player won’t play and keep on outputting the distance information in the serial monitor window. Put your hands or other objects closer to the ultrsonic sensor (less then 50cm), you will hear the music from the speaker! And the red LED or green LED will be on. If your hands or other objects closer to the ultrsonic sensor (less then 20cm), you will hear another music from the speaker, both of the red LED and green LED will be on, and the volume from the speakers can also change! Have fun!
- If you want to explore more, you can go back to the code editor of the Arduino IDE, modify the variables in the code, recompile, and upload your updated code to the Arduino board to see the results. For instance, change the distance threshold of starting playing music from 50 cm to 80 cm to see whether it will actually happen. Or you can change the music files, change the LEDs light, change the volumes etc. or change whatever you want to fully control the program. Have more fun from it!