How To Play MP3 Files on Arduino from SD Card
So let’s prepare the following materials:
1. Arduino Uno (or any microcontroller you are comfortable with).
2. SD card loaded with mp3 file.
3. A speaker (optional audio amplifier).
4. 3 pieces tactile switch for player control.
5. Breadboard.
6. Some jumper wires.
7. Source code provided below.
So let us begin by:
2. Connect the speaker to Arduino Uno as follows:
* Speaker (+) pin to Arduino Uno pin 9.
* Speaker (-) pin to Arduino Uno GND pin.
3. Connect the Arduino Uno to a computer.
4. Upload the following sketch. After successfully uploading the sketch to our microcontroller, it should function as follows:
* Pressing the first button should play the previous mp3 file.
* Pressing the middle button should play / pause the currently playing mp3 file.
* Pressing the third button should play the next mp3 file.
* Long pressing the first button should decrease the volume.
* Long pressing the third button should increase the volume.
5. Lastly, feel free to modify the source code for learning and fun.
Video Demonstration:
Source Code:
#include "SD.h" #include "TMRpcm.h" #include "SPI.h" #define SD_ChipSelectPin 10 #define spkrPin 9 TMRpcm tmrpcm; void setup() { tmrpcm.speakerPin = spkrPin; SD.begin(SD_ChipSelectPin); tmrpcm.setVolume(6); tmrpcm.play("CannotBe.wav"); delay(3000); } void loop() { tmrpcm.play("AyeSir.wav"); delay(3000); }
If you find this lesson helpful, please consider supporting my Youtube channel: tech-to-tinker. You may also leave your comments and suggestions in the comment box below.
Thank you and have a good day.
Happy tinkering!